diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-02-17 22:23:13 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-02-17 22:23:13 +0000 |
commit | cc34e970770e668048e65c4bf2eb946b05fb014e (patch) | |
tree | 5d5af4a78d4149fd7c3a859fe278ad743efe46b3 /vespalib/src | |
parent | e036cfe803b94b343cc41a1a80b07115fdbeb0ce (diff) |
Add a base vespa timer frequency that is used as a base to control poll frequency of various tasks.
Diffstat (limited to 'vespalib/src')
-rw-r--r-- | vespalib/src/tests/time/time_test.cpp | 4 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/time.cpp | 18 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/time.h | 5 |
3 files changed, 27 insertions, 0 deletions
diff --git a/vespalib/src/tests/time/time_test.cpp b/vespalib/src/tests/time/time_test.cpp index 0bef18ddc0d..c2858308006 100644 --- a/vespalib/src/tests/time/time_test.cpp +++ b/vespalib/src/tests/time/time_test.cpp @@ -64,4 +64,8 @@ TEST(TimeTest, conversion_of_max) { EXPECT_EQ(9223372036.8547764, vespalib::to_s(vespalib::duration::max())); } +TEST(TimeTest, default_timer_frequency_is_1000_hz) { + EXPECT_EQ(1000u, getVespaTimerHz()); +} + GTEST_MAIN_RUN_ALL_TESTS() diff --git a/vespalib/src/vespa/vespalib/util/time.cpp b/vespalib/src/vespa/vespalib/util/time.cpp index b5c019b4a27..bcc289489ea 100644 --- a/vespalib/src/vespa/vespalib/util/time.cpp +++ b/vespalib/src/vespa/vespalib/util/time.cpp @@ -3,6 +3,9 @@ #include "time.h" #include <thread> +#include <vespa/log/log.h> + +LOG_SETUP(".vespalib.time"); namespace vespalib { system_time @@ -12,6 +15,21 @@ to_utc(steady_time ts) { return system_time(std::chrono::duration_cast<system_time::duration>(nowUtc.time_since_epoch() - nowSteady.time_since_epoch() + ts.time_since_epoch())); } +uint32_t +getVespaTimerHz() { + const char * vespa_timer_hz = getenv("VESPA_TIMER_HZ"); + if (vespa_timer_hz != nullptr) { + try { + size_t idx(0); + uint32_t tmp = std::stoi(vespa_timer_hz, &idx, 0); + return std::max(1u, std::min(1000u, tmp)); + } catch (const std::exception & e) { + LOG(warning, "Parsing environment VESPA_TIMER_HZ='%s' failed with exception: %s", vespa_timer_hz, e.what()); + } + } + return 1000u; +} + namespace { string diff --git a/vespalib/src/vespa/vespalib/util/time.h b/vespalib/src/vespa/vespalib/util/time.h index f19d71afb32..dbbae862a8d 100644 --- a/vespalib/src/vespa/vespalib/util/time.h +++ b/vespalib/src/vespa/vespalib/util/time.h @@ -88,4 +88,9 @@ public: static void waitAtLeast(duration dur, bool busyWait); }; +/** + * The default frequency (1000hz) for vespa timer, with environment override VESPA_TIMER_HZ capped to [1..1000] + */ +uint32_t getVespaTimerHz(); + } |