Files
scylladb/utils/rate_limiter.hh
Calle Wilund 8a8694cbbf Add naive rate limiter object
This is mostly a placeholder, since the "limiting" is rather coarse
and stuttering
2015-07-08 10:50:46 +02:00

31 lines
578 B
C++

/*
* Copyright 2015 Cloudius Systems
*/
#pragma once
#include "core/timer.hh"
#include "core/semaphore.hh"
#include "core/reactor.hh"
namespace utils {
/**
* 100% naive rate limiter. Consider it a placeholder
* Will let you process X "units" per second, then reset this every s.
* Obviously, accuracy is virtually non-existant and steady rate will fluctuate.
*/
class rate_limiter {
private:
timer<lowres_clock> _timer;
size_t _units_per_s;
semaphore _sem;
void on_timer();
public:
rate_limiter(size_t rate);
future<> reserve(size_t u);
};
}