Skip to content

Commit

Permalink
Move lockfree bucket to ydb/library
Browse files Browse the repository at this point in the history
  • Loading branch information
serbel324 committed Sep 6, 2024
1 parent 75833b6 commit 6117a84
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 37 deletions.
33 changes: 31 additions & 2 deletions library/cpp/bucket_quoter/bucket_quoter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <library/cpp/deprecated/atomic/atomic.h>

#include <util/datetime/base.h>
#include <util/system/mutex.h>

#include "timers.h"
#include <util/system/hp_timer.h>

/* Token bucket.
* Makes flow of *inflow* units per second in average, with up to *capacity* bursts.
Expand Down Expand Up @@ -41,6 +41,35 @@
*/

struct TInstantTimerMs {
using TTime = TInstant;
static constexpr ui64 Resolution = 1000ull; // milliseconds
static TTime Now() {
return TInstant::Now();
}
static ui64 Duration(TTime from, TTime to) {
return (to - from).MilliSeconds();
}
};

struct THPTimerUs {
using TTime = NHPTimer::STime;
static constexpr ui64 Resolution = 1000000ull; // microseconds
static TTime Now() {
NHPTimer::STime ret;
NHPTimer::GetTime(&ret);
return ret;
}
static ui64 Duration(TTime from, TTime to) {
i64 cycles = to - from;
if (cycles > 0) {
return ui64(double(cycles) * double(Resolution) / NHPTimer::GetClockRate());
} else {
return 0;
}
}
};

template <typename StatCounter, typename Lock = TMutex, typename Timer = TInstantTimerMs>
class TBucketQuoter {
public:
Expand Down
33 changes: 0 additions & 33 deletions library/cpp/bucket_quoter/timers.h

This file was deleted.

3 changes: 2 additions & 1 deletion ydb/core/blobstorage/vdisk/common/blobstorage_cost_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include "vdisk_mongroups.h"
#include "vdisk_performance_params.h"

#include <library/cpp/lockfree_bucket/lockfree_bucket.h>
#include <library/cpp/bucket_quoter/bucket_quoter.h>
#include <ydb/library/lockfree_bucket/lockfree_bucket.h>
#include <util/system/compiler.h>
#include <ydb/core/base/blobstorage.h>
#include <ydb/core/blobstorage/base/blobstorage_events.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <library/cpp/bucket_quoter/timers.h>
#include <util/datetime/base.h>

template<class TTimer = TInstantTimerMs>
template<class TTimer>
class TLockFreeBucket {
public:
TLockFreeBucket(std::atomic<i64>& maxTokens, std::atomic<i64>& minTokens, std::atomic<ui64>& inflowPerSecond)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions ydb/library/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ RECURSE(
grpc
http_proxy
keys
lockfree_bucket
logger
login
mkql_proto
Expand Down

0 comments on commit 6117a84

Please sign in to comment.