diff options
8 files changed, 32 insertions, 5 deletions
diff --git a/config/src/vespa/config/subscription/configsubscriptionset.cpp b/config/src/vespa/config/subscription/configsubscriptionset.cpp index 40dc40d11ef..cbf2eb2333a 100644 --- a/config/src/vespa/config/subscription/configsubscriptionset.cpp +++ b/config/src/vespa/config/subscription/configsubscriptionset.cpp @@ -17,7 +17,7 @@ using vespalib::steady_clock; namespace config { ConfigSubscriptionSet::ConfigSubscriptionSet(std::shared_ptr<IConfigContext> context) - : _maxNapTime(vespalib::from_s(10*1.0/vespalib::getVespaTimerHz())), //10x slower than default timer frequency. + : _maxNapTime(vespalib::adjustTimeoutByDetectedHz(10ms)), _context(std::move(context)), _mgr(_context->getManagerInstance()), _currentGeneration(-1), diff --git a/fnet/src/vespa/fnet/scheduler.cpp b/fnet/src/vespa/fnet/scheduler.cpp index c6b1263bf61..f4e1e31219c 100644 --- a/fnet/src/vespa/fnet/scheduler.cpp +++ b/fnet/src/vespa/fnet/scheduler.cpp @@ -8,7 +8,7 @@ #include <vespa/log/log.h> LOG_SETUP(".fnet.scheduler"); -const vespalib::duration FNET_Scheduler::tick_ms = vespalib::from_s(10*1.0/vespalib::getVespaTimerHz()); +const vespalib::duration FNET_Scheduler::tick_ms = vespalib::adjustTimeoutByDetectedHz(10ms); FNET_Scheduler::FNET_Scheduler(vespalib::steady_time *sampler) : _cond(), diff --git a/searchcore/src/vespa/searchcore/proton/server/shared_threading_service.cpp b/searchcore/src/vespa/searchcore/proton/server/shared_threading_service.cpp index 1f06b29518b..b36dce23e28 100644 --- a/searchcore/src/vespa/searchcore/proton/server/shared_threading_service.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/shared_threading_service.cpp @@ -26,7 +26,7 @@ SharedThreadingService::SharedThreadingService(const SharedThreadingServiceConfi _shared(std::make_shared<vespalib::BlockingThreadStackExecutor>(cfg.shared_threads(), 128_Ki, cfg.shared_task_limit(), proton_shared_executor)), _field_writer(), - _invokeService(std::max(vespalib::from_s(1.0/vespalib::getVespaTimerHz()), + _invokeService(std::max(vespalib::adjustTimeoutByDetectedHz(1ms), cfg.field_writer_config().reactionTime())), _invokeRegistrations() { diff --git a/storage/src/vespa/storage/distributor/distributor_stripe_pool.cpp b/storage/src/vespa/storage/distributor/distributor_stripe_pool.cpp index d501172731a..8b172743d27 100644 --- a/storage/src/vespa/storage/distributor/distributor_stripe_pool.cpp +++ b/storage/src/vespa/storage/distributor/distributor_stripe_pool.cpp @@ -15,7 +15,7 @@ DistributorStripePool::DistributorStripePool(bool test_mode, PrivateCtorTag) _mutex(), _parker_cond(), _parked_threads(0), - _bootstrap_tick_wait_duration(vespalib::from_s(1.0/vespalib::getVespaTimerHz())), + _bootstrap_tick_wait_duration(vespalib::adjustTimeoutByDetectedHz(1ms)), _bootstrap_ticks_before_wait(10), _single_threaded_test_mode(test_mode), _stopped(false) diff --git a/storage/src/vespa/storage/distributor/distributor_stripe_thread.cpp b/storage/src/vespa/storage/distributor/distributor_stripe_thread.cpp index 94e4dc648cc..ae5445da620 100644 --- a/storage/src/vespa/storage/distributor/distributor_stripe_thread.cpp +++ b/storage/src/vespa/storage/distributor/distributor_stripe_thread.cpp @@ -11,7 +11,7 @@ DistributorStripeThread::DistributorStripeThread(TickableStripe& stripe, DistributorStripePool& stripe_pool) : _stripe(stripe), _stripe_pool(stripe_pool), - _tick_wait_duration(vespalib::from_s(1.0/vespalib::getVespaTimerHz())), + _tick_wait_duration(vespalib::adjustTimeoutByDetectedHz(1ms)), _mutex(), _event_cond(), _park_cond(), diff --git a/vespalib/src/tests/time/time_test.cpp b/vespalib/src/tests/time/time_test.cpp index c2858308006..0ca583c8326 100644 --- a/vespalib/src/tests/time/time_test.cpp +++ b/vespalib/src/tests/time/time_test.cpp @@ -68,4 +68,19 @@ TEST(TimeTest, default_timer_frequency_is_1000_hz) { EXPECT_EQ(1000u, getVespaTimerHz()); } +TEST(TimeTest, timeout_is_relative_to_frequency) { + EXPECT_EQ(1000u, getVespaTimerHz()); + + EXPECT_EQ(1ms, adjustTimeoutByDetectedHz(1ms)); + EXPECT_EQ(20ms, adjustTimeoutByDetectedHz(20ms)); + + EXPECT_EQ(1ms, adjustTimeoutByHz(1ms, 1000)); + EXPECT_EQ(10ms, adjustTimeoutByHz(1ms, 100)); + EXPECT_EQ(100ms, adjustTimeoutByHz(1ms, 10)); + + EXPECT_EQ(20ms, adjustTimeoutByHz(20ms, 1000)); + EXPECT_EQ(200ms, adjustTimeoutByHz(20ms, 100)); + EXPECT_EQ(2000ms, adjustTimeoutByHz(20ms, 10)); +} + GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/vespa/vespalib/util/time.cpp b/vespalib/src/vespa/vespalib/util/time.cpp index bcc289489ea..3737a25f268 100644 --- a/vespalib/src/vespa/vespalib/util/time.cpp +++ b/vespalib/src/vespa/vespalib/util/time.cpp @@ -30,6 +30,16 @@ getVespaTimerHz() { return 1000u; } +duration +adjustTimeoutByHz(duration timeout, long hz) { + return (timeout * 1000) / hz; +} + +duration +adjustTimeoutByDetectedHz(duration timeout) { + return adjustTimeoutByHz(timeout, getVespaTimerHz()); +} + namespace { string diff --git a/vespalib/src/vespa/vespalib/util/time.h b/vespalib/src/vespa/vespalib/util/time.h index dbbae862a8d..783831b5171 100644 --- a/vespalib/src/vespa/vespalib/util/time.h +++ b/vespalib/src/vespa/vespalib/util/time.h @@ -92,5 +92,7 @@ public: * The default frequency (1000hz) for vespa timer, with environment override VESPA_TIMER_HZ capped to [1..1000] */ uint32_t getVespaTimerHz(); +duration adjustTimeoutByDetectedHz(duration timeout); +duration adjustTimeoutByHz(duration timeout, long hz); } |