aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-12-03 14:24:41 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-12-04 18:15:16 +0000
commit8946dbea418f760e4f0a5cbe2eb2bcbcddd25032 (patch)
treefc254ea5dea29ddf6a395b8bcdcb8c7540d22238 /searchlib/src
parent7700f411ea6f4a3e7c0599fae239ec84c18c0038 (diff)
FastOS_THread::Sleep -> std::chrono::sleep_for
Renamed Timer -> ScheduledExecutor. Do not include thread.h when not needed in header files.
Diffstat (limited to 'searchlib/src')
-rw-r--r--searchlib/src/tests/postinglistbm/stress_runner.cpp4
-rw-r--r--searchlib/src/tests/transactionlog/translogclient_test.cpp22
-rw-r--r--searchlib/src/tests/transactionlogstress/translogstress.cpp33
-rw-r--r--searchlib/src/vespa/searchlib/transactionlog/translogserver.cpp4
4 files changed, 35 insertions, 28 deletions
diff --git a/searchlib/src/tests/postinglistbm/stress_runner.cpp b/searchlib/src/tests/postinglistbm/stress_runner.cpp
index 53b683cd7fd..100a4fcd70d 100644
--- a/searchlib/src/tests/postinglistbm/stress_runner.cpp
+++ b/searchlib/src/tests/postinglistbm/stress_runner.cpp
@@ -8,9 +8,11 @@
#include <vespa/searchlib/test/fakedata/fakeword.h>
#include <vespa/searchlib/test/fakedata/fakewordset.h>
#include <vespa/searchlib/test/fakedata/fpfactory.h>
+#include <vespa/vespalib/util/time.h>
#include <condition_variable>
#include <mutex>
#include <vector>
+#include <thread>
#include <vespa/log/log.h>
LOG_SETUP(".stress_runner");
@@ -306,7 +308,7 @@ StressMaster::run()
totalTime / _loops, type.c_str());
dropPostings();
}
- FastOS_Thread::Sleep(250);
+ std::this_thread::sleep_for(250ms);
}
double
diff --git a/searchlib/src/tests/transactionlog/translogclient_test.cpp b/searchlib/src/tests/transactionlog/translogclient_test.cpp
index 8a515f749f1..c4751af5adb 100644
--- a/searchlib/src/tests/transactionlog/translogclient_test.cpp
+++ b/searchlib/src/tests/transactionlog/translogclient_test.cpp
@@ -248,7 +248,7 @@ bool Test::partialUpdateTest()
TransLogClient::Visitor::UP visitor = tls.createVisitor("test1", ca);
ASSERT_TRUE(visitor.get());
ASSERT_TRUE( visitor->visit(5, 7) );
- for (size_t i(0); ! ca._eof && (i < 1000); i++ ) { FastOS_Thread::Sleep(10); }
+ for (size_t i(0); ! ca._eof && (i < 1000); i++ ) { std::this_thread::sleep_for(10ms); }
ASSERT_TRUE( ca._eof );
ASSERT_TRUE( ca.map().size() == 1);
ASSERT_TRUE( ca.hasSerial(7) );
@@ -257,7 +257,7 @@ bool Test::partialUpdateTest()
TransLogClient::Visitor::UP visitor1 = tls.createVisitor("test1", ca1);
ASSERT_TRUE(visitor1.get());
ASSERT_TRUE( visitor1->visit(4, 5) );
- for (size_t i(0); ! ca1._eof && (i < 1000); i++ ) { FastOS_Thread::Sleep(10); }
+ for (size_t i(0); ! ca1._eof && (i < 1000); i++ ) { std::this_thread::sleep_for(10ms); }
ASSERT_TRUE( ca1._eof );
ASSERT_TRUE( ca1.map().size() == 0);
@@ -265,7 +265,7 @@ bool Test::partialUpdateTest()
TransLogClient::Visitor::UP visitor2 = tls.createVisitor("test1", ca2);
ASSERT_TRUE(visitor2.get());
ASSERT_TRUE( visitor2->visit(5, 6) );
- for (size_t i(0); ! ca2._eof && (i < 1000); i++ ) { FastOS_Thread::Sleep(10); }
+ for (size_t i(0); ! ca2._eof && (i < 1000); i++ ) { std::this_thread::sleep_for(10ms); }
ASSERT_TRUE( ca2._eof );
ASSERT_TRUE( ca2.map().size() == 0);
@@ -273,7 +273,7 @@ bool Test::partialUpdateTest()
TransLogClient::Visitor::UP visitor3 = tls.createVisitor("test1", ca3);
ASSERT_TRUE(visitor3.get());
ASSERT_TRUE( visitor3->visit(5, 1000) );
- for (size_t i(0); ! ca3._eof && (i < 1000); i++ ) { FastOS_Thread::Sleep(10); }
+ for (size_t i(0); ! ca3._eof && (i < 1000); i++ ) { std::this_thread::sleep_for(10ms); }
ASSERT_TRUE( ca3._eof );
ASSERT_TRUE( ca3.map().size() == 1);
ASSERT_TRUE( ca3.hasSerial(7) );
@@ -437,7 +437,7 @@ bool Test::visitDomainTest(TransLogClient & tls, TransLogClient::Session * s1, c
TransLogClient::Visitor::UP visitor = tls.createVisitor(name, ca);
ASSERT_TRUE(visitor.get());
EXPECT_TRUE( visitor->visit(0, 1) );
- for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { FastOS_Thread::Sleep(10); }
+ for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); }
EXPECT_TRUE( ca._eof );
EXPECT_TRUE( ! ca.hasSerial(0) );
EXPECT_TRUE( ca.hasSerial(1) );
@@ -447,7 +447,7 @@ bool Test::visitDomainTest(TransLogClient & tls, TransLogClient::Session * s1, c
visitor = tls.createVisitor(name, ca);
ASSERT_TRUE(visitor.get());
EXPECT_TRUE( visitor->visit(1, 2) );
- for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { FastOS_Thread::Sleep(10); }
+ for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); }
EXPECT_TRUE( ca._eof );
EXPECT_TRUE( ! ca.hasSerial(0) );
EXPECT_TRUE( ! ca.hasSerial(1) );
@@ -458,7 +458,7 @@ bool Test::visitDomainTest(TransLogClient & tls, TransLogClient::Session * s1, c
visitor = tls.createVisitor(name, ca);
EXPECT_TRUE(visitor.get());
EXPECT_TRUE( visitor->visit(0, 3) );
- for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { FastOS_Thread::Sleep(10); }
+ for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); }
EXPECT_TRUE( ca._eof );
EXPECT_TRUE( ! ca.hasSerial(0) );
EXPECT_TRUE( ca.hasSerial(1) );
@@ -469,7 +469,7 @@ bool Test::visitDomainTest(TransLogClient & tls, TransLogClient::Session * s1, c
visitor = tls.createVisitor(name, ca);
ASSERT_TRUE(visitor.get());
EXPECT_TRUE( visitor->visit(2, 3) );
- for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { FastOS_Thread::Sleep(10); }
+ for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); }
EXPECT_TRUE( ca._eof );
EXPECT_TRUE( ! ca.hasSerial(0) );
EXPECT_TRUE( !ca.hasSerial(1) );
@@ -575,7 +575,7 @@ assertVisitStats(TransLogClient &tls, const vespalib::string &domain,
ASSERT_TRUE(visitor.get());
ASSERT_TRUE( visitor->visit(visitStart, visitEnd) );
for (size_t i(0); ! ca._eof && (i < 60000); i++ ) {
- FastOS_Thread::Sleep(10);
+ std::this_thread::sleep_for(10ms);
}
ASSERT_TRUE(ca._eof);
EXPECT_EQUAL(expFirstSerial, ca._firstSerial);
@@ -623,7 +623,7 @@ void Test::testMany()
TransLogClient::Visitor::UP visitor = tls.createVisitor("many", ca);
ASSERT_TRUE(visitor.get());
ASSERT_TRUE( visitor->visit(2, TOTAL_NUM_ENTRIES) );
- for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { FastOS_Thread::Sleep(10); }
+ for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); }
ASSERT_TRUE( ca._eof );
EXPECT_EQUAL(ca._count, TOTAL_NUM_ENTRIES);
EXPECT_EQUAL(ca._value, TOTAL_NUM_ENTRIES);
@@ -644,7 +644,7 @@ void Test::testMany()
TransLogClient::Visitor::UP visitor = tls.createVisitor("many", ca);
ASSERT_TRUE(visitor.get());
ASSERT_TRUE( visitor->visit(2, TOTAL_NUM_ENTRIES) );
- for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { FastOS_Thread::Sleep(10); }
+ for (size_t i(0); ! ca._eof && (i < 60000); i++ ) { std::this_thread::sleep_for(10ms); }
ASSERT_TRUE( ca._eof );
EXPECT_EQUAL(ca._count, TOTAL_NUM_ENTRIES);
EXPECT_EQUAL(ca._value, TOTAL_NUM_ENTRIES);
diff --git a/searchlib/src/tests/transactionlogstress/translogstress.cpp b/searchlib/src/tests/transactionlogstress/translogstress.cpp
index a047c5e1657..2ec193cfe45 100644
--- a/searchlib/src/tests/transactionlogstress/translogstress.cpp
+++ b/searchlib/src/tests/transactionlogstress/translogstress.cpp
@@ -11,8 +11,11 @@
#include <iostream>
#include <stdexcept>
#include <sstream>
+#include <thread>
#include <vespa/log/log.h>
+#include <vespa/vespalib/util/time.h>
+
LOG_SETUP("translogstress");
using document::ByteBuffer;
@@ -267,7 +270,7 @@ FeederThread::doRun()
int64_t milliSecsUsed = _timer.elapsed().ms();
if (milliSecsUsed < 1000) {
//LOG(info, "FeederThread: sleep %u ms", 1000 - milliSecsUsed);
- FastOS_Thread::Sleep(1000 - milliSecsUsed);
+ std::this_thread::sleep_for(std::chrono::milliseconds(1000 - milliSecsUsed));
} else {
LOG(info, "FeederThread: max throughput");
}
@@ -457,7 +460,7 @@ private:
EntryGenerator _generator;
std::vector<std::shared_ptr<VisitorAgent> > _visitors;
std::vector<std::shared_ptr<VisitorAgent> > _rndVisitors;
- uint64_t _visitorInterval; // in milliseconds
+ vespalib::duration _visitorInterval; // in milliseconds
int64_t _pruneInterval; // in milliseconds
fastos::StopWatch _pruneTimer;
SerialNum _begin;
@@ -481,14 +484,14 @@ ControllerThread::ControllerThread(const std::string & tlsSpec, const std::strin
const EntryGenerator & generator, uint32_t numVisitors,
uint64_t visitorInterval, uint64_t pruneInterval)
: _tlsSpec(tlsSpec), _domain(domain), _client(tlsSpec.c_str()), _session(),
- _generator(generator), _visitors(), _rndVisitors(), _visitorInterval(visitorInterval),
+ _generator(generator), _visitors(), _rndVisitors(), _visitorInterval(std::chrono::milliseconds(visitorInterval)),
_pruneInterval(pruneInterval), _pruneTimer(), _begin(0), _end(0), _count(0)
{
for (uint32_t i = 0; i < numVisitors; ++i) {
_visitors.push_back(std::make_shared<VisitorAgent>(tlsSpec, domain, generator, i, true));
}
}
-ControllerThread::~ControllerThread() {}
+ControllerThread::~ControllerThread() = default;
void
ControllerThread::getStatus()
@@ -553,7 +556,7 @@ ControllerThread::doRun()
}
_pruneTimer.restart();
}
- FastOS_Thread::Sleep(_visitorInterval);
+ std::this_thread::sleep_for(_visitorInterval);
}
}
@@ -569,7 +572,7 @@ private:
uint64_t domainPartSize;
size_t packetSize;
- uint64_t stressTime;
+ std::chrono::milliseconds stressTime;
uint32_t feedRate;
uint32_t numVisitors;
uint64_t visitorInterval;
@@ -598,7 +601,7 @@ void
TransLogStress::printConfig()
{
std::cout << "######## Config ########" << std::endl;
- std::cout << "stressTime: " << _cfg.stressTime / 1000 << " s" << std::endl;
+ std::cout << "stressTime: " << vespalib::to_s(_cfg.stressTime) << " s" << std::endl;
std::cout << "feedRate: " << _cfg.feedRate << " per/sec" << std::endl;
std::cout << "numVisitors: " << _cfg.numVisitors << std::endl;
std::cout << "visitorInterval: " << _cfg.visitorInterval << " ms" << std::endl;
@@ -628,7 +631,7 @@ TransLogStress::Main()
_cfg.domainPartSize = 8000000; // ~8MB
_cfg.packetSize = 0x10000;
- _cfg.stressTime = 1000 * 60;
+ _cfg.stressTime = std::chrono::milliseconds(1000 * 60);
_cfg.feedRate = 10000;
_cfg.numVisitors = 1;
_cfg.visitorInterval = 1000 * 1;
@@ -639,7 +642,7 @@ TransLogStress::Main()
_cfg.maxStrLen = 80;
_cfg.baseSeed = 100;
- uint64_t sleepTime = 4000;
+ vespalib::duration sleepTime = 4s;
int idx = 1;
char opt;
@@ -654,7 +657,7 @@ TransLogStress::Main()
_cfg.packetSize = atol(arg);
break;
case 't':
- _cfg.stressTime = 1000 * atol(arg);
+ _cfg.stressTime = std::chrono::milliseconds(1000 * atol(arg));
break;
case 'f':
_cfg.feedRate = atoi(arg);
@@ -690,7 +693,7 @@ TransLogStress::Main()
}
printConfig();
- FastOS_Thread::Sleep(sleepTime);
+ std::this_thread::sleep_for(sleepTime);
if (_argc != idx || optError) {
usage();
@@ -721,13 +724,13 @@ TransLogStress::Main()
FeederThread feeder(tlsSpec, domain, generator, _cfg.feedRate, _cfg.packetSize);
threadPool.NewThread(&feeder);
- FastOS_Thread::Sleep(sleepTime);
+ std::this_thread::sleep_for(sleepTime);
ControllerThread controller(tlsSpec, domain, generator, _cfg.numVisitors, _cfg.visitorInterval, _cfg.pruneInterval);
threadPool.NewThread(&controller);
// stop feeder and controller
- FastOS_Thread::Sleep(_cfg.stressTime);
+ std::this_thread::sleep_for(_cfg.stressTime);
printConfig();
LOG(info, "Stop feeder...");
feeder.stop();
@@ -735,7 +738,7 @@ TransLogStress::Main()
std::cout << "<feeder>" << std::endl;
std::cout << " <from>" << feeder.getRange().from() << "</from>" << std::endl;
std::cout << " <to>" << feeder.getRange().to() << "</to>" << std::endl;
- std::cout << " <rate>" << 1000 * (feeder.getRange().to() - feeder.getRange().from()) / (sleepTime + _cfg.stressTime)
+ std::cout << " <rate>" << 1000 * (feeder.getRange().to() - feeder.getRange().from()) / vespalib::count_ms(sleepTime + _cfg.stressTime)
<< "</rate>" << std::endl;
std::cout << "</feeder>" << std::endl;
@@ -743,7 +746,7 @@ TransLogStress::Main()
controller.stop();
controller.join();
- FastOS_Thread::Sleep(sleepTime);
+ std::this_thread::sleep_for(sleepTime);
std::vector<std::shared_ptr<VisitorAgent> > & visitors = controller.getVisitors();
for (size_t i = 0; i < visitors.size(); ++i) {
std::cout << "<visitor id='" << i << "'>" << std::endl;
diff --git a/searchlib/src/vespa/searchlib/transactionlog/translogserver.cpp b/searchlib/src/vespa/searchlib/transactionlog/translogserver.cpp
index 6d11ab1f5eb..37903bc21f5 100644
--- a/searchlib/src/vespa/searchlib/transactionlog/translogserver.cpp
+++ b/searchlib/src/vespa/searchlib/transactionlog/translogserver.cpp
@@ -2,12 +2,14 @@
#include "translogserver.h"
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/io/fileutil.h>
+#include <vespa/vespalib/util/time.h>
#include <vespa/vespalib/util/exceptions.h>
#include <vespa/fnet/frt/supervisor.h>
#include <vespa/fnet/frt/rpcrequest.h>
#include <vespa/fnet/task.h>
#include <vespa/fnet/transport.h>
#include <fstream>
+#include <thread>
#include <vespa/log/log.h>
LOG_SETUP(".transactionlog.server");
@@ -125,7 +127,7 @@ TransLogServer::TransLogServer(const vespalib::string &name, int listenPort, con
listenOk = true;
} else {
LOG(warning, "Failed listening at port %s trying for %d seconds more.", listenSpec, i);
- FastOS_Thread::Sleep(1000);
+ std::this_thread::sleep_for(1s);
}
}
if ( ! listenOk ) {