Skip to content

Commit

Permalink
Merge pull request #21467 from vespa-engine/balder/add-and-use-common…
Browse files Browse the repository at this point in the history
…-adjustTimeoutByDetectedHz

Add a simple adjustTimeoutByDetectedHz to compute a suitable timeout/…
  • Loading branch information
baldersheim authored Mar 1, 2022
2 parents a997a80 + a46a98b commit 891b71d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion fnet/src/vespa/fnet/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
15 changes: 15 additions & 0 deletions vespalib/src/tests/time/time_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
10 changes: 10 additions & 0 deletions vespalib/src/vespa/vespalib/util/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions vespalib/src/vespa/vespalib/util/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,7 @@ class Timer
* 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);

}

0 comments on commit 891b71d

Please sign in to comment.