Skip to content

Commit d00801f

Browse files
Rob Lyerlymeta-codesync[bot]
authored andcommitted
Use high-precision sleep for throttling
Summary: Makes op delay results more accurate. Reviewed By: pbhandar2 Differential Revision: D86894250 fbshipit-source-id: dd06225aa894b0c2b3d3eeaa0eac7d98eb4bc8dc
1 parent 26b4252 commit d00801f

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

cachelib/cachebench/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "cachelib/cachebench/runner/Runner.h"
2525
#include "cachelib/cachebench/runner/Stressor.h"
26+
#include "cachelib/cachebench/util/Sleep.h"
2627
#include "cachelib/common/Utils.h"
2728

2829
#ifdef CACHEBENCH_FB_ENV
@@ -123,6 +124,7 @@ int main(int argc, char** argv) {
123124
using namespace facebook::cachelib;
124125
using namespace facebook::cachelib::cachebench;
125126

127+
calibrateSleep();
126128
#ifdef CACHEBENCH_FB_ENV
127129
facebook::initFacebook(&argc, &argv);
128130
if (!checkArgsValidity()) {

cachelib/cachebench/runner/AsyncCacheStressor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "cachelib/cachebench/util/Exceptions.h"
3737
#include "cachelib/cachebench/util/Parallel.h"
3838
#include "cachelib/cachebench/util/Request.h"
39+
#include "cachelib/cachebench/util/Sleep.h"
3940
#include "cachelib/cachebench/workload/GeneratorBase.h"
4041

4142
namespace facebook {
@@ -418,7 +419,7 @@ class AsyncCacheStressor : public Stressor {
418419
auto throttleFn = [&] {
419420
if (needDelay && ++opCounter == opDelayBatch) {
420421
opCounter = 0;
421-
std::this_thread::sleep_for(opDelay);
422+
highPrecisionSleep(opDelay);
422423
}
423424
// Limit the rate if specified.
424425
limitRate();

cachelib/cachebench/runner/CacheStressor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "cachelib/cachebench/util/Exceptions.h"
3636
#include "cachelib/cachebench/util/Parallel.h"
3737
#include "cachelib/cachebench/util/Request.h"
38+
#include "cachelib/cachebench/util/Sleep.h"
3839
#include "cachelib/cachebench/workload/GeneratorBase.h"
3940

4041
namespace facebook {
@@ -229,7 +230,7 @@ class CacheStressor : public CacheStressorBase {
229230
auto throttleFn = [&] {
230231
if (needDelay && ++opCounter == opDelayBatch) {
231232
opCounter = 0;
232-
std::this_thread::sleep_for(opDelay);
233+
highPrecisionSleep(opDelay);
233234
}
234235
// Limit the rate if specified.
235236
limitRate();

0 commit comments

Comments
 (0)