summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-11-20 22:50:11 +0100
committerGitHub <noreply@github.com>2019-11-20 22:50:11 +0100
commit05377eb166b3d310774545fdd35172991dba9390 (patch)
treefa9cd911e7cdf421b86eff370bdaab0b0aa242a4
parent7c1d49d35f573e2e59b2909200e3cb07f3d8748b (diff)
parentafbe78369142bf8f02e89eb49117eef91a76e867 (diff)
Merge pull request #11363 from vespa-engine/balder/fastos_time-2-chrono-rebased-1
Balder/fastos time 2 chrono rebased 1
-rw-r--r--documentapi/src/tests/policies/policies_test.cpp6
-rw-r--r--fastos/src/vespa/fastos/timestamp.cpp31
-rw-r--r--fastos/src/vespa/fastos/timestamp.h12
-rw-r--r--messagebus/src/tests/loadbalance/loadbalance.cpp3
-rw-r--r--messagebus/src/tests/messageordering/messageordering.cpp5
-rw-r--r--messagebus/src/tests/routable/routable.cpp13
-rw-r--r--messagebus/src/tests/timeout/timeout.cpp12
-rw-r--r--messagebus/src/vespa/messagebus/CMakeLists.txt2
-rw-r--r--messagebus/src/vespa/messagebus/common.h8
-rw-r--r--messagebus/src/vespa/messagebus/dynamicthrottlepolicy.cpp6
-rw-r--r--messagebus/src/vespa/messagebus/message.cpp19
-rw-r--r--messagebus/src/vespa/messagebus/message.h66
-rw-r--r--messagebus/src/vespa/messagebus/messagebus.cpp7
-rw-r--r--messagebus/src/vespa/messagebus/messagebus.h2
-rw-r--r--messagebus/src/vespa/messagebus/network/inetwork.h2
-rw-r--r--messagebus/src/vespa/messagebus/network/rpcnetwork.cpp24
-rw-r--r--messagebus/src/vespa/messagebus/network/rpcnetwork.h2
-rw-r--r--messagebus/src/vespa/messagebus/network/rpcsend.cpp12
-rw-r--r--messagebus/src/vespa/messagebus/network/rpcsend.h10
-rw-r--r--messagebus/src/vespa/messagebus/network/rpcsend_private.h22
-rw-r--r--messagebus/src/vespa/messagebus/network/rpcsendadapter.h5
-rw-r--r--messagebus/src/vespa/messagebus/network/rpcsendv1.cpp6
-rw-r--r--messagebus/src/vespa/messagebus/network/rpcsendv1.h2
-rw-r--r--messagebus/src/vespa/messagebus/network/rpcsendv2.cpp6
-rw-r--r--messagebus/src/vespa/messagebus/network/rpcsendv2.h2
-rw-r--r--messagebus/src/vespa/messagebus/network/rpctarget.cpp10
-rw-r--r--messagebus/src/vespa/messagebus/network/rpctarget.h2
-rw-r--r--messagebus/src/vespa/messagebus/network/rpctargetpool.cpp4
-rw-r--r--messagebus/src/vespa/messagebus/reply.h2
-rw-r--r--messagebus/src/vespa/messagebus/routablequeue.cpp9
-rw-r--r--messagebus/src/vespa/messagebus/routing/resender.cpp25
-rw-r--r--messagebus/src/vespa/messagebus/routing/resender.h8
-rw-r--r--messagebus/src/vespa/messagebus/sourcesession.cpp9
-rw-r--r--messagebus/src/vespa/messagebus/sourcesession.h4
-rw-r--r--messagebus/src/vespa/messagebus/sourcesessionparams.cpp4
-rw-r--r--messagebus/src/vespa/messagebus/sourcesessionparams.h8
-rw-r--r--messagebus/src/vespa/messagebus/steadytimer.cpp15
-rw-r--r--messagebus/src/vespa/messagebus/steadytimer.h (renamed from messagebus/src/vespa/messagebus/systemtimer.h)3
-rw-r--r--messagebus/src/vespa/messagebus/systemtimer.cpp15
-rw-r--r--messagebus/src/vespa/messagebus/testlib/receptor.cpp27
-rw-r--r--messagebus_test/src/tests/error/cpp-client.cpp3
-rw-r--r--messagebus_test/src/tests/speed/cpp-client.cpp13
-rw-r--r--searchcore/src/tests/proton/common/cachedselect_test.cpp9
-rw-r--r--searchcore/src/vespa/searchcore/proton/attribute/attribute_initializer.cpp2
-rw-r--r--searchcore/src/vespa/searchcore/proton/docsummary/summarymanagerinitializer.cpp2
-rw-r--r--searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreinitializer.cpp2
-rw-r--r--searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h4
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/match_master.cpp8
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp3
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/matcher.cpp1
-rw-r--r--searchcore/src/vespa/searchcore/proton/reprocessing/reprocess_documents_task.cpp16
-rw-r--r--searchcore/src/vespa/searchcore/proton/reprocessing/reprocess_documents_task.h4
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.cpp11
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.h16
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp30
-rw-r--r--searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h27
-rw-r--r--searchcorespi/src/vespa/searchcorespi/index/fusionrunner.cpp16
-rw-r--r--searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp13
-rw-r--r--searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp17
-rw-r--r--searchlib/src/tests/util/bufferwriter/CMakeLists.txt8
-rw-r--r--searchlib/src/tests/util/bufferwriter/bm.cpp93
-rw-r--r--searchlib/src/tests/util/bufferwriter/bufferwriter_test.cpp5
-rw-r--r--searchlib/src/tests/util/bufferwriter/work.cpp92
-rw-r--r--searchlib/src/tests/util/bufferwriter/work.h22
-rw-r--r--searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp27
-rw-r--r--searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.h6
-rw-r--r--searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp50
-rw-r--r--searchlib/src/vespa/searchlib/features/debug_wait.cpp40
-rw-r--r--searchlib/src/vespa/searchlib/features/nowfeature.cpp30
-rw-r--r--searchlib/src/vespa/searchlib/features/nowfeature.h3
-rw-r--r--searchlib/src/vespa/searchlib/features/random_normal_feature.cpp32
-rw-r--r--searchlib/src/vespa/searchlib/features/randomfeature.cpp38
-rw-r--r--searchsummary/src/tests/extractkeywords/extractkeywordstest.cpp15
-rw-r--r--slobrok/src/vespa/slobrok/server/reserved_name.cpp21
-rw-r--r--slobrok/src/vespa/slobrok/server/reserved_name.h17
-rw-r--r--storage/src/tests/storageserver/documentapiconvertertest.cpp5
-rw-r--r--storage/src/vespa/storage/common/statusmetricconsumer.cpp5
-rw-r--r--storage/src/vespa/storage/storageserver/communicationmanager.cpp4
-rw-r--r--storage/src/vespa/storage/storageserver/documentapiconverter.cpp13
-rw-r--r--storage/src/vespa/storage/visiting/visitor.cpp10
-rw-r--r--vespalib/src/tests/btree/iteratespeed.cpp2
-rw-r--r--vespalib/src/vespa/vespalib/testkit/test_comparators.h11
-rw-r--r--vespalib/src/vespa/vespalib/util/slaveproc.cpp45
-rw-r--r--vespalib/src/vespa/vespalib/util/time_tracker.h7
84 files changed, 456 insertions, 772 deletions
diff --git a/documentapi/src/tests/policies/policies_test.cpp b/documentapi/src/tests/policies/policies_test.cpp
index 508d0a961f5..93c5d51fef5 100644
--- a/documentapi/src/tests/policies/policies_test.cpp
+++ b/documentapi/src/tests/policies/policies_test.cpp
@@ -40,6 +40,8 @@ using namespace documentapi;
using vespalib::make_string;
using std::make_unique;
using std::make_shared;
+using namespace std::chrono_literals;
+
class Test : public vespalib::TestApp {
private:
@@ -308,7 +310,7 @@ Test::testExternSend()
mbus::TestServer src(mbus::Identity("src"), mbus::RoutingSpec(), local,
std::make_shared<DocumentProtocol>(_loadTypes, _repo));
mbus::Receptor sr;
- mbus::SourceSession::UP ss = src.mb.createSourceSession(sr, mbus::SourceSessionParams().setTimeout(60));
+ mbus::SourceSession::UP ss = src.mb.createSourceSession(sr, mbus::SourceSessionParams().setTimeout(60s));
mbus::Slobrok slobrok;
mbus::TestServer itr(mbus::Identity("itr"), mbus::RoutingSpec()
@@ -349,7 +351,7 @@ Test::testExternMultipleSlobroks()
mbus::TestServer src(mbus::Identity("src"), mbus::RoutingSpec(), local,
std::make_shared<DocumentProtocol>(_loadTypes, _repo));
mbus::Receptor sr;
- mbus::SourceSession::UP ss = src.mb.createSourceSession(sr, mbus::SourceSessionParams().setTimeout(60));
+ mbus::SourceSession::UP ss = src.mb.createSourceSession(sr, mbus::SourceSessionParams().setTimeout(60s));
string spec;
mbus::Receptor dr;
diff --git a/fastos/src/vespa/fastos/timestamp.cpp b/fastos/src/vespa/fastos/timestamp.cpp
index a1da4322f8c..ae6bef1e317 100644
--- a/fastos/src/vespa/fastos/timestamp.cpp
+++ b/fastos/src/vespa/fastos/timestamp.cpp
@@ -1,7 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "timestamp.h"
-#include <chrono>
#include <cmath>
+#include <thread>
#include <sys/time.h>
using namespace std::chrono;
@@ -86,14 +86,31 @@ SteadyTimeStamp::toUTC() const {
}
StopWatch::StopWatch()
- : _startTime(steady_now()),
- _stopTime(_startTime)
+ : _startTime(steady_now())
{ }
-StopWatch &
-StopWatch::stop() {
- _stopTime = steady_now();
- return *this;
+void
+StopWatch::restart() {
+ _startTime = steady_now();
+}
+
+TimeStamp
+StopWatch::elapsed() const {
+ return (steady_now() - _startTime);
+}
+
+void
+StopWatch::waitAtLeast(std::chrono::microseconds us, bool busyWait) {
+ if (busyWait) {
+ steady_clock::time_point deadline = steady_clock::now() + us;
+ while (steady_clock::now() < deadline) {
+ if (busyWait) {
+ for (int i = 0; i < 1000; i++) { }
+ }
+ }
+ } else {
+ std::this_thread::sleep_for(us);
+ }
}
}
diff --git a/fastos/src/vespa/fastos/timestamp.h b/fastos/src/vespa/fastos/timestamp.h
index c670e9f9b49..79d6ef5eed6 100644
--- a/fastos/src/vespa/fastos/timestamp.h
+++ b/fastos/src/vespa/fastos/timestamp.h
@@ -4,6 +4,7 @@
#include <cstdint>
#include <limits>
#include <string>
+#include <chrono>
namespace fastos {
@@ -150,16 +151,11 @@ class StopWatch
{
public:
StopWatch();
-
- StopWatch & stop();
-
- TimeStamp elapsed() const {
- TimeStamp diff(_stopTime - _startTime);
- return (diff > 0) ? diff : TimeStamp(0);
- }
+ void restart();
+ TimeStamp elapsed() const;
+ static void waitAtLeast(std::chrono::microseconds us, bool busyWait);
private:
SteadyTimeStamp _startTime;
- SteadyTimeStamp _stopTime;
};
time_t time();
diff --git a/messagebus/src/tests/loadbalance/loadbalance.cpp b/messagebus/src/tests/loadbalance/loadbalance.cpp
index ebd8d6e250b..2f510d98ff1 100644
--- a/messagebus/src/tests/loadbalance/loadbalance.cpp
+++ b/messagebus/src/tests/loadbalance/loadbalance.cpp
@@ -16,6 +16,7 @@
#include <vespa/messagebus/testlib/testserver.h>
using namespace mbus;
+using namespace std::chrono_literals;
struct Handler : public IMessageHandler
{
@@ -64,7 +65,7 @@ Test::Main()
RoutableQueue queue;
SourceSessionParams params;
- params.setTimeout(30.0);
+ params.setTimeout(30s);
params.setThrottlePolicy(IThrottlePolicy::SP());
SourceSession::UP ss = src.mb.createSourceSession(queue, params);
diff --git a/messagebus/src/tests/messageordering/messageordering.cpp b/messagebus/src/tests/messageordering/messageordering.cpp
index d1b512bb1f1..520c3d3dea3 100644
--- a/messagebus/src/tests/messageordering/messageordering.cpp
+++ b/messagebus/src/tests/messageordering/messageordering.cpp
@@ -13,6 +13,7 @@
LOG_SETUP("messageordering_test");
using namespace mbus;
+using namespace std::chrono_literals;
TEST_SETUP(Test);
@@ -151,10 +152,10 @@ Test::Main()
SourceSessionParams ssp;
ssp.setThrottlePolicy(IThrottlePolicy::SP());
- ssp.setTimeout(400);
+ ssp.setTimeout(400s);
SourceSession::UP ss = srcNet.mb.createSourceSession(src, ssp);
DestinationSession::UP ds = dstNet.mb.createDestinationSession("session", true, dst);
- ASSERT_EQUAL(400u, ssp.getTimeout());
+ ASSERT_EQUAL(400s, ssp.getTimeout());
// wait for slobrok registration
ASSERT_TRUE(srcNet.waitSlobrok("test/dst/session"));
diff --git a/messagebus/src/tests/routable/routable.cpp b/messagebus/src/tests/routable/routable.cpp
index 18427a933cd..a7a35508656 100644
--- a/messagebus/src/tests/routable/routable.cpp
+++ b/messagebus/src/tests/routable/routable.cpp
@@ -11,6 +11,7 @@
#include <vespa/vespalib/testkit/testapp.h>
using namespace mbus;
+using namespace std::chrono_literals;
TEST_SETUP(Test);
@@ -26,14 +27,14 @@ Test::Main()
foo.setRoute(fooRoute);
foo.setRetry(1);
foo.setTimeReceivedNow();
- foo.setTimeRemaining(2);
+ foo.setTimeRemaining(2ms);
SimpleMessage bar("bar");
Route barRoute = Route::parse("bar");
bar.setRoute(barRoute);
bar.setRetry(3);
bar.setTimeReceivedNow();
- bar.setTimeRemaining(4);
+ bar.setTimeRemaining(4ms);
foo.swapState(bar);
EXPECT_EQUAL(barRoute.toString(), foo.getRoute().toString());
@@ -41,8 +42,8 @@ Test::Main()
EXPECT_EQUAL(3u, foo.getRetry());
EXPECT_EQUAL(1u, bar.getRetry());
EXPECT_TRUE(foo.getTimeReceived() >= bar.getTimeReceived());
- EXPECT_EQUAL(4u, foo.getTimeRemaining());
- EXPECT_EQUAL(2u, bar.getTimeRemaining());
+ EXPECT_EQUAL(4ms, foo.getTimeRemaining());
+ EXPECT_EQUAL(2ms, bar.getTimeRemaining());
}
{
// Test reply swap state.
@@ -73,7 +74,7 @@ Test::Main()
msg.discard();
Reply::UP reply = handler.getReply(0);
- ASSERT_TRUE(reply.get() == NULL);
+ ASSERT_FALSE(reply);
}
{
// Test reply discard logic.
@@ -86,7 +87,7 @@ Test::Main()
reply.discard();
Reply::UP ap = handler.getReply(0);
- ASSERT_TRUE(ap.get() == NULL);
+ ASSERT_FALSE(ap);
}
TEST_DONE();
diff --git a/messagebus/src/tests/timeout/timeout.cpp b/messagebus/src/tests/timeout/timeout.cpp
index 03a2c61a052..b2631e13d9c 100644
--- a/messagebus/src/tests/timeout/timeout.cpp
+++ b/messagebus/src/tests/timeout/timeout.cpp
@@ -13,6 +13,8 @@
#include <vespa/messagebus/testlib/testserver.h>
using namespace mbus;
+using namespace std::chrono_literals;
+
class Test : public vespalib::TestApp {
public:
@@ -42,7 +44,7 @@ Test::testZeroTimeout()
TestServer dstServer(Identity("dst"), RoutingSpec(), slobrok);
Receptor srcHandler;
- SourceSession::UP srcSession = srcServer.mb.createSourceSession(srcHandler, SourceSessionParams().setTimeout(0));
+ SourceSession::UP srcSession = srcServer.mb.createSourceSession(srcHandler, SourceSessionParams().setTimeout(0s));
Receptor dstHandler;
DestinationSession::UP dstSession = dstServer.mb.createDestinationSession("session", true, dstHandler);
@@ -50,7 +52,7 @@ Test::testZeroTimeout()
ASSERT_TRUE(srcSession->send(Message::UP(new SimpleMessage("msg")), "dst/session", true).isAccepted());
Reply::UP reply = srcHandler.getReply();
- ASSERT_TRUE(reply.get() != NULL);
+ ASSERT_TRUE(reply);
EXPECT_EQUAL(1u, reply->getNumErrors());
EXPECT_EQUAL((uint32_t)ErrorCode::TIMEOUT, reply->getError(0).getCode());
}
@@ -63,19 +65,19 @@ Test::testMessageExpires()
TestServer dstServer(Identity("dst"), RoutingSpec(), slobrok);
Receptor srcHandler, dstHandler;
- SourceSession::UP srcSession = srcServer.mb.createSourceSession(srcHandler, SourceSessionParams().setTimeout(1));
+ SourceSession::UP srcSession = srcServer.mb.createSourceSession(srcHandler, SourceSessionParams().setTimeout(1s));
DestinationSession::UP dstSession = dstServer.mb.createDestinationSession("session", true, dstHandler);
ASSERT_TRUE(srcServer.waitSlobrok("dst/session", 1));
ASSERT_TRUE(srcSession->send(Message::UP(new SimpleMessage("msg")), "dst/session", true).isAccepted());
Reply::UP reply = srcHandler.getReply();
- ASSERT_TRUE(reply.get() != NULL);
+ ASSERT_TRUE(reply);
EXPECT_EQUAL(1u, reply->getNumErrors());
EXPECT_EQUAL((uint32_t)ErrorCode::TIMEOUT, reply->getError(0).getCode());
Message::UP msg = dstHandler.getMessage(1);
- if (msg.get() != NULL) {
+ if (msg) {
msg->discard();
}
}
diff --git a/messagebus/src/vespa/messagebus/CMakeLists.txt b/messagebus/src/vespa/messagebus/CMakeLists.txt
index 9ff3bae67c8..1dfac1fbdac 100644
--- a/messagebus/src/vespa/messagebus/CMakeLists.txt
+++ b/messagebus/src/vespa/messagebus/CMakeLists.txt
@@ -30,7 +30,7 @@ vespa_add_library(messagebus
sourcesession.cpp
sourcesessionparams.cpp
staticthrottlepolicy.cpp
- systemtimer.cpp
+ steadytimer.cpp
$<TARGET_OBJECTS:messagebus_routing>
$<TARGET_OBJECTS:messagebus_network>
INSTALL lib64
diff --git a/messagebus/src/vespa/messagebus/common.h b/messagebus/src/vespa/messagebus/common.h
index 0e171b9f6d0..df25bf17973 100644
--- a/messagebus/src/vespa/messagebus/common.h
+++ b/messagebus/src/vespa/messagebus/common.h
@@ -2,11 +2,17 @@
#pragma once
#include <vespa/vespalib/stllike/string.h>
+#include <chrono>
namespace mbus {
// Decide the type of string used once
-typedef vespalib::string string;
+using string = vespalib::string;
+
+using seconds = std::chrono::duration<double>;
+using milliseconds = std::chrono::milliseconds;
+
+
} // namespace mbus
diff --git a/messagebus/src/vespa/messagebus/dynamicthrottlepolicy.cpp b/messagebus/src/vespa/messagebus/dynamicthrottlepolicy.cpp
index 55720f7d6ca..7145e0ec36d 100644
--- a/messagebus/src/vespa/messagebus/dynamicthrottlepolicy.cpp
+++ b/messagebus/src/vespa/messagebus/dynamicthrottlepolicy.cpp
@@ -1,6 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "dynamicthrottlepolicy.h"
-#include "systemtimer.h"
+#include "steadytimer.h"
#include <climits>
#include <vespa/log/log.h>
@@ -9,7 +9,7 @@ LOG_SETUP(".dynamicthrottlepolicy");
namespace mbus {
DynamicThrottlePolicy::DynamicThrottlePolicy() :
- _timer(new SystemTimer()),
+ _timer(new SteadyTimer()),
_numSent(0),
_numOk(0),
_resizeRate(3),
@@ -27,7 +27,7 @@ DynamicThrottlePolicy::DynamicThrottlePolicy() :
{ }
DynamicThrottlePolicy::DynamicThrottlePolicy(double windowSizeIncrement) :
- _timer(new SystemTimer()),
+ _timer(new SteadyTimer()),
_numSent(0),
_numOk(0),
_resizeRate(3),
diff --git a/messagebus/src/vespa/messagebus/message.cpp b/messagebus/src/vespa/messagebus/message.cpp
index c6d1bcce36f..af1d97334f6 100644
--- a/messagebus/src/vespa/messagebus/message.cpp
+++ b/messagebus/src/vespa/messagebus/message.cpp
@@ -10,6 +10,7 @@
#include <vespa/log/log.h>
LOG_SETUP(".message");
+using namespace std::chrono;
namespace mbus {
Message::Message() :
@@ -29,7 +30,7 @@ Message::~Message()
string backtrace = vespalib::getStackTrace(0);
LOG(warning, "Deleted message %p with non-empty call-stack. Deleted at:\n%s",
this, backtrace.c_str());
- Reply::UP reply(new EmptyReply());
+ auto reply = std::make_unique<EmptyReply>();
swapState(*reply);
reply->addError(Error(ErrorCode::TRANSIENT_ERROR,
"The message object was deleted while containing state information; "
@@ -55,23 +56,21 @@ Message::swapState(Routable &rhs)
}
Message &
-Message::setTimeReceived(uint64_t timeReceived)
+Message::setTimeReceivedNow()
{
- _timeReceived.SetMilliSecs(timeReceived);
+ _timeReceived = steady_clock::now();
return *this;
}
-Message &
-Message::setTimeReceivedNow()
-{
- _timeReceived.SetNow();
- return *this;
+steady_clock::time_point
+Message::getTimeReceived() const {
+ return _timeReceived;
}
-uint64_t
+milliseconds
Message::getTimeRemainingNow() const
{
- return (uint64_t)std::max(0.0, _timeRemaining - _timeReceived.MilliSecsToNow());
+ return std::max(milliseconds(0), _timeRemaining - duration_cast<milliseconds>(steady_clock::now() - _timeReceived));
}
} // namespace mbus
diff --git a/messagebus/src/vespa/messagebus/message.h b/messagebus/src/vespa/messagebus/message.h
index 539720374d0..4021143a052 100644
--- a/messagebus/src/vespa/messagebus/message.h
+++ b/messagebus/src/vespa/messagebus/message.h
@@ -3,8 +3,7 @@
#include "routable.h"
#include <vespa/messagebus/routing/route.h>
-#include <vespa/fastos/time.h>
-#include <memory>
+#include <chrono>
namespace mbus {
@@ -12,22 +11,10 @@ namespace mbus {
* A Message is a question, a Reply is the answer.
*/
class Message : public Routable {
-private:
- Route _route;
- FastOS_Time _timeReceived;
- uint64_t _timeRemaining;
- bool _retryEnabled;
- uint32_t _retry;
-
public:
- /**
- * Convenience typedef for an auto pointer to a Message object.
- */
- typedef std::unique_ptr<Message> UP;
+ using time_point = std::chrono::steady_clock::time_point;
+ using UP = std::unique_ptr<Message>;
- /**
- * Constructs a new instance of this class.
- */
Message();
Message(const Message &) = delete;
Message(Message &&) = delete;
@@ -39,7 +26,7 @@ public:
* will log an error and generate an auto-reply to avoid having the sender
* wait indefinetly for a reply.
*/
- ~Message();
+ ~Message() override;
void swapState(Routable &rhs) override;
@@ -50,20 +37,7 @@ public:
*
* @return The timestamp this was last seen.
*/
- uint64_t getTimeReceived() const { return (uint64_t)_timeReceived.MilliSecs(); }
-
- /**
- * Sets the timestamp for when this message was last seen by message bus to
- * the given time in milliseconds since epoch. Please see comment on {@link
- * #isExpired()} for more information on how to determine whether or not a
- * message has expired. You should never need to call this method yourself,
- * as it is touched automatically whenever message bus encounters a new
- * message.
- *
- * @param timeReceived The time received in milliseconds.
- * @return This, to allow chaining.
- */
- Message &setTimeReceived(uint64_t timeReceived);
+ time_point getTimeReceived() const;
/**
* This is a convenience method to call {@link #setTimeReceived(uint64_t)}
@@ -81,7 +55,7 @@ public:
*
* @return The remaining time in milliseconds.
*/
- uint64_t getTimeRemaining() const { return _timeRemaining; }
+ milliseconds getTimeRemaining() const { return _timeRemaining; }
/**
* Sets the numer of milliseconds that remain before this message times
@@ -91,7 +65,7 @@ public:
* @param timeRemaining The number of milliseconds until expiration.
* @return This, to allow chaining.
*/
- Message &setTimeRemaining(uint64_t timeRemaining) { _timeRemaining = timeRemaining; return *this; }
+ Message &setTimeRemaining(milliseconds timeRemaining) { _timeRemaining = timeRemaining; return *this; }
/**
* Returns the number of milliseconds that remain right now before this
@@ -105,15 +79,7 @@ public:
*
* @return The remaining time in milliseconds.
*/
- uint64_t getTimeRemainingNow() const;
-
- /**
- * Returns whether or not this message has expired.
- *
- * @return True if {@link this#getTimeRemainingNow()} is less than or equal
- * to zero.
- */
- bool isExpired() { return getTimeRemainingNow() == 0; }
+ milliseconds getTimeRemainingNow() const;
/**
* Access the route associated with this message.
@@ -173,16 +139,6 @@ public:
virtual bool hasBucketSequence() { return false; }
/**
- * Returns the identifier used to order message buckets. Any two messages
- * that have the same bucket sequence are ensured to arrive at the NEXT peer
- * in the order they were sent by THIS peer. This value is only respected if
- * the {@link #hasBucketSequence()} method returns true.
- *
- * @return The bucket sequence.
- */
- virtual uint64_t getBucketSequence() { return 0; }
-
- /**
* Obtain the approximate size of this message object in bytes. This enables
* messagebus to track the size of the send queue in both memory usage and
* item count. This method returns 1 by default, and must be overridden to
@@ -226,6 +182,12 @@ public:
* @return This, to allow chaining.
*/
Message &setRetry(uint32_t retry) { _retry = retry; return *this; }
+private:
+ Route _route;
+ time_point _timeReceived;
+ milliseconds _timeRemaining;
+ bool _retryEnabled;
+ uint32_t _retry;
};
} // namespace mbus
diff --git a/messagebus/src/vespa/messagebus/messagebus.cpp b/messagebus/src/vespa/messagebus/messagebus.cpp
index fd1ad2908c7..d277063a273 100644
--- a/messagebus/src/vespa/messagebus/messagebus.cpp
+++ b/messagebus/src/vespa/messagebus/messagebus.cpp
@@ -15,6 +15,7 @@ LOG_SETUP(".messagebus");
using vespalib::LockGuard;
using vespalib::make_string;
+using namespace std::chrono_literals;
namespace {
@@ -64,7 +65,7 @@ public:
_gate(gate)
{ }
- ~ShutdownTask() {
+ ~ShutdownTask() override {
_gate.countDown();
}
@@ -150,7 +151,7 @@ MessageBus::setup(const MessageBusParams &params)
if (!_network.start()) {
throw vespalib::NetworkSetupFailureException("Failed to start network.");
}
- if (!_network.waitUntilReady(120)) {
+ if (!_network.waitUntilReady(120s)) {
throw vespalib::NetworkSetupFailureException("Network failed to become ready in time.");
}
@@ -396,7 +397,7 @@ MessageBus::deliverReply(Reply::UP reply, IReplyHandler &handler)
_msn->deliverReply(std::move(reply), handler);
}
-const string
+string
MessageBus::getConnectionSpec() const
{
return _network.getConnectionSpec();
diff --git a/messagebus/src/vespa/messagebus/messagebus.h b/messagebus/src/vespa/messagebus/messagebus.h
index d00444b563a..f10898275b3 100644
--- a/messagebus/src/vespa/messagebus/messagebus.h
+++ b/messagebus/src/vespa/messagebus/messagebus.h
@@ -274,7 +274,7 @@ public:
*
* @return The connection string.
*/
- const string getConnectionSpec() const;
+ string getConnectionSpec() const;
/**
* Provide access to the underlying {@link Messenger} object.
diff --git a/messagebus/src/vespa/messagebus/network/inetwork.h b/messagebus/src/vespa/messagebus/network/inetwork.h
index a22e9fe9e11..037298cf7c0 100644
--- a/messagebus/src/vespa/messagebus/network/inetwork.h
+++ b/messagebus/src/vespa/messagebus/network/inetwork.h
@@ -62,7 +62,7 @@ public:
* @param seconds The timeout.
* @return True if ready.
*/
- virtual bool waitUntilReady(double seconds) const = 0;
+ virtual bool waitUntilReady(seconds timeout) const = 0;
/**
* Register a session name with the network layer. This will make the
diff --git a/messagebus/src/vespa/messagebus/network/rpcnetwork.cpp b/messagebus/src/vespa/messagebus/network/rpcnetwork.cpp
index e214a435a4e..5ae6b07c3fa 100644
--- a/messagebus/src/vespa/messagebus/network/rpcnetwork.cpp
+++ b/messagebus/src/vespa/messagebus/network/rpcnetwork.cpp
@@ -7,7 +7,6 @@
#include "rpcnetworkparams.h"
#include <vespa/messagebus/errorcode.h>
#include <vespa/messagebus/iprotocol.h>
-#include <vespa/messagebus/tracelevel.h>
#include <vespa/messagebus/emptyreply.h>
#include <vespa/messagebus/routing/routingnode.h>
#include <vespa/slobrok/sbregister.h>
@@ -15,7 +14,6 @@
#include <vespa/vespalib/component/vtag.h>
#include <vespa/vespalib/stllike/asciistream.h>
#include <vespa/vespalib/util/stringfmt.h>
-#include <vespa/vespalib/util/lambdatask.h>
#include <vespa/fnet/scheduler.h>
#include <vespa/fnet/transport.h>
#include <vespa/fnet/frt/supervisor.h>
@@ -46,7 +44,7 @@ public:
_gate() {
ScheduleNow();
}
- ~SyncTask() = default;
+ ~SyncTask() override = default;
void await() {
_gate.await();
@@ -227,12 +225,12 @@ RPCNetwork::start()
}
bool
-RPCNetwork::waitUntilReady(double seconds) const
+RPCNetwork::waitUntilReady(seconds timeout) const
{
slobrok::api::SlobrokList brokerList;
slobrok::Configurator::UP configurator = _slobrokCfgFactory->create(brokerList);
bool hasConfig = false;
- for (uint32_t i = 0; i < seconds * 100; ++i) {
+ for (uint32_t i = 0; i < timeout.count() * 100; ++i) {
if (configurator->poll()) {
hasConfig = true;
}
@@ -242,10 +240,10 @@ RPCNetwork::waitUntilReady(double seconds) const
std::this_thread::sleep_for(10ms);
}
if (! hasConfig) {
- LOG(error, "failed to get config for slobroks in %d seconds", (int)seconds);
+ LOG(error, "failed to get config for slobroks in %2.2f seconds", timeout.count());
} else if (! _mirror->ready()) {
auto brokers = brokerList.logString();
- LOG(error, "mirror (of %s) failed to become ready in %d seconds", brokers.c_str(), (int)seconds);
+ LOG(error, "mirror (of %s) failed to become ready in %2.2f seconds", brokers.c_str(), timeout.count());
}
return false;
}
@@ -322,7 +320,7 @@ void
RPCNetwork::send(const Message &msg, const std::vector<RoutingNode*> &recipients)
{
SendContext &ctx = *(new SendContext(*this, msg, recipients)); // deletes self
- double timeout = ctx._msg.getTimeRemainingNow() / 1000.0;
+ seconds timeout = ctx._msg.getTimeRemainingNow();
for (uint32_t i = 0, len = ctx._recipients.size(); i < len; ++i) {
RoutingNode *&recipient = ctx._recipients[i];
@@ -335,7 +333,8 @@ RPCNetwork::send(const Message &msg, const std::vector<RoutingNode*> &recipients
namespace {
-void emit_recipient_endpoint(vespalib::asciistream& stream, const RoutingNode& recipient) {
+void
+emit_recipient_endpoint(vespalib::asciistream& stream, const RoutingNode& recipient) {
if (recipient.hasServiceAddress()) {
// At this point the service addresses _should_ be RPCServiceAddress instances,
// but stay on the safe side of the tracks anyway.
@@ -352,7 +351,8 @@ void emit_recipient_endpoint(vespalib::asciistream& stream, const RoutingNode& r
}
-vespalib::string RPCNetwork::buildRecipientListString(const SendContext& ctx) {
+vespalib::string
+RPCNetwork::buildRecipientListString(const SendContext& ctx) {
vespalib::asciistream s;
bool first = true;
for (const auto* recipient : ctx._recipients) {
@@ -373,13 +373,13 @@ RPCNetwork::send(RPCNetwork::SendContext &ctx)
make_string("An error occurred while resolving version of recipient(s) [%s] from host '%s'.",
buildRecipientListString(ctx).c_str(), getIdentity().getHostname().c_str()));
} else {
- uint64_t timeRemaining = ctx._msg.getTimeRemainingNow();
+ std::chrono::milliseconds timeRemaining = ctx._msg.getTimeRemainingNow();
Blob payload = _owner->getProtocol(ctx._msg.getProtocol())->encode(ctx._version, ctx._msg);
RPCSendAdapter *adapter = getSendAdapter(ctx._version);
if (adapter == nullptr) {
replyError(ctx, ErrorCode::INCOMPATIBLE_VERSION,
make_string("Can not send to version '%s' recipient.", ctx._version.toString().c_str()));
- } else if (timeRemaining == 0) {
+ } else if (timeRemaining == 0ms) {
replyError(ctx, ErrorCode::TIMEOUT, "Aborting transmission because zero time remains.");
} else if (payload.size() == 0) {
replyError(ctx, ErrorCode::ENCODE_ERROR,
diff --git a/messagebus/src/vespa/messagebus/network/rpcnetwork.h b/messagebus/src/vespa/messagebus/network/rpcnetwork.h
index 123987fea68..169bdd86dd9 100644
--- a/messagebus/src/vespa/messagebus/network/rpcnetwork.h
+++ b/messagebus/src/vespa/messagebus/network/rpcnetwork.h
@@ -219,7 +219,7 @@ public:
void attach(INetworkOwner &owner) override;
const string getConnectionSpec() const override;
bool start() override;
- bool waitUntilReady(double seconds) const override;
+ bool waitUntilReady(seconds timout) const override;
void registerSession(const string &session) override;
void unregisterSession(const string &session) override;
bool allocServiceAddress(RoutingNode &recipient) override;
diff --git a/messagebus/src/vespa/messagebus/network/rpcsend.cpp b/messagebus/src/vespa/messagebus/network/rpcsend.cpp
index 87c87173ec7..e0fae8eabd6 100644
--- a/messagebus/src/vespa/messagebus/network/rpcsend.cpp
+++ b/messagebus/src/vespa/messagebus/network/rpcsend.cpp
@@ -98,20 +98,20 @@ RPCSend::handleDiscard(Context ctx)
}
void
-RPCSend::sendByHandover(RoutingNode &recipient, const vespalib::Version &version, Blob payload, uint64_t timeRemaining)
+RPCSend::sendByHandover(RoutingNode &recipient, const vespalib::Version &version, Blob payload, milliseconds timeRemaining)
{
send(recipient, version, FillByHandover(std::move(payload)), timeRemaining);
}
void
-RPCSend::send(RoutingNode &recipient, const vespalib::Version &version, BlobRef payload, uint64_t timeRemaining)
+RPCSend::send(RoutingNode &recipient, const vespalib::Version &version, BlobRef payload, milliseconds timeRemaining)
{
send(recipient, version, FillByCopy(payload), timeRemaining);
}
void
RPCSend::send(RoutingNode &recipient, const vespalib::Version &version,
- const PayLoadFiller & payload, uint64_t timeRemaining)
+ const PayLoadFiller & payload, milliseconds timeRemaining)
{
SendContext::UP ctx(new SendContext(recipient, timeRemaining));
RPCServiceAddress &address = static_cast<RPCServiceAddress&>(recipient.getServiceAddress());
@@ -126,7 +126,7 @@ RPCSend::send(RoutingNode &recipient, const vespalib::Version &version,
ctx->getTrace().trace(TraceLevel::SEND_RECEIVE,
make_string("Sending message (version %s) from %s to '%s' with %.2f seconds timeout.",
version.toString().c_str(), _clientIdent.c_str(),
- address.getServiceName().c_str(), ctx->getTimeout()));
+ address.getServiceName().c_str(), ctx->getTimeout().count()));
}
if (hop.getIgnoreResult()) {
@@ -141,7 +141,7 @@ RPCSend::send(RoutingNode &recipient, const vespalib::Version &version,
} else {
SendContext *ptr = ctx.release();
req->SetContext(FNET_Context(ptr));
- address.getTarget().getFRTTarget().InvokeAsync(req, ptr->getTimeout(), this);
+ address.getTarget().getFRTTarget().InvokeAsync(req, ptr->getTimeout().count(), this);
}
}
@@ -164,7 +164,7 @@ RPCSend::doRequestDone(FRT_RPCRequest *req) {
case FRTE_RPC_TIMEOUT:
error = Error(ErrorCode::TIMEOUT,
make_string("A timeout occured while waiting for '%s' (%g seconds expired); %s",
- serviceName.c_str(), ctx->getTimeout(), req->GetErrorMessage()));
+ serviceName.c_str(), ctx->getTimeout().count(), req->GetErrorMessage()));
break;
case FRTE_RPC_CONNECTION:
error = Error(ErrorCode::CONNECTION_ERROR,
diff --git a/messagebus/src/vespa/messagebus/network/rpcsend.h b/messagebus/src/vespa/messagebus/network/rpcsend.h
index 051abff6d1b..e7bf5495974 100644
--- a/messagebus/src/vespa/messagebus/network/rpcsend.h
+++ b/messagebus/src/vespa/messagebus/network/rpcsend.h
@@ -44,7 +44,7 @@ public:
virtual uint32_t getTraceLevel() const = 0;
virtual bool useRetry() const = 0;
virtual uint32_t getRetries() const = 0;
- virtual uint64_t getRemainingTime() const = 0;
+ virtual milliseconds getRemainingTime() const = 0;
virtual vespalib::stringref getRoute() const = 0;
virtual vespalib::stringref getSession() const = 0;
virtual BlobRef getPayload() const = 0;
@@ -59,13 +59,13 @@ protected:
Error & error, vespalib::TraceNode & rootTrace) const = 0;
virtual void encodeRequest(FRT_RPCRequest &req, const vespalib::Version &version, const Route & route,
const RPCServiceAddress & address, const Message & msg, uint32_t traceLevel,
- const PayLoadFiller &filler, uint64_t timeRemaining) const = 0;
+ const PayLoadFiller &filler, milliseconds timeRemaining) const = 0;
virtual const char * getReturnSpec() const = 0;
virtual void createResponse(FRT_Values & ret, const string & version, Reply & reply, Blob payload) const = 0;
virtual std::unique_ptr<Params> toParams(const FRT_Values &param) const = 0;
void send(RoutingNode &recipient, const vespalib::Version &version,
- const PayLoadFiller & filler, uint64_t timeRemaining);
+ const PayLoadFiller & filler, milliseconds timeRemaining);
std::unique_ptr<Reply> decode(vespalib::stringref protocol, const vespalib::Version & version,
BlobRef payload, Error & error) const;
/**
@@ -89,9 +89,9 @@ private:
void attach(RPCNetwork &net) final override;
void handleDiscard(Context ctx) final override;
void sendByHandover(RoutingNode &recipient, const vespalib::Version &version,
- Blob payload, uint64_t timeRemaining) final override;
+ Blob payload, milliseconds timeRemaining) final override;
void send(RoutingNode &recipient, const vespalib::Version &version,
- BlobRef payload, uint64_t timeRemaining) final override;
+ BlobRef payload, milliseconds timeRemaining) final override;
void RequestDone(FRT_RPCRequest *req) final override;
void handleReply(std::unique_ptr<Reply> reply) final override;
};
diff --git a/messagebus/src/vespa/messagebus/network/rpcsend_private.h b/messagebus/src/vespa/messagebus/network/rpcsend_private.h
index f5867e79856..0b620b3b11f 100644
--- a/messagebus/src/vespa/messagebus/network/rpcsend_private.h
+++ b/messagebus/src/vespa/messagebus/network/rpcsend_private.h
@@ -10,22 +10,22 @@ namespace mbus::network::internal {
* an rpc return value. This object is held as the context of an FRT_RPCRequest.
*/
class SendContext {
-private:
- mbus::RoutingNode &_recipient;
- mbus::Trace _trace;
- double _timeout;
-
public:
- typedef std::unique_ptr<SendContext> UP;
+ using UP = std::unique_ptr<SendContext>;
SendContext(const SendContext &) = delete;
SendContext & operator = (const SendContext &) = delete;
- SendContext(mbus::RoutingNode &recipient, uint64_t timeRemaining)
- : _recipient(recipient),
- _trace(recipient.getTrace().getLevel()),
- _timeout(timeRemaining * 0.001) { }
+ SendContext(mbus::RoutingNode &recipient, milliseconds timeRemaining)
+ : _recipient(recipient),
+ _trace(recipient.getTrace().getLevel()),
+ _timeout(timeRemaining)
+ { }
mbus::RoutingNode &getRecipient() { return _recipient; }
mbus::Trace &getTrace() { return _trace; }
- double getTimeout() { return _timeout; }
+ seconds getTimeout() { return _timeout; }
+private:
+ mbus::RoutingNode &_recipient;
+ mbus::Trace _trace;
+ seconds _timeout;
};
/**
diff --git a/messagebus/src/vespa/messagebus/network/rpcsendadapter.h b/messagebus/src/vespa/messagebus/network/rpcsendadapter.h
index d06f3531ca5..cc89bb022b9 100644
--- a/messagebus/src/vespa/messagebus/network/rpcsendadapter.h
+++ b/messagebus/src/vespa/messagebus/network/rpcsendadapter.h
@@ -2,6 +2,7 @@
#pragma once
#include <vespa/messagebus/blobref.h>
+#include <vespa/messagebus/common.h>
#include <vespa/vespalib/component/version.h>
namespace mbus {
@@ -42,7 +43,7 @@ public:
* @param timeRemaining The time remaining until the message expires.
*/
virtual void send(RoutingNode &recipient, const vespalib::Version &version,
- BlobRef payload, uint64_t timeRemaining) = 0;
+ BlobRef payload, milliseconds timeRemaining) = 0;
/**
* Performs the actual sending to the given recipient.
@@ -53,7 +54,7 @@ public:
* @param timeRemaining The time remaining until the message expires.
*/
virtual void sendByHandover(RoutingNode &recipient, const vespalib::Version &version,
- Blob payload, uint64_t timeRemaining) = 0;
+ Blob payload, milliseconds timeRemaining) = 0;
};
} // namespace mbus
diff --git a/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp b/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp
index 376267b555c..e902aa20965 100644
--- a/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp
+++ b/messagebus/src/vespa/messagebus/network/rpcsendv1.cpp
@@ -59,7 +59,7 @@ RPCSendV1::build(FRT_ReflectionBuilder & builder)
void
RPCSendV1::encodeRequest(FRT_RPCRequest &req, const vespalib::Version &version, const Route & route,
const RPCServiceAddress & address, const Message & msg, uint32_t traceLevel,
- const PayLoadFiller &filler, uint64_t timeRemaining) const
+ const PayLoadFiller &filler, milliseconds timeRemaining) const
{
FRT_Values &args = *req.GetParams();
@@ -69,7 +69,7 @@ RPCSendV1::encodeRequest(FRT_RPCRequest &req, const vespalib::Version &version,
args.AddString(address.getSessionName().c_str());
args.AddInt8(msg.getRetryEnabled() ? 1 : 0);
args.AddInt32(msg.getRetry());
- args.AddInt64(timeRemaining);
+ args.AddInt64(timeRemaining.count());
args.AddString(msg.getProtocol().c_str());
filler.fill(args);
args.AddInt32(traceLevel);
@@ -85,7 +85,7 @@ public:
uint32_t getTraceLevel() const override { return _args[8]._intval32; }
bool useRetry() const override { return _args[3]._intval8 != 0; }
uint32_t getRetries() const override { return _args[4]._intval32; }
- uint64_t getRemainingTime() const override { return _args[5]._intval64; }
+ milliseconds getRemainingTime() const override { return milliseconds(_args[5]._intval64); }
vespalib::Version getVersion() const override {
return vespalib::Version(vespalib::stringref(_args[0]._string._str, _args[0]._string._len));
diff --git a/messagebus/src/vespa/messagebus/network/rpcsendv1.h b/messagebus/src/vespa/messagebus/network/rpcsendv1.h
index 37f23335309..3265c304830 100644
--- a/messagebus/src/vespa/messagebus/network/rpcsendv1.h
+++ b/messagebus/src/vespa/messagebus/network/rpcsendv1.h
@@ -14,7 +14,7 @@ private:
std::unique_ptr<Params> toParams(const FRT_Values &param) const override;
void encodeRequest(FRT_RPCRequest &req, const vespalib::Version &version, const Route & route,
const RPCServiceAddress & address, const Message & msg, uint32_t traceLevel,
- const PayLoadFiller &filler, uint64_t timeRemaining) const override;
+ const PayLoadFiller &filler, milliseconds timeRemaining) const override;
std::unique_ptr<Reply> createReply(const FRT_Values & response, const string & serviceName,
Error & error, vespalib::TraceNode & rootTrace) const override;
diff --git a/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp b/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp
index 91a41a6a800..3e453bb60eb 100644
--- a/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp
+++ b/messagebus/src/vespa/messagebus/network/rpcsendv2.cpp
@@ -101,7 +101,7 @@ private:
void
RPCSendV2::encodeRequest(FRT_RPCRequest &req, const Version &version, const Route & route,
const RPCServiceAddress & address, const Message & msg, uint32_t traceLevel,
- const PayLoadFiller &filler, uint64_t timeRemaining) const
+ const PayLoadFiller &filler, milliseconds timeRemaining) const
{
FRT_Values &args = *req.GetParams();
req.SetMethodName(METHOD_NAME);
@@ -118,7 +118,7 @@ RPCSendV2::encodeRequest(FRT_RPCRequest &req, const Version &version, const Rout
root.setString(SESSION_F, address.getSessionName());
root.setBool(USERETRY_F, msg.getRetryEnabled());
root.setLong(RETRY_F, msg.getRetry());
- root.setLong(TIMELEFT_F, timeRemaining);
+ root.setLong(TIMELEFT_F, timeRemaining.count());
root.setString(PROTOCOL_F, msg.getProtocol());
root.setLong(TRACELEVEL_F, traceLevel);
filler.fill(BLOB_F, root);
@@ -156,7 +156,7 @@ public:
uint32_t getTraceLevel() const override { return _slime.get()[TRACELEVEL_F].asLong(); }
bool useRetry() const override { return _slime.get()[USERETRY_F].asBool(); }
uint32_t getRetries() const override { return _slime.get()[RETRY_F].asLong(); }
- uint64_t getRemainingTime() const override { return _slime.get()[TIMELEFT_F].asLong(); }
+ milliseconds getRemainingTime() const override { return milliseconds(_slime.get()[TIMELEFT_F].asLong()); }
Version getVersion() const override {
return Version(_slime.get()[VERSION_F].asString().make_stringref());
diff --git a/messagebus/src/vespa/messagebus/network/rpcsendv2.h b/messagebus/src/vespa/messagebus/network/rpcsendv2.h
index e793868d2aa..939c37c81b2 100644
--- a/messagebus/src/vespa/messagebus/network/rpcsendv2.h
+++ b/messagebus/src/vespa/messagebus/network/rpcsendv2.h
@@ -14,7 +14,7 @@ private:
std::unique_ptr<Params> toParams(const FRT_Values &param) const override;
void encodeRequest(FRT_RPCRequest &req, const vespalib::Version &version, const Route & route,
const RPCServiceAddress & address, const Message & msg, uint32_t traceLevel,
- const PayLoadFiller &filler, uint64_t timeRemaining) const override;
+ const PayLoadFiller &filler, milliseconds timeRemaining) const override;
std::unique_ptr<Reply> createReply(const FRT_Values & response, const string & serviceName,
Error & error, vespalib::TraceNode & rootTrace) const override;
diff --git a/messagebus/src/vespa/messagebus/network/rpctarget.cpp b/messagebus/src/vespa/messagebus/network/rpctarget.cpp
index 04423b5e90b..bb3bf1d172d 100644
--- a/messagebus/src/vespa/messagebus/network/rpctarget.cpp
+++ b/messagebus/src/vespa/messagebus/network/rpctarget.cpp
@@ -23,7 +23,7 @@ RPCTarget::~RPCTarget()
}
void
-RPCTarget::resolveVersion(double timeout, RPCTarget::IVersionHandler &handler)
+RPCTarget::resolveVersion(seconds timeout, RPCTarget::IVersionHandler &handler)
{
bool hasVersion = false;
bool shouldInvoke = false;
@@ -47,7 +47,7 @@ RPCTarget::resolveVersion(double timeout, RPCTarget::IVersionHandler &handler)
} else if (shouldInvoke) {
FRT_RPCRequest *req = _orb.AllocRPCRequest();
req->SetMethodName("mbus.getVersion");
- _target.InvokeAsync(req, timeout, this);
+ _target.InvokeAsync(req, timeout.count(), this);
}
}
@@ -84,10 +84,8 @@ RPCTarget::RequestDone(FRT_RPCRequest *req)
_versionHandlers.swap(handlers);
_state = PROCESSING_HANDLERS;
}
- for (HandlerList::iterator it = handlers.begin();
- it != handlers.end(); ++it)
- {
- (*it)->handleVersion(_version.get());
+ for (IVersionHandler * handler : handlers) {
+ handler->handleVersion(_version.get());
}
{
vespalib::MonitorGuard guard(_lock);
diff --git a/messagebus/src/vespa/messagebus/network/rpctarget.h b/messagebus/src/vespa/messagebus/network/rpctarget.h
index cd1028d6df4..9c089381de7 100644
--- a/messagebus/src/vespa/messagebus/network/rpctarget.h
+++ b/messagebus/src/vespa/messagebus/network/rpctarget.h
@@ -88,7 +88,7 @@ public:
* @param timeout The timeout for the request in milliseconds.
* @param handler The handler to be called once the version is available.
*/
- void resolveVersion(double timeout, IVersionHandler &handler);
+ void resolveVersion(seconds timeout, IVersionHandler &handler);
/**
* @return true if the FRT target is valid or has been invoked (which
diff --git a/messagebus/src/vespa/messagebus/network/rpctargetpool.cpp b/messagebus/src/vespa/messagebus/network/rpctargetpool.cpp
index 6dca636cad2..7fcc214faa7 100644
--- a/messagebus/src/vespa/messagebus/network/rpctargetpool.cpp
+++ b/messagebus/src/vespa/messagebus/network/rpctargetpool.cpp
@@ -1,6 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "rpctargetpool.h"
-#include <vespa/messagebus/systemtimer.h>
+#include <vespa/messagebus/steadytimer.h>
namespace mbus {
@@ -12,7 +12,7 @@ RPCTargetPool::Entry::Entry(RPCTarget::SP target, uint64_t lastUse) :
RPCTargetPool::RPCTargetPool(double expireSecs) :
_lock(),
_targets(),
- _timer(new SystemTimer()),
+ _timer(new SteadyTimer()),
_expireMillis(static_cast<uint64_t>(expireSecs * 1000))
{ }
diff --git a/messagebus/src/vespa/messagebus/reply.h b/messagebus/src/vespa/messagebus/reply.h
index a7040c0cbb9..64b9f5c0b13 100644
--- a/messagebus/src/vespa/messagebus/reply.h
+++ b/messagebus/src/vespa/messagebus/reply.h
@@ -40,7 +40,7 @@ public:
* will log an error and generate an auto-reply to avoid having the sender
* wait indefinetly for a reply.
*/
- ~Reply();
+ ~Reply() override;
void swapState(Routable &rhs) override;
bool isReply() const override;
diff --git a/messagebus/src/vespa/messagebus/routablequeue.cpp b/messagebus/src/vespa/messagebus/routablequeue.cpp
index a3ba2ffadd3..eb2d93c6688 100644
--- a/messagebus/src/vespa/messagebus/routablequeue.cpp
+++ b/messagebus/src/vespa/messagebus/routablequeue.cpp
@@ -2,6 +2,8 @@
#include "routablequeue.h"
+using namespace std::chrono;
+
namespace mbus {
RoutableQueue::RoutableQueue()
@@ -39,15 +41,14 @@ RoutableQueue::enqueue(Routable::UP r)
Routable::UP
RoutableQueue::dequeue(uint32_t msTimeout)
{
- FastOS_Time t;
- t.SetNow();
- uint32_t msLeft = msTimeout;
+ steady_clock::time_point startTime = steady_clock::now();
+ uint64_t msLeft = msTimeout;
vespalib::MonitorGuard guard(_monitor);
while (_queue.size() == 0 && msLeft > 0) {
if (!guard.wait(msLeft) || _queue.size() > 0) {
break;
}
- uint32_t elapsed = (uint32_t)t.MilliSecsToNow();
+ uint64_t elapsed = duration_cast<milliseconds>(steady_clock::now() - startTime).count();
msLeft = (elapsed > msTimeout) ? 0 : msTimeout - elapsed;
}
if (_queue.size() == 0) {
diff --git a/messagebus/src/vespa/messagebus/routing/resender.cpp b/messagebus/src/vespa/messagebus/routing/resender.cpp
index 0ba6e0827b2..979a9d61491 100644
--- a/messagebus/src/vespa/messagebus/routing/resender.cpp
+++ b/messagebus/src/vespa/messagebus/routing/resender.cpp
@@ -6,15 +6,14 @@
#include <vespa/messagebus/tracelevel.h>
#include <vespa/vespalib/util/stringfmt.h>
+using namespace std::chrono;
+
namespace mbus {
Resender::Resender(IRetryPolicy::SP retryPolicy) :
_queue(),
- _retryPolicy(retryPolicy),
- _time()
-{
- _time.SetNow();
-}
+ _retryPolicy(retryPolicy)
+{ }
Resender::~Resender()
{
@@ -30,18 +29,15 @@ Resender::resendScheduled()
typedef std::vector<RoutingNode*> NodeList;
NodeList sendList;
- double now = _time.MilliSecsToNow();
+ time_point now = steady_clock::now();
while (!_queue.empty() && _queue.top().first <= now) {
sendList.push_back(_queue.top().second);
_queue.pop();
}
- for (NodeList::iterator it = sendList.begin();
- it != sendList.end(); ++it)
- {
- (*it)->getTrace().trace(mbus::TraceLevel::COMPONENT,
- "Resender resending message.");
- (*it)->send();
+ for (RoutingNode *node : sendList) {
+ node->getTrace().trace(mbus::TraceLevel::COMPONENT, "Resender resending message.");
+ node->send();
}
}
@@ -78,7 +74,8 @@ Resender::scheduleRetry(RoutingNode &node)
if (delay < 0) {
delay = _retryPolicy->getRetryDelay(retry);
}
- if (msg.getTimeRemainingNow() * 0.001 - delay <= 0) {
+ milliseconds delayMS(long(delay * 1000));
+ if (msg.getTimeRemainingNow() <= delayMS) {
node.addError(ErrorCode::TIMEOUT, "Timeout exceeded by resender, giving up.");
return false;
}
@@ -87,7 +84,7 @@ Resender::scheduleRetry(RoutingNode &node)
TraceLevel::COMPONENT,
vespalib::make_string("Message scheduled for retry %u in %.3f seconds.", retry, delay));
msg.setRetry(retry);
- _queue.push(Entry((uint64_t)(_time.MilliSecsToNow() + delay * 1000), &node));
+ _queue.push(Entry(steady_clock::now() + delayMS, &node));
return true;
}
diff --git a/messagebus/src/vespa/messagebus/routing/resender.h b/messagebus/src/vespa/messagebus/routing/resender.h
index 93752dcfd5c..68b49cde606 100644
--- a/messagebus/src/vespa/messagebus/routing/resender.h
+++ b/messagebus/src/vespa/messagebus/routing/resender.h
@@ -5,7 +5,6 @@
#include <vespa/messagebus/queue.h>
#include <vespa/messagebus/reply.h>
#include <vespa/vespalib/util/sync.h>
-#include <vespa/fastos/time.h>
#include <queue>
#include <vector>
@@ -23,18 +22,17 @@ class RoutingNode;
class Resender
{
private:
- typedef std::pair<uint64_t, RoutingNode*> Entry;
+ using time_point = std::chrono::steady_clock::time_point;
+ typedef std::pair<time_point , RoutingNode*> Entry;
struct Cmp {
bool operator()(const Entry &a, const Entry &b) {
return (b.first < a.first);
}
};
- typedef std::priority_queue<Entry, std::vector<Entry>, Cmp> PriorityQueue;
+ using PriorityQueue = std::priority_queue<Entry, std::vector<Entry>, Cmp>;
PriorityQueue _queue;
IRetryPolicy::SP _retryPolicy;
- FastOS_Time _time;
-
public:
/**
* Convenience typedefs.
diff --git a/messagebus/src/vespa/messagebus/sourcesession.cpp b/messagebus/src/vespa/messagebus/sourcesession.cpp
index 1f6758b92c3..41fe01625ae 100644
--- a/messagebus/src/vespa/messagebus/sourcesession.cpp
+++ b/messagebus/src/vespa/messagebus/sourcesession.cpp
@@ -9,6 +9,9 @@
using vespalib::make_string;
+using namespace std::chrono_literals;
+using namespace std::chrono;
+
namespace mbus {
SourceSession::SourceSession(MessageBus &mbus, const SourceSessionParams &params)
@@ -71,8 +74,8 @@ Result
SourceSession::send(Message::UP msg)
{
msg->setTimeReceivedNow();
- if (msg->getTimeRemaining() == 0) {
- msg->setTimeRemaining((uint64_t)(_timeout * 1000));
+ if (msg->getTimeRemaining() == 0ms) {
+ msg->setTimeRemaining(duration_cast<milliseconds>(_timeout));
}
{
vespalib::MonitorGuard guard(_monitor);
@@ -145,7 +148,7 @@ SourceSession &
SourceSession::setTimeout(double timeout)
{
vespalib::MonitorGuard guard(_monitor);
- _timeout = timeout;
+ _timeout = seconds(timeout);
return *this;
}
diff --git a/messagebus/src/vespa/messagebus/sourcesession.h b/messagebus/src/vespa/messagebus/sourcesession.h
index 2ce8eea384c..31ebec3555e 100644
--- a/messagebus/src/vespa/messagebus/sourcesession.h
+++ b/messagebus/src/vespa/messagebus/sourcesession.h
@@ -27,7 +27,7 @@ private:
Sequencer _sequencer;
IReplyHandler &_replyHandler;
IThrottlePolicy::SP _throttlePolicy;
- double _timeout;
+ seconds _timeout;
uint32_t _pendingCount;
bool _closed;
bool _done;
@@ -53,7 +53,7 @@ public:
* messages. After this method returns, messagebus will not invoke any handlers associated with this
* session.
**/
- virtual ~SourceSession();
+ ~SourceSession() override;
/**
* This is a convenience function to assign a named route to the given message, and then pass it to the
diff --git a/messagebus/src/vespa/messagebus/sourcesessionparams.cpp b/messagebus/src/vespa/messagebus/sourcesessionparams.cpp
index 51fe91562ae..e7a99f2a1de 100644
--- a/messagebus/src/vespa/messagebus/sourcesessionparams.cpp
+++ b/messagebus/src/vespa/messagebus/sourcesessionparams.cpp
@@ -24,14 +24,14 @@ SourceSessionParams::setThrottlePolicy(IThrottlePolicy::SP throttlePolicy)
return *this;
}
-double
+seconds
SourceSessionParams::getTimeout() const
{
return _timeout;
}
SourceSessionParams &
-SourceSessionParams::setTimeout(double timeout)
+SourceSessionParams::setTimeout(seconds timeout)
{
_timeout = timeout;
return *this;
diff --git a/messagebus/src/vespa/messagebus/sourcesessionparams.h b/messagebus/src/vespa/messagebus/sourcesessionparams.h
index 7c14ee4524d..9ee17280d40 100644
--- a/messagebus/src/vespa/messagebus/sourcesessionparams.h
+++ b/messagebus/src/vespa/messagebus/sourcesessionparams.h
@@ -3,6 +3,7 @@
#include "ireplyhandler.h"
#include "ithrottlepolicy.h"
+#include <chrono>
namespace mbus {
@@ -12,13 +13,12 @@ namespace mbus {
* parameter.
*
* @author Simon Thoresen Hult
- * @version $Id$
*/
class SourceSessionParams {
private:
IReplyHandler *_replyHandler;
IThrottlePolicy::SP _throttlePolicy;
- double _timeout;
+ seconds _timeout;
public:
/**
@@ -46,14 +46,14 @@ public:
*
* @return The total timeout parameter.
*/
- double getTimeout() const;
+ seconds getTimeout() const;
/**
* Returns the number of seconds a message can spend trying to succeed.
*
* @return The timeout in seconds.
*/
- SourceSessionParams &setTimeout(double timeout);
+ SourceSessionParams &setTimeout(seconds timeout);
/**
* Returns whether or not a reply handler has been assigned to this.
diff --git a/messagebus/src/vespa/messagebus/steadytimer.cpp b/messagebus/src/vespa/messagebus/steadytimer.cpp
new file mode 100644
index 00000000000..f64c8f361cd
--- /dev/null
+++ b/messagebus/src/vespa/messagebus/steadytimer.cpp
@@ -0,0 +1,15 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include "steadytimer.h"
+#include <chrono>
+
+using namespace std::chrono;
+
+namespace mbus {
+
+uint64_t
+SteadyTimer::getMilliTime() const
+{
+ return duration_cast<milliseconds>(steady_clock::now().time_since_epoch()).count();
+}
+
+} // namespace mbus
diff --git a/messagebus/src/vespa/messagebus/systemtimer.h b/messagebus/src/vespa/messagebus/steadytimer.h
index aff3dc87e75..919dd54b7d5 100644
--- a/messagebus/src/vespa/messagebus/systemtimer.h
+++ b/messagebus/src/vespa/messagebus/steadytimer.h
@@ -10,8 +10,9 @@ namespace mbus {
* constructs in message bus use by default. The only reason for replacing this
* is for writing unit tests.
*/
-class SystemTimer : public ITimer {
+class SteadyTimer : public ITimer {
public:
+ //TODO Return chrono::duration
uint64_t getMilliTime() const override;
};
diff --git a/messagebus/src/vespa/messagebus/systemtimer.cpp b/messagebus/src/vespa/messagebus/systemtimer.cpp
deleted file mode 100644
index 6c787509fbf..00000000000
--- a/messagebus/src/vespa/messagebus/systemtimer.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include "systemtimer.h"
-#include <vespa/fastos/time.h>
-
-namespace mbus {
-
-uint64_t
-SystemTimer::getMilliTime() const
-{
- FastOS_Time time;
- time.SetNow();
- return (uint64_t)time.MilliSecs();
-}
-
-} // namespace mbus
diff --git a/messagebus/src/vespa/messagebus/testlib/receptor.cpp b/messagebus/src/vespa/messagebus/testlib/receptor.cpp
index f821021a482..f98a4be05c3 100644
--- a/messagebus/src/vespa/messagebus/testlib/receptor.cpp
+++ b/messagebus/src/vespa/messagebus/testlib/receptor.cpp
@@ -2,17 +2,12 @@
#include "receptor.h"
-namespace mbus {
+using namespace std::chrono;
-Receptor::Receptor()
- : IMessageHandler(),
- IReplyHandler(),
- _mon(),
- _msg(),
- _reply()
-{ }
+namespace mbus {
-Receptor::~Receptor() {}
+Receptor::Receptor() = default;
+Receptor::~Receptor() = default;
void
Receptor::handleMessage(Message::UP msg)
@@ -33,12 +28,11 @@ Receptor::handleReply(Reply::UP reply)
Message::UP
Receptor::getMessage(double maxWait)
{
- int ms = (int)(maxWait * 1000);
- FastOS_Time startTime;
- startTime.SetNow();
+ int64_t ms = (int64_t)(maxWait * 1000);
+ steady_clock::time_point startTime = steady_clock::now();
vespalib::MonitorGuard guard(_mon);
while (_msg.get() == 0) {
- int w = ms - (int)startTime.MilliSecsToNow();
+ int64_t w = ms - duration_cast<milliseconds>(steady_clock::now() - startTime).count();
if (w <= 0 || !guard.wait(w)) {
break;
}
@@ -49,12 +43,11 @@ Receptor::getMessage(double maxWait)
Reply::UP
Receptor::getReply(double maxWait)
{
- int ms = (int)(maxWait * 1000);
- FastOS_Time startTime;
- startTime.SetNow();
+ int64_t ms = (int)(maxWait * 1000);
+ steady_clock::time_point startTime = steady_clock::now();
vespalib::MonitorGuard guard(_mon);
while (_reply.get() == 0) {
- int w = ms - (int)startTime.MilliSecsToNow();
+ int64_t w = ms - duration_cast<milliseconds>(steady_clock::now() - startTime).count();
if (w <= 0 || !guard.wait(w)) {
break;
}
diff --git a/messagebus_test/src/tests/error/cpp-client.cpp b/messagebus_test/src/tests/error/cpp-client.cpp
index 2a3376336ea..f186be68d01 100644
--- a/messagebus_test/src/tests/error/cpp-client.cpp
+++ b/messagebus_test/src/tests/error/cpp-client.cpp
@@ -10,6 +10,7 @@
#include <vespa/fastos/app.h>
using namespace mbus;
+using namespace std::chrono_literals;
class App : public FastOS_Application
{
@@ -29,7 +30,7 @@ App::Main()
Message::UP msg;
Reply::UP reply;
- SourceSession::UP ss = mb.getMessageBus().createSourceSession(src, SourceSessionParams().setTimeout(300));
+ SourceSession::UP ss = mb.getMessageBus().createSourceSession(src, SourceSessionParams().setTimeout(300s));
for (int i = 0; i < 10; ++i) {
msg.reset(new SimpleMessage("test"));
msg->getTrace().setLevel(9);
diff --git a/messagebus_test/src/tests/speed/cpp-client.cpp b/messagebus_test/src/tests/speed/cpp-client.cpp
index 8f65e919e97..7bb30f1f6ff 100644
--- a/messagebus_test/src/tests/speed/cpp-client.cpp
+++ b/messagebus_test/src/tests/speed/cpp-client.cpp
@@ -7,9 +7,11 @@
#include <vespa/messagebus/testlib/simplemessage.h>
#include <vespa/messagebus/testlib/simpleprotocol.h>
#include <vespa/messagebus/testlib/simplereply.h>
+#include <vespa/fastos/timestamp.h>
#include <vespa/fastos/app.h>
using namespace mbus;
+using namespace std::chrono_literals;
class Client : public IReplyHandler
{
@@ -95,7 +97,7 @@ App::Main()
RPCMessageBus mb(MessageBusParams().setRetryPolicy(retryPolicy).addProtocol(std::make_shared<SimpleProtocol>()),
RPCNetworkParams("file:slobrok.cfg").setIdentity(Identity("server/cpp")),
"file:routing.cfg");
- Client client(mb.getMessageBus(), SourceSessionParams().setTimeout(30));
+ Client client(mb.getMessageBus(), SourceSessionParams().setTimeout(30s));
// let the system 'warm up'
FastOS_Thread::Sleep(5000);
@@ -108,20 +110,17 @@ App::Main()
// let the system 'warm up'
FastOS_Thread::Sleep(5000);
- FastOS_Time start;
- FastOS_Time stop;
+ fastos::StopWatch stopWatch;
uint32_t okBefore = 0;
uint32_t okAfter = 0;
uint32_t failBefore = 0;
uint32_t failAfter = 0;
- start.SetNow();
client.sample(okBefore, failBefore);
FastOS_Thread::Sleep(10000); // Benchmark time
- stop.SetNow();
+ fastos::TimeStamp elapsed = stopWatch.elapsed();
client.sample(okAfter, failAfter);
- stop -= start;
- double time = stop.MilliSecs();
+ double time = elapsed.ms();
double msgCnt = (double)(okAfter - okBefore);
double throughput = (msgCnt / time) * 1000.0;
fprintf(stdout, "CPP-CLIENT: %g msg/s\n", throughput);
diff --git a/searchcore/src/tests/proton/common/cachedselect_test.cpp b/searchcore/src/tests/proton/common/cachedselect_test.cpp
index aa2106923e3..74d65a5bf7f 100644
--- a/searchcore/src/tests/proton/common/cachedselect_test.cpp
+++ b/searchcore/src/tests/proton/common/cachedselect_test.cpp
@@ -632,14 +632,11 @@ TEST_F("Test performance when using attributes", TestFixture)
if (sel->contains(ctx) != Result::Invalid)
break;
}
- sw.stop();
+ fastos::TimeStamp elapsed = sw.elapsed();
EXPECT_EQUAL(loopcnt, i);
LOG(info,
- "Elapsed time for %u iterations of 4 docs each: %" PRId64 " ns, "
- "%8.4f ns/doc",
- i,
- sw.elapsed().ns(),
- static_cast<double>(sw.elapsed().ns()) / ( 4 * i));
+ "Elapsed time for %u iterations of 4 docs each: %" PRId64 " ns, %8.4f ns/doc",
+ i, elapsed.ns(), static_cast<double>(elapsed.ns()) / ( 4 * i));
}
diff --git a/searchcore/src/vespa/searchcore/proton/attribute/attribute_initializer.cpp b/searchcore/src/vespa/searchcore/proton/attribute/attribute_initializer.cpp
index c3063521a99..bb41004d834 100644
--- a/searchcore/src/vespa/searchcore/proton/attribute/attribute_initializer.cpp
+++ b/searchcore/src/vespa/searchcore/proton/attribute/attribute_initializer.cpp
@@ -183,7 +183,7 @@ AttributeInitializer::loadAttribute(const AttributeVectorSP &attr,
return false;
} else {
attr->commit(serialNum, serialNum);
- EventLogger::loadAttributeComplete(_documentSubDbName, attr->getName(), stopWatch.stop().elapsed().ms());
+ EventLogger::loadAttributeComplete(_documentSubDbName, attr->getName(), stopWatch.elapsed().ms());
}
return true;
}
diff --git a/searchcore/src/vespa/searchcore/proton/docsummary/summarymanagerinitializer.cpp b/searchcore/src/vespa/searchcore/proton/docsummary/summarymanagerinitializer.cpp
index 5cdfbf03c07..1915d9107cc 100644
--- a/searchcore/src/vespa/searchcore/proton/docsummary/summarymanagerinitializer.cpp
+++ b/searchcore/src/vespa/searchcore/proton/docsummary/summarymanagerinitializer.cpp
@@ -43,7 +43,7 @@ SummaryManagerInitializer::run()
*_result = std::make_shared<SummaryManager>
(_summaryExecutor, _storeCfg, _grow, _baseDir, _docTypeName,
_tuneFile, _fileHeaderContext, _tlSyncer, _bucketizer);
- EventLogger::loadDocumentStoreComplete(_subDbName, stopWatch.stop().elapsed().ms());
+ EventLogger::loadDocumentStoreComplete(_subDbName, stopWatch.elapsed().ms());
}
} // namespace proton
diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreinitializer.cpp b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreinitializer.cpp
index eed333a11d8..c4b6d88c1c3 100644
--- a/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreinitializer.cpp
+++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/documentmetastoreinitializer.cpp
@@ -51,7 +51,7 @@ DocumentMetaStoreInitializer::run()
} else {
_dms->commit(snap.syncToken, snap.syncToken);
}
- EventLogger::loadDocumentMetaStoreComplete(_subDbName, stopWatch.stop().elapsed().ms());
+ EventLogger::loadDocumentMetaStoreComplete(_subDbName, stopWatch.elapsed().ms());
}
} else {
vespalib::mkdir(_baseDir, false);
diff --git a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h
index 38f8eabf828..97ba51a1b97 100644
--- a/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h
+++ b/searchcore/src/vespa/searchcore/proton/flushengine/flushengine.h
@@ -24,12 +24,12 @@ public:
~FlushMeta();
const vespalib::string & getName() const { return _name; }
fastos::UTCTimeStamp getStart() const { return fastos::ClockSystem::now() - elapsed(); }
- fastos::TimeStamp elapsed() const { return _stopWatch.stop().elapsed(); }
+ fastos::TimeStamp elapsed() const { return _stopWatch.elapsed(); }
uint32_t getId() const { return _id; }
bool operator < (const FlushMeta & rhs) const { return _id < rhs._id; }
private:
vespalib::string _name;
- mutable fastos::StopWatch _stopWatch;
+ fastos::StopWatch _stopWatch;
uint32_t _id;
};
typedef std::set<FlushMeta> FlushMetaSet;
diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_master.cpp b/searchcore/src/vespa/searchcore/proton/matching/match_master.cpp
index 20cd739020e..b3b97da6752 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/match_master.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/match_master.cpp
@@ -30,18 +30,19 @@ namespace {
struct TimedMatchLoopCommunicator : IMatchLoopCommunicator {
IMatchLoopCommunicator &communicator;
fastos::StopWatch rerank_time;
+ fastos::TimeStamp elapsed;
TimedMatchLoopCommunicator(IMatchLoopCommunicator &com) : communicator(com) {}
double estimate_match_frequency(const Matches &matches) override {
return communicator.estimate_match_frequency(matches);
}
Hits selectBest(SortedHitSequence sortedHits) override {
auto result = communicator.selectBest(sortedHits);
- rerank_time = fastos::StopWatch();
+ rerank_time.restart();
return result;
}
RangePair rangeCover(const RangePair &ranges) override {
RangePair result = communicator.rangeCover(ranges);
- rerank_time.stop();
+ elapsed = rerank_time.elapsed();
return result;
}
};
@@ -89,9 +90,8 @@ MatchMaster::match(search::engine::Trace & trace,
resultProcessor.prepareThreadContextCreation(threadBundle.size());
threadBundle.run(targets);
ResultProcessor::Result::UP reply = resultProcessor.makeReply(threadState[0]->extract_result());
- query_latency_time.stop();
double query_time_s = query_latency_time.elapsed().sec();
- double rerank_time_s = timedCommunicator.rerank_time.elapsed().sec();
+ double rerank_time_s = timedCommunicator.elapsed.sec();
double match_time_s = 0.0;
std::unique_ptr<vespalib::slime::Inserter> inserter;
if (trace.shouldTrace(4)) {
diff --git a/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp b/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp
index 71ff9696050..e2695340725 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/match_thread.cpp
@@ -41,7 +41,6 @@ struct WaitTimer {
: wait_time_s(wait_time_s_in), wait_time()
{ }
void done() {
- wait_time.stop();
wait_time_s += wait_time.elapsed().sec();
}
};
@@ -434,7 +433,6 @@ MatchThread::run()
trace->addEvent(4, "Start MatchThread::run");
MatchTools::UP matchTools = matchToolsFactory.createMatchTools();
search::ResultSet::UP result = findMatches(*matchTools);
- match_time.stop();
match_time_s = match_time.elapsed().sec();
resultContext = resultProcessor.createThreadContext(matchTools->getHardDoom(), thread_id, _distributionKey);
{
@@ -450,7 +448,6 @@ MatchThread::run()
trace->addEvent(5, "Start result processing");
processResult(matchTools->getHardDoom(), std::move(result), *resultContext);
}
- total_time.stop();
total_time_s = total_time.elapsed().sec();
thread_stats.active_time(total_time_s - wait_time_s).wait_time(wait_time_s);
trace->addEvent(4, "Start thread merge");
diff --git a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp
index 48599b1ecff..dace9674d64 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp
@@ -279,7 +279,6 @@ Matcher::match(const SearchRequest &request, vespalib::ThreadBundle &threadBundl
numThreadsPerSearch, _rankSetup->getNumThreadsPerSearch(), estHits, reply->totalHitCount,
request.ranking.c_str());
}
- total_matching_time.stop();
my_stats.queryCollateralTime(total_matching_time.elapsed().sec() - my_stats.queryLatencyAvg());
{
fastos::TimeStamp duration = request.getTimeUsed();
diff --git a/searchcore/src/vespa/searchcore/proton/reprocessing/reprocess_documents_task.cpp b/searchcore/src/vespa/searchcore/proton/reprocessing/reprocess_documents_task.cpp
index 12e612869d1..d8e0fcc7843 100644
--- a/searchcore/src/vespa/searchcore/proton/reprocessing/reprocess_documents_task.cpp
+++ b/searchcore/src/vespa/searchcore/proton/reprocessing/reprocess_documents_task.cpp
@@ -5,6 +5,9 @@
#include "document_reprocessing_handler.h"
#include <vespa/searchcore/proton/common/eventlogger.h>
+using namespace std::chrono_literals;
+using namespace std::chrono;
+
namespace proton {
ReprocessDocumentsTask::
@@ -33,7 +36,7 @@ ReprocessDocumentsTask::run()
{
if (_handler.hasProcessors()) {
EventLogger::reprocessDocumentsStart(_subDbName, _visitorCost);
- _stopWatch = fastos::StopWatch();
+ _start = clock::now();
search::IDocumentStore &docstore = _sm->getBackingStore();
if (_handler.hasRewriters()) {
docstore.accept(_handler.getRewriteVisitor(), *this, *_docTypeRepo);
@@ -41,8 +44,8 @@ ReprocessDocumentsTask::run()
docstore.accept(_handler, *this, *_docTypeRepo);
}
_handler.done();
- _stopWatch.stop();
- EventLogger::reprocessDocumentsComplete(_subDbName, _visitorCost, _stopWatch.elapsed().ms());
+ EventLogger::reprocessDocumentsComplete(_subDbName, _visitorCost,
+ duration_cast<milliseconds>(clock::now() - _start).count());
}
}
@@ -52,11 +55,10 @@ ReprocessDocumentsTask::updateProgress(double progress)
_visitorProgress = progress;
double deltaProgress = progress - _loggedProgress;
if (deltaProgress >= 0.01) {
- fastos::StopWatch intermediate = _stopWatch;
- fastos::TimeStamp logDelayTime = intermediate.stop().elapsed() - _stopWatch.elapsed();
- if (logDelayTime.ms() >= 60000 || deltaProgress >= 0.10) {
+ auto secondsSinceLastLog = duration_cast<seconds>(clock::now() - _lastLogTime);
+ if (secondsSinceLastLog >= 60s || deltaProgress >= 0.10) {
EventLogger::reprocessDocumentsProgress(_subDbName, progress, _visitorCost);
- _stopWatch.stop();
+ _lastLogTime = clock::now();
_loggedProgress = progress;
}
}
diff --git a/searchcore/src/vespa/searchcore/proton/reprocessing/reprocess_documents_task.h b/searchcore/src/vespa/searchcore/proton/reprocessing/reprocess_documents_task.h
index f64eddd29ee..fc82f475412 100644
--- a/searchcore/src/vespa/searchcore/proton/reprocessing/reprocess_documents_task.h
+++ b/searchcore/src/vespa/searchcore/proton/reprocessing/reprocess_documents_task.h
@@ -20,13 +20,15 @@ namespace proton
class ReprocessDocumentsTask : public IReprocessingTask,
public search::IDocumentStoreVisitorProgress
{
+ using clock = std::chrono::steady_clock;
proton::ISummaryManager::SP _sm;
std::shared_ptr<const document::DocumentTypeRepo> _docTypeRepo;
vespalib::string _subDbName;
double _visitorProgress;
double _visitorCost;
DocumentReprocessingHandler _handler;
- fastos::StopWatch _stopWatch;
+ clock::time_point _start;
+ clock::time_point _lastLogTime;
double _loggedProgress;
public:
diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.cpp b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.cpp
index 2f6eaeadf5c..271393ea3c8 100644
--- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.cpp
+++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.cpp
@@ -18,14 +18,13 @@ namespace proton {
void
TransactionLogManager::doLogReplayComplete(const vespalib::string &domainName,
- int64_t elapsedTime) const
+ std::chrono::milliseconds elapsedTime) const
{
- EventLogger::transactionLogReplayComplete(domainName, elapsedTime);
+ EventLogger::transactionLogReplayComplete(domainName, elapsedTime.count());
}
-TransactionLogManager::TransactionLogManager(const vespalib::string &tlsSpec,
- const vespalib::string &domainName)
+TransactionLogManager::TransactionLogManager(const vespalib::string &tlsSpec, const vespalib::string &domainName)
: TransactionLogManagerBase(tlsSpec, domainName),
_visitor()
{
@@ -34,9 +33,7 @@ TransactionLogManager::TransactionLogManager(const vespalib::string &tlsSpec,
TransactionLogManager::~TransactionLogManager() = default;
void
-TransactionLogManager::init(SerialNum oldestConfigSerial,
- SerialNum &prunedSerialNum,
- SerialNum &serialNum)
+TransactionLogManager::init(SerialNum oldestConfigSerial, SerialNum &prunedSerialNum, SerialNum &serialNum)
{
StatusResult res = TransactionLogManagerBase::init();
prunedSerialNum = res.serialBegin > 0 ? (res.serialBegin - 1) : 0;
diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.h b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.h
index 8f48b9adc48..82c4f9f7449 100644
--- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.h
+++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanager.h
@@ -18,8 +18,7 @@ class TransactionLogManager : public TransactionLogManagerBase
{
TransLogClient::Visitor::UP _visitor;
- virtual void doLogReplayComplete(const vespalib::string &domainName,
- int64_t elapsedTime) const override;
+ void doLogReplayComplete(const vespalib::string &domainName, std::chrono::milliseconds elapsedTime) const override;
public:
/**
@@ -28,8 +27,7 @@ public:
* @param tlsSpec the spec of the transaction log server.
* @param domainName the name of the domain this manager should handle.
**/
- TransactionLogManager(const vespalib::string &tlsSpec,
- const vespalib::string &domainName);
+ TransactionLogManager(const vespalib::string &tlsSpec, const vespalib::string &domainName);
~TransactionLogManager();
/**
@@ -41,10 +39,7 @@ public:
* @param the current serial num will be set to 1 higher than
* the serial num of the last entry in the transaction log.
**/
- void
- init(SerialNum oldestConfigSerial,
- SerialNum &prunedSerialNum,
- SerialNum &serialNum);
+ void init(SerialNum oldestConfigSerial, SerialNum &prunedSerialNum, SerialNum &serialNum);
/**
* Prepare replay of the transaction log.
@@ -59,10 +54,7 @@ public:
/**
* Start replay of the transaction log.
**/
- TlsReplayProgress::UP
- startReplay(SerialNum first,
- SerialNum syncToken,
- TransLogClient::Session::Callback &callback);
+ TlsReplayProgress::UP startReplay(SerialNum first, SerialNum syncToken, TransLogClient::Session::Callback &callback);
/**
* Indicate that replay is done.
diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp
index 19175d1e2c7..985e042c97b 100644
--- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp
+++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.cpp
@@ -2,7 +2,6 @@
#include "transactionlogmanagerbase.h"
#include <vespa/vespalib/util/stringfmt.h>
-#include <vespa/fastos/time.h>
#include <vespa/log/log.h>
LOG_SETUP(".proton.server.transactionlogmanagerbase");
@@ -21,7 +20,7 @@ TransactionLogManagerBase::TransactionLogManagerBase(
_replayCond(),
_replayDone(false),
_replayStarted(false),
- _replayStartTime(0)
+ _replayStopWatch()
{
}
@@ -31,7 +30,7 @@ TransactionLogManagerBase::StatusResult
TransactionLogManagerBase::init()
{
TransLogClient::Session::UP session = _tlc.open(_domainName);
- if (session.get() == NULL) {
+ if ( ! session) {
if (!_tlc.create(_domainName)) {
vespalib::string str = vespalib::make_string(
"Failed creating domain '%s' on TLS '%s'",
@@ -41,7 +40,7 @@ TransactionLogManagerBase::init()
LOG(debug, "Created domain '%s' on TLS '%s'",
_domainName.c_str(), _tlc.getRPCTarget().c_str());
session = _tlc.open(_domainName);
- if (session.get() == NULL) {
+ if ( ! session) {
vespalib::string str = vespalib::make_string(
"Could not open session for domain '%s' on TLS '%s'",
_domainName.c_str(), _tlc.getRPCTarget().c_str());
@@ -70,16 +69,7 @@ TransactionLogManagerBase::internalStartReplay()
std::lock_guard<std::mutex> guard(_replayLock);
_replayStarted = true;
_replayDone = false;
- FastOS_Time timer;
- timer.SetNow();
- _replayStartTime = timer.MilliSecs();
-}
-
-void
-TransactionLogManagerBase::markReplayStarted()
-{
- std::lock_guard<std::mutex> guard(_replayLock);
- _replayStarted = true;
+ _replayStopWatch.restart();
}
void TransactionLogManagerBase::changeReplayDone()
@@ -101,18 +91,18 @@ TransactionLogManagerBase::waitForReplayDone() const
void
TransactionLogManagerBase::close()
{
- if (_tlcSession.get() != NULL) {
+ if (_tlcSession) {
_tlcSession->close();
}
// Delay destruction until replay is not active.
waitForReplayDone();
- if (_tlcSession.get() != NULL) {
+ if (_tlcSession) {
_tlcSession->clear();
}
}
-TransLogClient::Visitor::UP TransactionLogManagerBase::createTlcVisitor(
- TransLogClient::Session::Callback &callback) {
+TransLogClient::Visitor::UP
+TransactionLogManagerBase::createTlcVisitor(TransLogClient::Session::Callback &callback) {
return _tlc.createVisitor(_domainName, callback);
}
@@ -127,9 +117,7 @@ bool TransactionLogManagerBase::isDoingReplay() const {
}
void TransactionLogManagerBase::logReplayComplete() const {
- FastOS_Time timer;
- timer.SetMilliSecs(_replayStartTime);
- doLogReplayComplete(_domainName, static_cast<int64_t>(timer.MilliSecsToNow()));
+ doLogReplayComplete(_domainName, std::chrono::milliseconds(_replayStopWatch.elapsed().ms()));
}
} // namespace proton
diff --git a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h
index 9f4e63842cd..8c4bc2bbfa3 100644
--- a/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h
+++ b/searchcore/src/vespa/searchcore/proton/server/transactionlogmanagerbase.h
@@ -5,6 +5,7 @@
#include <vespa/searchlib/transactionlog/translogclient.h>
#include <mutex>
#include <condition_variable>
+#include <vespa/fastos/timestamp.h>
namespace proton {
@@ -12,18 +13,19 @@ namespace proton {
* Base class managing the initialization and replay of a transaction log.
**/
class TransactionLogManagerBase {
-
- search::transactionlog::TransLogClient _tlc;
- search::transactionlog::TransLogClient::Session::UP _tlcSession;
- vespalib::string _domainName;
- mutable std::mutex _replayLock;
+protected:
+ using TransLogClient = search::transactionlog::TransLogClient;
+private:
+ TransLogClient _tlc;
+ TransLogClient::Session::UP _tlcSession;
+ vespalib::string _domainName;
+ mutable std::mutex _replayLock;
mutable std::condition_variable _replayCond;
- volatile bool _replayDone;
- bool _replayStarted;
- double _replayStartTime;
+ volatile bool _replayDone;
+ bool _replayStarted;
+ fastos::StopWatch _replayStopWatch;
protected:
- typedef search::transactionlog::TransLogClient TransLogClient;
typedef search::SerialNum SerialNum;
struct StatusResult {
@@ -36,8 +38,7 @@ protected:
StatusResult init();
void internalStartReplay();
- virtual void doLogReplayComplete(const vespalib::string &domainName,
- int64_t elapsedTime) const = 0;
+ virtual void doLogReplayComplete(const vespalib::string &domainName, std::chrono::milliseconds elapsedTime) const = 0;
public:
TransactionLogManagerBase(const TransactionLogManagerBase &) = delete;
@@ -65,10 +66,6 @@ public:
bool isDoingReplay() const;
void logReplayComplete() const;
const vespalib::string &getRpcTarget() const { return _tlc.getRPCTarget(); }
-
- void
- markReplayStarted();
};
} // namespace proton
-
diff --git a/searchcorespi/src/vespa/searchcorespi/index/fusionrunner.cpp b/searchcorespi/src/vespa/searchcorespi/index/fusionrunner.cpp
index 009bf5d16d9..ca709362152 100644
--- a/searchcorespi/src/vespa/searchcorespi/index/fusionrunner.cpp
+++ b/searchcorespi/src/vespa/searchcorespi/index/fusionrunner.cpp
@@ -7,7 +7,6 @@
#include <vespa/searchlib/attribute/fixedsourceselector.h>
#include <vespa/searchlib/queryeval/isourceselector.h>
#include <vespa/searchlib/util/dirtraverse.h>
-#include <vespa/vespalib/util/jsonwriter.h>
#include <vespa/log/log.h>
LOG_SETUP(".searchcorespi.index.fusionrunner");
@@ -23,7 +22,6 @@ using search::diskindex::SelectorArray;
using search::SerialNum;
using std::vector;
using vespalib::string;
-using vespalib::JSONStringer;
namespace searchcorespi::index {
@@ -37,8 +35,7 @@ FusionRunner::FusionRunner(const string &base_dir,
_fileHeaderContext(fileHeaderContext)
{ }
-FusionRunner::~FusionRunner() {
-}
+FusionRunner::~FusionRunner() = default;
namespace {
@@ -102,16 +99,15 @@ FusionRunner::fuse(const FusionSpec &fusion_spec,
id_map[0] = sources.size();
sources.push_back(_diskLayout.getFusionDir(fusion_spec.last_fusion_id));
}
- for (size_t i = 0; i < ids.size(); ++i) {
- id_map[ids[i] - fusion_spec.last_fusion_id] = sources.size();
- sources.push_back(_diskLayout.getFlushDir(ids[i]));
+ for (uint32_t id : ids) {
+ id_map[id - fusion_spec.last_fusion_id] = sources.size();
+ sources.push_back(_diskLayout.getFlushDir(id));
}
if (LOG_WOULD_LOG(event)) {
EventLogger::diskFusionStart(sources, fusion_dir);
}
- FastOS_Time timer;
- timer.SetNow();
+ fastos::StopWatch stopWatch;
const string selector_name = IndexDiskLayout::getSelectorFileName(_diskLayout.getFlushDir(fusion_id));
SelectorArray selector_array;
@@ -128,7 +124,7 @@ FusionRunner::fuse(const FusionSpec &fusion_spec,
}
if (LOG_WOULD_LOG(event)) {
- EventLogger::diskFusionComplete(fusion_dir, (int64_t)timer.MilliSecsToNow());
+ EventLogger::diskFusionComplete(fusion_dir, stopWatch.elapsed().ms());
}
return fusion_id;
}
diff --git a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp
index 45bd2a52349..da3058e9bbd 100644
--- a/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp
+++ b/searchcorespi/src/vespa/searchcorespi/index/indexmaintainer.cpp
@@ -10,7 +10,6 @@
#include "indexwriteutilities.h"
#include <vespa/fastos/file.h>
#include <vespa/searchcorespi/flush/closureflushtask.h>
-#include <vespa/searchlib/common/serialnumfileheadercontext.h>
#include <vespa/searchlib/index/schemautil.h>
#include <vespa/searchlib/util/dirtraverse.h>
#include <vespa/searchlib/util/filekit.h>
@@ -277,14 +276,13 @@ IndexMaintainer::loadDiskIndex(const string &indexDir)
if (LOG_WOULD_LOG(event)) {
EventLogger::diskIndexLoadStart(indexDir);
}
- FastOS_Time timer;
- timer.SetNow();
+ fastos::StopWatch stopWatch;
_active_indexes->setActive(indexDir);
IDiskIndex::SP retval(new DiskIndexWithDestructorClosure
(_operations.loadDiskIndex(indexDir),
makeClosure(this, &IndexMaintainer::deactivateDiskIndexes, indexDir)));
if (LOG_WOULD_LOG(event)) {
- EventLogger::diskIndexLoadComplete(indexDir, (int64_t)timer.MilliSecsToNow());
+ EventLogger::diskIndexLoadComplete(indexDir, stopWatch.elapsed().ms());
}
return retval;
}
@@ -297,8 +295,7 @@ IndexMaintainer::reloadDiskIndex(const IDiskIndex &oldIndex)
if (LOG_WOULD_LOG(event)) {
EventLogger::diskIndexLoadStart(indexDir);
}
- FastOS_Time timer;
- timer.SetNow();
+ fastos::StopWatch stopWatch;
_active_indexes->setActive(indexDir);
const IDiskIndex &wrappedDiskIndex =
(dynamic_cast<const DiskIndexWithDestructorClosure &>(oldIndex)).getWrapped();
@@ -306,7 +303,7 @@ IndexMaintainer::reloadDiskIndex(const IDiskIndex &oldIndex)
(_operations.reloadDiskIndex(wrappedDiskIndex),
makeClosure(this, &IndexMaintainer::deactivateDiskIndexes, indexDir)));
if (LOG_WOULD_LOG(event)) {
- EventLogger::diskIndexLoadComplete(indexDir, (int64_t)timer.MilliSecsToNow());
+ EventLogger::diskIndexLoadComplete(indexDir, stopWatch.elapsed().ms());
}
return retval;
}
@@ -441,7 +438,7 @@ IndexMaintainer::FlushArgs::FlushArgs()
_prunedSchema()
{
}
-IndexMaintainer::FlushArgs::~FlushArgs() { }
+IndexMaintainer::FlushArgs::~FlushArgs() = default;
IndexMaintainer::FlushArgs::FlushArgs(FlushArgs &&) = default;
IndexMaintainer::FlushArgs & IndexMaintainer::FlushArgs::operator=(FlushArgs &&) = default;
diff --git a/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp b/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp
index 1834beb9590..f4de610a06d 100644
--- a/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp
+++ b/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp
@@ -153,29 +153,28 @@ LoadAttribute::Main()
vespalib::string fileName(_argv[idx]);
vespalib::FileHeader fh;
- do {
+ {
vespalib::string datFileName(fileName + ".dat");
Fast_BufferedFile file;
file.ReadOpenExisting(datFileName.c_str());
(void) fh.readFile(file);
- } while (0);
+ }
attribute::BasicType bt(fh.getTag("datatype").asString());
attribute::CollectionType ct(fh.getTag("collectiontype").asString());
attribute::Config c(bt, ct);
c.setFastSearch(doFastSearch);
c.setHuge(doHuge);
AttributePtr ptr = AttributeFactory::createAttribute(fileName, c);
- FastOS_Time timer;
- timer.SetNow();
+ fastos::StopWatch timer;
load(ptr);
- std::cout << "load time: " << timer.MilliSecsToNow() / 1000 << " seconds " << std::endl;
+ std::cout << "load time: " << timer.elapsed().sec() << " seconds " << std::endl;
std::cout << "numDocs: " << ptr->getNumDocs() << std::endl;
if (doApplyUpdate) {
- timer.SetNow();
+ timer.restart();
applyUpdate(ptr);
- std::cout << "update time: " << timer.MilliSecsToNow() / 1000 << " seconds " << std::endl;
+ std::cout << "update time: " << timer.elapsed().sec() << " seconds " << std::endl;
}
if (doPrintContent) {
@@ -192,9 +191,9 @@ LoadAttribute::Main()
if (doSave) {
vespalib::string saveFile = fileName + ".save";
std::cout << "saving attribute: " << saveFile << std::endl;
- timer.SetNow();
+ timer.restart();
ptr->save(saveFile);
- std::cout << "save time: " << timer.MilliSecsToNow() / 1000 << " seconds " << std::endl;
+ std::cout << "save time: " << timer.elapsed().sec() << " seconds " << std::endl;
}
return 0;
diff --git a/searchlib/src/tests/util/bufferwriter/CMakeLists.txt b/searchlib/src/tests/util/bufferwriter/CMakeLists.txt
index 511c7b566cf..406dddb9a05 100644
--- a/searchlib/src/tests/util/bufferwriter/CMakeLists.txt
+++ b/searchlib/src/tests/util/bufferwriter/CMakeLists.txt
@@ -6,11 +6,3 @@ vespa_add_executable(searchlib_bufferwriter_test_app TEST
searchlib
)
vespa_add_test(NAME searchlib_bufferwriter_test_app COMMAND searchlib_bufferwriter_test_app)
-vespa_add_executable(searchlib_bufferwriter_bm_app
- SOURCES
- work.cpp
- bm.cpp
- DEPENDS
- searchlib
-)
-vespa_add_test(NAME searchlib_bufferwriter_bm_app COMMAND searchlib_bufferwriter_bm_app BENCHMARK)
diff --git a/searchlib/src/tests/util/bufferwriter/bm.cpp b/searchlib/src/tests/util/bufferwriter/bm.cpp
deleted file mode 100644
index ac3cc3a09b1..00000000000
--- a/searchlib/src/tests/util/bufferwriter/bm.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "work.h"
-#include <vespa/searchlib/util/drainingbufferwriter.h>
-#include <vespa/vespalib/testkit/testapp.h>
-#include <vespa/fastos/timestamp.h>
-#include <iostream>
-
-#include <vespa/log/log.h>
-LOG_SETUP("bufferwriter_bm");
-
-using search::DrainingBufferWriter;
-
-constexpr size_t million = 1000000;
-
-enum class WorkFuncDispatch
-{
- DIRECT,
- LAMBDA,
- FUNCTOR,
- FUNCTOR2
-};
-
-
-template <typename T>
-void
-callWork(size_t size, WorkFuncDispatch dispatch)
-{
- std::vector<T> foo;
- DrainingBufferWriter writer;
- foo.resize(size);
- std::cout << "will write " << size << " elements of size " << sizeof(T) <<
- std::endl;
- fastos::StopWatch stopWatch;
- switch (dispatch) {
- case WorkFuncDispatch::DIRECT:
- work(foo, writer);
- break;
- case WorkFuncDispatch::LAMBDA:
- workLambda(foo, writer);
- break;
- case WorkFuncDispatch::FUNCTOR:
- workFunctor(foo, writer);
- break;
- case WorkFuncDispatch::FUNCTOR2:
- workFunctor2(foo, writer);
- break;
- default:
- LOG_ABORT("should not be reached");
- }
- double delta = stopWatch.stop().elapsed();
- double writeSpeed = writer.getBytesWritten() / delta;
- EXPECT_GREATER(writeSpeed, 1000);
- std::cout << "written is " << writer.getBytesWritten() << std::endl;
- std::cout << "time used is " << (delta * 1000.0) << " ms" << std::endl;
- std::cout << "write speed is " << writeSpeed << std::endl;
-}
-
-
-void
-callWorks(WorkFuncDispatch dispatch)
-{
- callWork<char>(million * 1000, dispatch);
- callWork<short>(million * 500, dispatch);
- callWork<int>(million * 250, dispatch);
- callWork<long>(million * 125, dispatch);
-}
-
-TEST("simple bufferwriter speed test")
-{
- callWorks(WorkFuncDispatch::DIRECT);
-}
-
-TEST("lambda func bufferwriter speed test")
-{
- callWorks(WorkFuncDispatch::LAMBDA);
-}
-
-TEST("functor bufferwriter speed test")
-{
- callWorks(WorkFuncDispatch::FUNCTOR);
-}
-
-TEST("functor2 bufferwriter speed test")
-{
- callWorks(WorkFuncDispatch::FUNCTOR2);
-}
-
-
-TEST_MAIN()
-{
- TEST_RUN_ALL();
-}
diff --git a/searchlib/src/tests/util/bufferwriter/bufferwriter_test.cpp b/searchlib/src/tests/util/bufferwriter/bufferwriter_test.cpp
index bafb4105996..33afa67e660 100644
--- a/searchlib/src/tests/util/bufferwriter/bufferwriter_test.cpp
+++ b/searchlib/src/tests/util/bufferwriter/bufferwriter_test.cpp
@@ -6,8 +6,7 @@
#include <vespa/searchlib/util/drainingbufferwriter.h>
#include <vespa/searchlib/util/rand48.h>
-namespace search
-{
+namespace search {
namespace {
@@ -39,7 +38,7 @@ StoreBufferWriter::StoreBufferWriter()
setup(&_buf[0], _buf.size());
}
-StoreBufferWriter::~StoreBufferWriter() {}
+StoreBufferWriter::~StoreBufferWriter() = default;
void
diff --git a/searchlib/src/tests/util/bufferwriter/work.cpp b/searchlib/src/tests/util/bufferwriter/work.cpp
deleted file mode 100644
index bd5bf4a9d81..00000000000
--- a/searchlib/src/tests/util/bufferwriter/work.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "work.h"
-#include <vespa/vespalib/util/bufferwriter.h>
-
-namespace search
-{
-
-template <class T>
-class WriteFunctor
-{
- BufferWriter &_writer;
-public:
- WriteFunctor(BufferWriter &writer)
- : _writer(writer)
- {
- }
-
- void operator()(const T &val) { _writer.write(&val, sizeof(val)); }
-};
-
-template <class T>
-class WriteFunctor2
-{
- BufferWriter &_writer;
-public:
- WriteFunctor2(BufferWriter &writer)
- : _writer(writer)
- {
- }
-
- void operator()(const T &val) __attribute((noinline))
- { _writer.write(&val, sizeof(val)); }
-};
-
-template <class T, class Func>
-void workLoop(const std::vector<T> &v, Func &&func)
-{
- for (const auto &val : v) {
- func(val);
- }
-}
-
-template <class T>
-void work(const std::vector<T> &v, BufferWriter &writer)
-{
- for (const auto &val : v) {
- writer.write(&val, sizeof(val));
- }
- writer.flush();
-}
-
-template <class T>
-void workLambda(const std::vector<T> &v, BufferWriter &writer)
-{
- workLoop<T>(v,
- [&writer](const T &val) { writer.write(&val, sizeof(val)); });
- writer.flush();
-}
-
-template <class T>
-void workFunctor(const std::vector<T> &v, BufferWriter &writer)
-{
- workLoop<T>(v, WriteFunctor<T>(writer));
- writer.flush();
-}
-
-template <class T>
-void workFunctor2(const std::vector<T> &v, BufferWriter &writer)
-{
- workLoop<T>(v, WriteFunctor2<T>(writer));
- writer.flush();
-}
-
-template void work(const std::vector<char> &v, BufferWriter &writer);
-template void work(const std::vector<short> &v, BufferWriter &writer);
-template void work(const std::vector<int> &v, BufferWriter &writer);
-template void work(const std::vector<long> &v, BufferWriter &writer);
-template void workLambda(const std::vector<char> &v, BufferWriter &writer);
-template void workLambda(const std::vector<short> &v, BufferWriter &writer);
-template void workLambda(const std::vector<int> &v, BufferWriter &writer);
-template void workLambda(const std::vector<long> &v, BufferWriter &writer);
-template void workFunctor(const std::vector<char> &v, BufferWriter &writer);
-template void workFunctor(const std::vector<short> &v, BufferWriter &writer);
-template void workFunctor(const std::vector<int> &v, BufferWriter &writer);
-template void workFunctor(const std::vector<long> &v, BufferWriter &writer);
-template void workFunctor2(const std::vector<char> &v, BufferWriter &writer);
-template void workFunctor2(const std::vector<short> &v, BufferWriter &writer);
-template void workFunctor2(const std::vector<int> &v, BufferWriter &writer);
-template void workFunctor2(const std::vector<long> &v, BufferWriter &writer);
-
-} // namespace search
diff --git a/searchlib/src/tests/util/bufferwriter/work.h b/searchlib/src/tests/util/bufferwriter/work.h
deleted file mode 100644
index 17f381d99eb..00000000000
--- a/searchlib/src/tests/util/bufferwriter/work.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include <vector>
-
-namespace search {
-
-class BufferWriter;
-
-template <class T>
-using WorkFunc = void (*)(const std::vector<T> &v, BufferWriter &writer);
-template <class T>
-void work(const std::vector<T> &v, BufferWriter &writer);
-template <class T>
-void workLambda(const std::vector<T> &v, BufferWriter &writer);
-template <class T>
-void workFunctor(const std::vector<T> &v, BufferWriter &writer);
-template <class T>
-void workFunctor2(const std::vector<T> &v, BufferWriter &writer);
-
-} // namespace search
diff --git a/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp b/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp
index 5c09f2d80bf..c51cd444b54 100644
--- a/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp
+++ b/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp
@@ -1,14 +1,13 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "debugwaitfunctionnode.h"
-#include <vespa/fastos/time.h>
-#include <thread>
+#include <vespa/fastos/timestamp.h>
-namespace search {
-namespace expression {
+namespace search::expression {
using vespalib::FieldBase;
using vespalib::Serializer;
using vespalib::Deserializer;
+using namespace std::chrono;
IMPLEMENT_EXPRESSIONNODE(DebugWaitFunctionNode, UnaryFunctionNode);
@@ -17,9 +16,7 @@ DebugWaitFunctionNode::DebugWaitFunctionNode()
_busyWait(true)
{ }
-DebugWaitFunctionNode::~DebugWaitFunctionNode()
-{
-}
+DebugWaitFunctionNode::~DebugWaitFunctionNode() = default;
DebugWaitFunctionNode::DebugWaitFunctionNode(ExpressionNode::UP arg, double waitTime, bool busyWait)
: UnaryFunctionNode(std::move(arg)),
@@ -28,22 +25,13 @@ DebugWaitFunctionNode::DebugWaitFunctionNode(ExpressionNode::UP arg, double wait
{
}
+using std::chrono::microseconds;
+
bool
DebugWaitFunctionNode::onExecute() const
{
- FastOS_Time time;
- time.SetNow();
- double millis = _waitTime * 1000.0;
+ fastos::StopWatch::waitAtLeast(microseconds(long(_waitTime * 1000000)), _busyWait);
- while (time.MilliSecsToNow() < millis) {
- if (_busyWait) {
- for (int i = 0; i < 1000; i++)
- ;
- } else {
- int rem = (int)(millis - time.MilliSecsToNow());
- std::this_thread::sleep_for(std::chrono::milliseconds(rem));
- }
- }
getArg().execute();
updateResult().assign(getArg().getResult());
return true;
@@ -73,7 +61,6 @@ DebugWaitFunctionNode::visitMembers(vespalib::ObjectVisitor &visitor) const
}
}
-}
// this function was added by ../../forcelink.sh
void forcelink_file_searchlib_expression_debugwaitfunctionnode() {}
diff --git a/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.h b/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.h
index e5958a89bd0..c98a7dc36b5 100644
--- a/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.h
+++ b/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.h
@@ -6,8 +6,7 @@
#include "resultvector.h"
#include <vespa/searchlib/common/sortspec.h>
-namespace search {
-namespace expression {
+namespace search::expression {
class DebugWaitFunctionNode : public UnaryFunctionNode
{
@@ -15,7 +14,7 @@ public:
DECLARE_EXPRESSIONNODE(DebugWaitFunctionNode);
DECLARE_NBO_SERIALIZE;
DebugWaitFunctionNode();
- ~DebugWaitFunctionNode();
+ ~DebugWaitFunctionNode() override;
DebugWaitFunctionNode(ExpressionNode::UP arg, double waitTime, bool busyWait);
void visitMembers(vespalib::ObjectVisitor &visitor) const override;
private:
@@ -25,4 +24,3 @@ private:
};
}
-}
diff --git a/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp b/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp
index 99645cc3338..975f510cd22 100644
--- a/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp
+++ b/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp
@@ -1,16 +1,13 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "debug_attribute_wait.h"
-#include <vespa/fastos/time.h>
-#include <thread>
+#include <vespa/fastos/timestamp.h>
using search::attribute::IAttributeVector;
+using namespace search::fef;
+using namespace std::chrono;
-namespace search {
-
-using namespace fef;
-
-namespace features {
+namespace search::features {
//-----------------------------------------------------------------------------
@@ -28,39 +25,26 @@ public:
void execute(uint32_t docId) override;
};
-DebugAttributeWaitExecutor::DebugAttributeWaitExecutor(const IQueryEnvironment &env,
+DebugAttributeWaitExecutor::DebugAttributeWaitExecutor(const IQueryEnvironment &,
const IAttributeVector *attribute,
const DebugAttributeWaitParams &params)
: _attribute(attribute),
_buf(),
_params(params)
-{
- (void)env;
-}
+{ }
void
DebugAttributeWaitExecutor::execute(uint32_t docId)
{
double waitTime = 0.0;
- FastOS_Time time;
- time.SetNow();
- if (_attribute != NULL) {
+ if (_attribute != nullptr) {
_buf.fill(*_attribute, docId);
waitTime = _buf[0];
}
- double millis = waitTime * 1000.0;
-
- while (time.MilliSecsToNow() < millis) {
- if (_params.busyWait) {
- for (int i = 0; i < 1000; i++)
- ;
- } else {
- int rem = (int)(millis - time.MilliSecsToNow());
- std::this_thread::sleep_for(std::chrono::milliseconds(rem));
- }
- }
- outputs().set_number(0, 1.0e-6 * time.MicroSecsToNow());
+ fastos::StopWatch timer;
+ fastos::StopWatch::waitAtLeast(microseconds(long(waitTime * 1000000)), _params.busyWait);
+ outputs().set_number(0, timer.elapsed().sec());
}
//-----------------------------------------------------------------------------
@@ -72,22 +56,19 @@ DebugAttributeWaitBlueprint::DebugAttributeWaitBlueprint()
}
void
-DebugAttributeWaitBlueprint::visitDumpFeatures(const IIndexEnvironment &env, IDumpFeatureVisitor &visitor) const
+DebugAttributeWaitBlueprint::visitDumpFeatures(const IIndexEnvironment &, IDumpFeatureVisitor &) const
{
- (void)env;
- (void)visitor;
}
Blueprint::UP
DebugAttributeWaitBlueprint::createInstance() const
{
- return Blueprint::UP(new DebugAttributeWaitBlueprint());
+ return std::make_unique<DebugAttributeWaitBlueprint>();
}
bool
DebugAttributeWaitBlueprint::setup(const IIndexEnvironment &env, const ParameterList &params)
{
- (void)env;
_attribute = params[0].getValue();
_params.busyWait = (params[1].asDouble() == 1.0);
@@ -107,10 +88,7 @@ DebugAttributeWaitBlueprint::createExecutor(const IQueryEnvironment &env, vespal
fef::ParameterDescriptions
DebugAttributeWaitBlueprint::getDescriptions() const
{
- return fef::ParameterDescriptions().desc().attribute(fef::ParameterDataTypeSet::normalTypeSet(), fef::ParameterCollection::ANY).number();
+ return fef::ParameterDescriptions().desc().attribute(ParameterDataTypeSet::normalTypeSet(), ParameterCollection::ANY).number();
}
-//-----------------------------------------------------------------------------
-
-} // namespace features
-} // namespace search
+}
diff --git a/searchlib/src/vespa/searchlib/features/debug_wait.cpp b/searchlib/src/vespa/searchlib/features/debug_wait.cpp
index 6a26b24b451..79ba1678b2b 100644
--- a/searchlib/src/vespa/searchlib/features/debug_wait.cpp
+++ b/searchlib/src/vespa/searchlib/features/debug_wait.cpp
@@ -1,14 +1,11 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "debug_wait.h"
-#include <vespa/fastos/time.h>
-#include <thread>
+#include <vespa/fastos/timestamp.h>
-namespace search {
+using namespace search::fef;
-using namespace fef;
-
-namespace features {
+namespace search::features {
//-----------------------------------------------------------------------------
@@ -22,29 +19,19 @@ public:
void execute(uint32_t docId) override;
};
-DebugWaitExecutor::DebugWaitExecutor(const IQueryEnvironment &env, const DebugWaitParams &params)
+DebugWaitExecutor::DebugWaitExecutor(const IQueryEnvironment &, const DebugWaitParams &params)
: _params(params)
{
- (void)env;
}
+using namespace std::chrono;
+
void
DebugWaitExecutor::execute(uint32_t)
{
- FastOS_Time time;
- time.SetNow();
- double millis = _params.waitTime * 1000.0;
-
- while (time.MilliSecsToNow() < millis) {
- if (_params.busyWait) {
- for (int i = 0; i < 1000; i++)
- ;
- } else {
- int rem = (int)(millis - time.MilliSecsToNow());
- std::this_thread::sleep_for(std::chrono::milliseconds(rem));
- }
- }
- outputs().set_number(0, 1.0e-6 * time.MicroSecsToNow());
+ fastos::StopWatch timer;
+ fastos::StopWatch::waitAtLeast(microseconds(long(_params.waitTime * 1000000)), _params.busyWait);
+ outputs().set_number(0, timer.elapsed().sec());
}
//-----------------------------------------------------------------------------
@@ -56,16 +43,14 @@ DebugWaitBlueprint::DebugWaitBlueprint()
}
void
-DebugWaitBlueprint::visitDumpFeatures(const IIndexEnvironment &env, IDumpFeatureVisitor &visitor) const
+DebugWaitBlueprint::visitDumpFeatures(const IIndexEnvironment &, IDumpFeatureVisitor &) const
{
- (void)env;
- (void)visitor;
}
Blueprint::UP
DebugWaitBlueprint::createInstance() const
{
- return Blueprint::UP(new DebugWaitBlueprint());
+ return std::make_unique<DebugWaitBlueprint>();
}
bool
@@ -87,5 +72,4 @@ DebugWaitBlueprint::createExecutor(const IQueryEnvironment &env, vespalib::Stash
//-----------------------------------------------------------------------------
-} // namespace features
-} // namespace search
+}
diff --git a/searchlib/src/vespa/searchlib/features/nowfeature.cpp b/searchlib/src/vespa/searchlib/features/nowfeature.cpp
index 76cbd3fa05c..074acb2e890 100644
--- a/searchlib/src/vespa/searchlib/features/nowfeature.cpp
+++ b/searchlib/src/vespa/searchlib/features/nowfeature.cpp
@@ -1,16 +1,14 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "nowfeature.h"
-#include <vespa/searchlib/fef/featurenamebuilder.h>
#include <vespa/searchlib/fef/queryproperties.h>
#include <vespa/searchlib/fef/properties.h>
-#include <vespa/fastos/time.h>
+#include <chrono>
-namespace search {
-namespace features {
+namespace search::features {
NowExecutor::NowExecutor(int64_t timestamp) :
- search::fef::FeatureExecutor(),
+ fef::FeatureExecutor(),
_timestamp(timestamp)
{
}
@@ -21,39 +19,37 @@ NowExecutor::execute(uint32_t) {
}
void
-NowBlueprint::visitDumpFeatures(const search::fef::IIndexEnvironment &,
- search::fef::IDumpFeatureVisitor &visitor) const
+NowBlueprint::visitDumpFeatures(const fef::IIndexEnvironment &, fef::IDumpFeatureVisitor &visitor) const
{
visitor.visitDumpFeature(getBaseName());
}
bool
-NowBlueprint::setup(const search::fef::IIndexEnvironment &,
- const search::fef::ParameterList &)
+NowBlueprint::setup(const fef::IIndexEnvironment &, const fef::ParameterList &)
{
describeOutput("out", "The timestamp (seconds since epoch) of query execution.");
return true;
}
-search::fef::Blueprint::UP
+fef::Blueprint::UP
NowBlueprint::createInstance() const
{
- return search::fef::Blueprint::UP(new NowBlueprint());
+ return std::make_unique<NowBlueprint>();
}
-search::fef::FeatureExecutor &
-NowBlueprint::createExecutor(const search::fef::IQueryEnvironment &env, vespalib::Stash &stash) const
+using namespace std::chrono;
+
+fef::FeatureExecutor &
+NowBlueprint::createExecutor(const fef::IQueryEnvironment &env, vespalib::Stash &stash) const
{
int64_t timestamp;
const fef::Property &prop = env.getProperties().lookup(fef::queryproperties::now::SystemTime::NAME);
if (prop.found()) {
timestamp = atoll(prop.get().c_str());
} else {
- FastOS_Time now;
- now.SetNow();
- timestamp = (int64_t)now.Secs();
+ timestamp = duration_cast<seconds>(system_clock::now().time_since_epoch()).count();
}
return stash.create<NowExecutor>(timestamp);
}
-}}
+}
diff --git a/searchlib/src/vespa/searchlib/features/nowfeature.h b/searchlib/src/vespa/searchlib/features/nowfeature.h
index e9191689fb2..73a19048a00 100644
--- a/searchlib/src/vespa/searchlib/features/nowfeature.h
+++ b/searchlib/src/vespa/searchlib/features/nowfeature.h
@@ -36,8 +36,7 @@ public:
fef::ParameterDescriptions getDescriptions() const override {
return fef::ParameterDescriptions().desc();
}
- bool setup(const fef::IIndexEnvironment & env,
- const fef::ParameterList & params) override;
+ bool setup(const fef::IIndexEnvironment & env, const fef::ParameterList & params) override;
fef::FeatureExecutor &createExecutor(const fef::IQueryEnvironment &env, vespalib::Stash &stash) const override;
};
diff --git a/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp b/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp
index 99de8ba31e2..dd0c67df45c 100644
--- a/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp
+++ b/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp
@@ -3,16 +3,16 @@
#include "random_normal_feature.h"
#include "utils.h"
#include <vespa/searchlib/fef/properties.h>
-#include <vespa/fastos/time.h>
+#include <chrono>
#include <vespa/log/log.h>
LOG_SETUP(".features.randomnormalfeature");
namespace search::features {
-RandomNormalExecutor::RandomNormalExecutor(uint64_t seed, double mean, double stddev) :
- search::fef::FeatureExecutor(),
- _rnd(mean, stddev, true)
+RandomNormalExecutor::RandomNormalExecutor(uint64_t seed, double mean, double stddev)
+ : fef::FeatureExecutor(),
+ _rnd(mean, stddev, true)
{
LOG(debug, "RandomNormalExecutor: seed=%" PRIu64 ", mean=%f, stddev=%f", seed, mean, stddev);
_rnd.seed(seed);
@@ -25,7 +25,7 @@ RandomNormalExecutor::execute(uint32_t)
}
RandomNormalBlueprint::RandomNormalBlueprint() :
- search::fef::Blueprint("randomNormal"),
+ fef::Blueprint("randomNormal"),
_seed(0),
_mean(0.0),
_stddev(1.0)
@@ -33,22 +33,20 @@ RandomNormalBlueprint::RandomNormalBlueprint() :
}
void
-RandomNormalBlueprint::visitDumpFeatures(const search::fef::IIndexEnvironment &,
- search::fef::IDumpFeatureVisitor &) const
+RandomNormalBlueprint::visitDumpFeatures(const fef::IIndexEnvironment &, fef::IDumpFeatureVisitor &) const
{
}
-search::fef::Blueprint::UP
+fef::Blueprint::UP
RandomNormalBlueprint::createInstance() const
{
- return search::fef::Blueprint::UP(new RandomNormalBlueprint());
+ return std::make_unique<RandomNormalBlueprint>();
}
bool
-RandomNormalBlueprint::setup(const search::fef::IIndexEnvironment & env,
- const search::fef::ParameterList & params)
+RandomNormalBlueprint::setup(const fef::IIndexEnvironment & env, const fef::ParameterList & params)
{
- search::fef::Property p = env.getProperties().lookup(getName(), "seed");
+ fef::Property p = env.getProperties().lookup(getName(), "seed");
if (p.found()) {
_seed = util::strToNum<uint64_t>(p.get());
}
@@ -64,14 +62,14 @@ RandomNormalBlueprint::setup(const search::fef::IIndexEnvironment & env,
return true;
}
-search::fef::FeatureExecutor &
-RandomNormalBlueprint::createExecutor(const search::fef::IQueryEnvironment &, vespalib::Stash &stash) const
+using namespace std::chrono;
+
+fef::FeatureExecutor &
+RandomNormalBlueprint::createExecutor(const fef::IQueryEnvironment &, vespalib::Stash &stash) const
{
uint64_t seed = _seed;
if (seed == 0) {
- FastOS_Time time;
- time.SetNow();
- seed = static_cast<uint64_t>(time.MicroSecs()) ^
+ seed = static_cast<uint64_t>(duration_cast<microseconds>(system_clock::now().time_since_epoch()).count()) ^
reinterpret_cast<uint64_t>(&seed); // results in different seeds in different threads
}
return stash.create<RandomNormalExecutor>(seed, _mean, _stddev);
diff --git a/searchlib/src/vespa/searchlib/features/randomfeature.cpp b/searchlib/src/vespa/searchlib/features/randomfeature.cpp
index cdedbcadc5e..18b0cf616d4 100644
--- a/searchlib/src/vespa/searchlib/features/randomfeature.cpp
+++ b/searchlib/src/vespa/searchlib/features/randomfeature.cpp
@@ -3,19 +3,17 @@
#include "randomfeature.h"
#include "utils.h"
#include <vespa/searchlib/fef/properties.h>
-#include <vespa/vespalib/util/stringfmt.h>
-#include <vespa/fastos/time.h>
-
+#include <chrono>
#include <vespa/log/log.h>
LOG_SETUP(".features.randomfeature");
namespace search::features {
-RandomExecutor::RandomExecutor(uint64_t seed, uint64_t matchSeed) :
- search::fef::FeatureExecutor(),
- _rnd(),
- _matchRnd(),
- _matchSeed(matchSeed)
+RandomExecutor::RandomExecutor(uint64_t seed, uint64_t matchSeed)
+ : fef::FeatureExecutor(),
+ _rnd(),
+ _matchRnd(),
+ _matchSeed(matchSeed)
{
LOG(debug, "RandomExecutor: seed=%" PRIu64 ", matchSeed=%" PRIu64, seed, matchSeed);
_rnd.srand48(seed);
@@ -33,28 +31,26 @@ RandomExecutor::execute(uint32_t docId)
RandomBlueprint::RandomBlueprint() :
- search::fef::Blueprint("random"),
+ fef::Blueprint("random"),
_seed(0)
{
}
void
-RandomBlueprint::visitDumpFeatures(const search::fef::IIndexEnvironment &,
- search::fef::IDumpFeatureVisitor &) const
+RandomBlueprint::visitDumpFeatures(const fef::IIndexEnvironment &, fef::IDumpFeatureVisitor &) const
{
}
-search::fef::Blueprint::UP
+fef::Blueprint::UP
RandomBlueprint::createInstance() const
{
- return search::fef::Blueprint::UP(new RandomBlueprint());
+ return std::make_unique<RandomBlueprint>();
}
bool
-RandomBlueprint::setup(const search::fef::IIndexEnvironment & env,
- const search::fef::ParameterList &)
+RandomBlueprint::setup(const fef::IIndexEnvironment & env, const fef::ParameterList &)
{
- search::fef::Property p = env.getProperties().lookup(getName(), "seed");
+ fef::Property p = env.getProperties().lookup(getName(), "seed");
if (p.found()) {
_seed = util::strToNum<uint64_t>(p.get());
}
@@ -63,14 +59,14 @@ RandomBlueprint::setup(const search::fef::IIndexEnvironment & env,
return true;
}
-search::fef::FeatureExecutor &
-RandomBlueprint::createExecutor(const search::fef::IQueryEnvironment &env, vespalib::Stash &stash) const
+using namespace std::chrono;
+
+fef::FeatureExecutor &
+RandomBlueprint::createExecutor(const fef::IQueryEnvironment &env, vespalib::Stash &stash) const
{
uint64_t seed = _seed;
if (seed == 0) {
- FastOS_Time time;
- time.SetNow();
- seed = static_cast<uint64_t>(time.MicroSecs()) ^
+ seed = static_cast<uint64_t>(duration_cast<microseconds>(system_clock::now().time_since_epoch()).count()) ^
reinterpret_cast<uint64_t>(&seed); // results in different seeds in different threads
}
uint64_t matchSeed = util::strToNum<uint64_t>
diff --git a/searchsummary/src/tests/extractkeywords/extractkeywordstest.cpp b/searchsummary/src/tests/extractkeywords/extractkeywordstest.cpp
index b2920b39eaf..5d1025c6de2 100644
--- a/searchsummary/src/tests/extractkeywords/extractkeywordstest.cpp
+++ b/searchsummary/src/tests/extractkeywords/extractkeywordstest.cpp
@@ -3,7 +3,7 @@
#include "extractkeywordstest.h"
#include <vespa/searchsummary/docsummary/keywordextractor.h>
#include <vespa/searchlib/parsequery/simplequerystack.h>
-#include <vespa/fastos/time.h>
+#include <vespa/fastos/timestamp.h>
#define NUMTESTS 5
@@ -94,11 +94,10 @@ ExtractKeywordsTest::Main()
int testCnt = 0;
// init keyword extractor
- _extractor = new search::docsummary::KeywordExtractor(NULL);
+ _extractor = new search::docsummary::KeywordExtractor(nullptr);
_extractor->AddLegalIndexSpec("*");
- FastOS_Time timer;
- timer.SetNow();
+ fastos::StopWatch timer;
// Actually run the tests that we wanted.
for (int j = 0; j < multiplier; j++)
@@ -110,7 +109,7 @@ ExtractKeywordsTest::Main()
}
// Print time taken
- double timeTaken = timer.MilliSecsToNow();
+ double timeTaken = timer.elapsed().ms();
printf("Time taken : %f ms\n", timeTaken);
printf("Number of tests run: %d\n", testCnt);
@@ -118,7 +117,7 @@ ExtractKeywordsTest::Main()
printf("Tests pr Sec: %f\n", avgTestPrMSec * 1000.0);
delete _extractor;
- _extractor = NULL;
+ _extractor = nullptr;
return failed ? 1 : 0;
}
@@ -159,8 +158,8 @@ ExtractKeywordsTest::RunTest(int testno, bool verify)
{
search::SimpleQueryStack stack;
search::RawBuf buf(32768);
- const char *correct = NULL;
- const char *keywords = NULL;
+ const char *correct = nullptr;
+ const char *keywords = nullptr;
switch (testno) {
case 0:
diff --git a/slobrok/src/vespa/slobrok/server/reserved_name.cpp b/slobrok/src/vespa/slobrok/server/reserved_name.cpp
index 389154f16b8..1b36c86592e 100644
--- a/slobrok/src/vespa/slobrok/server/reserved_name.cpp
+++ b/slobrok/src/vespa/slobrok/server/reserved_name.cpp
@@ -1,2 +1,23 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "reserved_name.h"
+
+using std::chrono::duration_cast;
+
+namespace slobrok {
+
+ReservedName::ReservedName(const std::string &name, const std::string &spec, bool local)
+ : NamedService(name, spec),
+ _reservedTime(steady_clock::now()),
+ isLocal(local)
+{ }
+
+bool
+ReservedName::stillReserved() const {
+ return (milliseconds() < 15000);
+}
+
+int64_t ReservedName::milliseconds() const {
+ return duration_cast<std::chrono::milliseconds>(steady_clock::now() - _reservedTime).count();
+}
+
+} \ No newline at end of file
diff --git a/slobrok/src/vespa/slobrok/server/reserved_name.h b/slobrok/src/vespa/slobrok/server/reserved_name.h
index 1ebed4b94dc..0b2a4c392ee 100644
--- a/slobrok/src/vespa/slobrok/server/reserved_name.h
+++ b/slobrok/src/vespa/slobrok/server/reserved_name.h
@@ -2,7 +2,7 @@
#pragma once
#include "named_service.h"
-#include <vespa/fastos/time.h>
+#include <chrono>
namespace slobrok {
@@ -18,19 +18,14 @@ namespace slobrok {
class ReservedName: public NamedService
{
private:
- FastOS_Time _reservedTime;
+ using steady_clock = std::chrono::steady_clock;
+ steady_clock::time_point _reservedTime;
+ int64_t milliseconds() const;
public:
const bool isLocal;
- ReservedName(const std::string &name, const std::string &spec, bool local)
- : NamedService(name, spec), _reservedTime(), isLocal(local)
- {
- _reservedTime.SetNow();
- }
- bool stillReserved() const {
- return (_reservedTime.MilliSecsToNow() < 15000);
- }
- int seconds() const { return _reservedTime.MilliSecsToNow() / 1000; }
+ ReservedName(const std::string &name, const std::string &spec, bool local);
+ bool stillReserved() const;
};
//-----------------------------------------------------------------------------
diff --git a/storage/src/tests/storageserver/documentapiconvertertest.cpp b/storage/src/tests/storageserver/documentapiconvertertest.cpp
index f006277a7b6..16b43828120 100644
--- a/storage/src/tests/storageserver/documentapiconvertertest.cpp
+++ b/storage/src/tests/storageserver/documentapiconvertertest.cpp
@@ -28,6 +28,7 @@ using document::DocumentTypeRepo;
using document::readDocumenttypesConfig;
using document::test::makeDocumentBucket;
using namespace ::testing;
+using namespace std::chrono_literals;
namespace storage {
@@ -186,7 +187,7 @@ TEST_F(DocumentApiConverterTest, get) {
TEST_F(DocumentApiConverterTest, create_visitor) {
documentapi::CreateVisitorMessage cv("mylib", "myinstance", "control-dest", "data-dest");
cv.setBucketSpace(defaultSpaceName);
- cv.setTimeRemaining(123456);
+ cv.setTimeRemaining(123456ms);
auto cmd = toStorageAPI<api::CreateVisitorCommand>(cv);
EXPECT_EQ(defaultBucketSpace, cmd->getBucket().getBucketSpace());
@@ -202,7 +203,7 @@ TEST_F(DocumentApiConverterTest, create_visitor) {
TEST_F(DocumentApiConverterTest, create_visitor_high_timeout) {
documentapi::CreateVisitorMessage cv("mylib", "myinstance", "control-dest", "data-dest");
- cv.setTimeRemaining((uint64_t)std::numeric_limits<uint32_t>::max() + 1); // Will be INT_MAX
+ cv.setTimeRemaining(std::chrono::milliseconds(1l << 32)); // Will be larger than INT_MAX
auto cmd = toStorageAPI<api::CreateVisitorCommand>(cv);
EXPECT_EQ("mylib", cmd->getLibraryName());
diff --git a/storage/src/vespa/storage/common/statusmetricconsumer.cpp b/storage/src/vespa/storage/common/statusmetricconsumer.cpp
index d458a821e02..6d5b6b1eb2b 100644
--- a/storage/src/vespa/storage/common/statusmetricconsumer.cpp
+++ b/storage/src/vespa/storage/common/statusmetricconsumer.cpp
@@ -33,9 +33,7 @@ StatusMetricConsumer::StatusMetricConsumer(
_component.registerStatusPage(*this);
}
-StatusMetricConsumer::~StatusMetricConsumer()
-{
-}
+StatusMetricConsumer::~StatusMetricConsumer() = default;
void
StatusMetricConsumer::updateMetrics(const MetricLockGuard & guard)
@@ -79,7 +77,6 @@ namespace {
name = "Clone of total metrics with active metrics added";
}
std::vector<char> buffer(40);
- //FastOS_Time::GMT_timestr(&buffer[0], data.first)
out << " <tr>\n"
<< " <td>" << name << "</td>\n";
//if (snapshot.getToTime() != 0 || interval < 0 || building != 0)
diff --git a/storage/src/vespa/storage/storageserver/communicationmanager.cpp b/storage/src/vespa/storage/storageserver/communicationmanager.cpp
index 978d434847e..499d7ce15ac 100644
--- a/storage/src/vespa/storage/storageserver/communicationmanager.cpp
+++ b/storage/src/vespa/storage/storageserver/communicationmanager.cpp
@@ -148,7 +148,7 @@ CommunicationManager::handleMessage(std::unique_ptr<mbus::Message> msg)
//TODO: Can it be moved ?
std::shared_ptr<api::StorageCommand> cmd = storMsgPtr->getCommand();
- cmd->setTimeout(storMsgPtr->getTimeRemaining());
+ cmd->setTimeout(storMsgPtr->getTimeRemaining().count());
cmd->setTrace(storMsgPtr->getTrace());
cmd->setTransportContext(std::make_unique<StorageTransportContext>(std::move(storMsgPtr)));
@@ -567,7 +567,7 @@ CommunicationManager::sendCommand(
cmd->setContext(mbus::Context(msg->getMsgId()));
cmd->setRetryEnabled(address.retryEnabled());
- cmd->setTimeRemaining(msg->getTimeout());
+ cmd->setTimeRemaining(std::chrono::milliseconds(msg->getTimeout()));
cmd->setTrace(msg->getTrace());
sendMessageBusMessage(msg, std::move(cmd), address.getRoute());
break;
diff --git a/storage/src/vespa/storage/storageserver/documentapiconverter.cpp b/storage/src/vespa/storage/storageserver/documentapiconverter.cpp
index 54b1a9ae257..c6a16de3282 100644
--- a/storage/src/vespa/storage/storageserver/documentapiconverter.cpp
+++ b/storage/src/vespa/storage/storageserver/documentapiconverter.cpp
@@ -20,6 +20,8 @@ LOG_SETUP(".documentapiconverter");
using document::BucketSpace;
+using std::chrono::milliseconds;
+
namespace storage {
DocumentApiConverter::DocumentApiConverter(const config::ConfigUri &configUri,
@@ -28,7 +30,7 @@ DocumentApiConverter::DocumentApiConverter(const config::ConfigUri &configUri,
_bucketResolver(std::move(bucketResolver))
{}
-DocumentApiConverter::~DocumentApiConverter() {}
+DocumentApiConverter::~DocumentApiConverter() = default;
std::unique_ptr<api::StorageCommand>
DocumentApiConverter::toStorageAPI(documentapi::DocumentMessage& fromMsg)
@@ -139,11 +141,8 @@ DocumentApiConverter::toStorageAPI(documentapi::DocumentMessage& fromMsg)
}
if (toMsg.get() != 0) {
- int64_t timeout = fromMsg.getTimeRemaining();
- if (timeout > INT_MAX) {
- timeout = INT_MAX;
- }
- toMsg->setTimeout(timeout);
+ milliseconds timeout = std::min(milliseconds(INT_MAX), fromMsg.getTimeRemaining());
+ toMsg->setTimeout(timeout.count());
toMsg->setPriority(_priConverter->toStoragePriority(fromMsg.getPriority()));
toMsg->setLoadType(fromMsg.getLoadType());
@@ -310,7 +309,7 @@ DocumentApiConverter::toDocumentAPI(api::StorageCommand& fromMsg)
}
if (toMsg.get()) {
- toMsg->setTimeRemaining(fromMsg.getTimeout());
+ toMsg->setTimeRemaining(milliseconds(fromMsg.getTimeout()));
toMsg->setContext(mbus::Context(fromMsg.getMsgId()));
if (LOG_WOULD_LOG(spam)) {
toMsg->getTrace().setLevel(9);
diff --git a/storage/src/vespa/storage/visiting/visitor.cpp b/storage/src/vespa/storage/visiting/visitor.cpp
index 3bed02f88fe..4b213dff1d5 100644
--- a/storage/src/vespa/storage/visiting/visitor.cpp
+++ b/storage/src/vespa/storage/visiting/visitor.cpp
@@ -237,11 +237,11 @@ Visitor::sendMessage(documentapi::DocumentMessage::UP cmd)
framework::MicroSecTime time(_component.getClock().getTimeInMicros());
if (time + _docBlockTimeout.getMicros() > _timeToDie) {
- cmd->setTimeRemaining((_timeToDie > time)
+ cmd->setTimeRemaining(std::chrono::milliseconds((_timeToDie > time)
? (_timeToDie - time).getMillis().getTime()
- : 0);
+ : 0));
} else {
- cmd->setTimeRemaining(_docBlockTimeout.getTime());
+ cmd->setTimeRemaining(std::chrono::milliseconds(_docBlockTimeout.getTime()));
}
cmd->getTrace().setLevel(_traceLevel);
@@ -301,7 +301,7 @@ Visitor::sendInfoMessage(documentapi::VisitorInfoMessage::UP cmd)
if (_controlDestination->toString().length()) {
cmd->setRoute(_controlDestination->getRoute());
cmd->setPriority(_documentPriority);
- cmd->setTimeRemaining(_visitorInfoTimeout.getTime());
+ cmd->setTimeRemaining(std::chrono::milliseconds(_visitorInfoTimeout.getTime()));
auto& msgMeta = _visitorTarget.insertMessage(std::move(cmd));
sendDocumentApiMessage(msgMeta);
}
@@ -637,7 +637,7 @@ Visitor::handleDocumentApiReply(mbus::Reply::UP reply,
if (!reply->hasErrors()) {
metrics.averageMessageSendTime[getLoadType()].addValue(
- (message->getTimeRemaining() - message->getTimeRemainingNow()) / 1000.0);
+ (message->getTimeRemaining() - message->getTimeRemainingNow()).count() / 1000.0);
LOG(debug, "Visitor '%s' reply %s for message ID %" PRIu64 " was OK", _id.c_str(),
reply->toString().c_str(), messageId);
diff --git a/vespalib/src/tests/btree/iteratespeed.cpp b/vespalib/src/tests/btree/iteratespeed.cpp
index 20aad948f33..82aa9bb5f54 100644
--- a/vespalib/src/tests/btree/iteratespeed.cpp
+++ b/vespalib/src/tests/btree/iteratespeed.cpp
@@ -106,7 +106,7 @@ IterateSpeed::workLoop(int loops, bool enableForward, bool enableBackwards,
[&](int key) { sum += key; } );
}
}
- double used = stopWatch.stop().elapsed().sec();
+ double used = stopWatch.elapsed().sec();
printf("Elapsed time for iterating %ld steps is %8.5f, "
"direction=%s, fanout=%u,%u, sum=%" PRIu64 "\n",
numEntries * numInnerLoops,
diff --git a/vespalib/src/vespa/vespalib/testkit/test_comparators.h b/vespalib/src/vespa/vespalib/testkit/test_comparators.h
index 02e7566c976..5119aaebea6 100644
--- a/vespalib/src/vespa/vespalib/testkit/test_comparators.h
+++ b/vespalib/src/vespa/vespalib/testkit/test_comparators.h
@@ -3,6 +3,17 @@
#pragma once
#include <vespa/vespalib/util/approx.h>
+#include <ostream>
+#include <chrono>
+
+namespace std::chrono {
+//TODO Move to a more suitable place
+template <typename rep, typename period>
+ostream & operator << (ostream & os, duration<rep, period> ts) {
+ return os << ts.count();
+}
+
+}
namespace vespalib {
diff --git a/vespalib/src/vespa/vespalib/util/slaveproc.cpp b/vespalib/src/vespa/vespalib/util/slaveproc.cpp
index 8b35fa3559b..6f40aa9a4d7 100644
--- a/vespalib/src/vespa/vespalib/util/slaveproc.cpp
+++ b/vespalib/src/vespa/vespalib/util/slaveproc.cpp
@@ -1,47 +1,48 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/fastos/time.h>
#include "guard.h"
#include "slaveproc.h"
#include <cstring>
-#ifndef FASTOS_NO_THREADS
-
namespace vespalib {
namespace slaveproc {
+using namespace std::chrono;
+
/**
* @brief SlaveProc internal timeout management.
**/
class Timer
{
private:
- FastOS_Time _startTime;
- int _maxTime;
- int _elapsed;
+ const steady_clock::time_point _startTime;
+ const int64_t _maxTimeMS;
+ milliseconds _elapsed;
public:
- Timer(int maxTime) : _startTime(), _maxTime(maxTime), _elapsed(0) {
- _startTime.SetNow();
- }
+ Timer(int64_t maxTimeMS)
+ : _startTime(steady_clock::now()),
+ _maxTimeMS(maxTimeMS),
+ _elapsed(0)
+ { }
Timer &update() {
- _elapsed = (int) _startTime.MilliSecsToNow();
+ _elapsed = duration_cast<milliseconds>(steady_clock::now() - _startTime);
return *this;
}
- int elapsed() const {
- return _elapsed;
+ int64_t elapsed() const {
+ return _elapsed.count();
}
- int remaining() const {
- if (_maxTime == -1) {
+ int64_t remaining() const {
+ if (_maxTimeMS == -1) {
return -1;
}
- if (_elapsed > _maxTime) {
+ if (elapsed() > _maxTimeMS) {
return 0;
}
- return (_maxTime - _elapsed);
+ return (_maxTimeMS - _elapsed.count());
}
- int waitTime() const {
+ int64_t waitTime() const {
int res = remaining();
if (res >= 0 && res <= 10000) {
return res;
@@ -216,9 +217,7 @@ SlaveProc::SlaveProc(const char *cmd)
}
-SlaveProc::~SlaveProc()
-{
-}
+SlaveProc::~SlaveProc() = default;
bool
@@ -234,7 +233,7 @@ SlaveProc::write(const char *buf, uint32_t len)
bool
SlaveProc::close()
{
- return _proc.WriteStdin(NULL, 0);
+ return _proc.WriteStdin(nullptr, 0);
}
@@ -309,7 +308,7 @@ SlaveProc::run(const std::string &input, const char *cmd,
output.append(buf, res);
timer.update();
}
- if (output.size() > 0 && output.find('\n') == output.size() - 1) {
+ if ( ! output.empty() && output.find('\n') == output.size() - 1) {
output.erase(output.size() - 1, 1);
}
proc.wait(timer.update().remaining());
@@ -334,5 +333,3 @@ SlaveProc::run(const char *cmd, int msTimeout)
}
} // namespace vespalib
-
-#endif // FASTOS_NO_THREADS
diff --git a/vespalib/src/vespa/vespalib/util/time_tracker.h b/vespalib/src/vespa/vespalib/util/time_tracker.h
index 99f88d69110..95dc8feb325 100644
--- a/vespalib/src/vespa/vespalib/util/time_tracker.h
+++ b/vespalib/src/vespa/vespalib/util/time_tracker.h
@@ -16,11 +16,12 @@ private:
struct Task {
vespalib::string name;
fastos::StopWatch task_time;
+ fastos::TimeStamp elapsed;
std::vector<Task> sub_tasks;
- Task(const char *name_in) : name(name_in), task_time() { }
+ Task(const char *name_in) : name(name_in), task_time(), elapsed() { }
~Task();
- void close_task() { task_time.stop(); }
- double ms() const { return (task_time.elapsed().sec() * 1000.0); }
+ void close_task() { elapsed = task_time.elapsed(); }
+ double ms() const { return elapsed.sec()*1000.0; }
};
std::vector<Task> _tasks;