public class RateLimiter extends RocksObject
Modifier and Type | Field and Description |
---|---|
static boolean |
DEFAULT_AUTOTUNE |
static int |
DEFAULT_FAIRNESS |
static RateLimiterMode |
DEFAULT_MODE |
static long |
DEFAULT_REFILL_PERIOD_MICROS |
nativeHandle_
Constructor and Description |
---|
RateLimiter(long rateBytesPerSecond)
RateLimiter constructor
|
RateLimiter(long rateBytesPerSecond,
long refillPeriodMicros)
RateLimiter constructor
|
RateLimiter(long rateBytesPerSecond,
long refillPeriodMicros,
int fairness)
RateLimiter constructor
|
RateLimiter(long rateBytesPerSecond,
long refillPeriodMicros,
int fairness,
RateLimiterMode rateLimiterMode)
RateLimiter constructor
|
RateLimiter(long rateBytesPerSecond,
long refillPeriodMicros,
int fairness,
RateLimiterMode rateLimiterMode,
boolean autoTune)
RateLimiter constructor
|
Modifier and Type | Method and Description |
---|---|
protected void |
disposeInternal(long handle) |
long |
getBytesPerSecond()
Returns the bytes per second.
|
long |
getSingleBurstBytes()
Max bytes can be granted in a single burst.
|
long |
getTotalBytesThrough()
Total bytes that go though rate limiter.
|
long |
getTotalRequests()
Total # of requests that go though rate limiter.
|
void |
request(long bytes)
Request for token to write bytes.
|
void |
setBytesPerSecond(long bytesPerSecond)
This API allows user to dynamically change rate limiter's bytes per second.
|
disposeInternal
close, disOwnNativeHandle, isOwningHandle
dispose, finalize
public static final long DEFAULT_REFILL_PERIOD_MICROS
public static final int DEFAULT_FAIRNESS
public static final RateLimiterMode DEFAULT_MODE
public static final boolean DEFAULT_AUTOTUNE
public RateLimiter(long rateBytesPerSecond)
rateBytesPerSecond
- this is the only parameter you want to set
most of the time. It controls the total write rate of compaction
and flush in bytes per second. Currently, RocksDB does not enforce
rate limit for anything other than flush and compaction, e.g. write to
WAL.public RateLimiter(long rateBytesPerSecond, long refillPeriodMicros)
rateBytesPerSecond
- this is the only parameter you want to set
most of the time. It controls the total write rate of compaction
and flush in bytes per second. Currently, RocksDB does not enforce
rate limit for anything other than flush and compaction, e.g. write to
WAL.refillPeriodMicros
- this controls how often tokens are refilled. For
example,
when rate_bytes_per_sec is set to 10MB/s and refill_period_us is set to
100ms, then 1MB is refilled every 100ms internally. Larger value can
lead to burstier writes while smaller value introduces more CPU
overhead. The default of 100,000ms should work for most cases.public RateLimiter(long rateBytesPerSecond, long refillPeriodMicros, int fairness)
rateBytesPerSecond
- this is the only parameter you want to set
most of the time. It controls the total write rate of compaction
and flush in bytes per second. Currently, RocksDB does not enforce
rate limit for anything other than flush and compaction, e.g. write to
WAL.refillPeriodMicros
- this controls how often tokens are refilled. For
example,
when rate_bytes_per_sec is set to 10MB/s and refill_period_us is set to
100ms, then 1MB is refilled every 100ms internally. Larger value can
lead to burstier writes while smaller value introduces more CPU
overhead. The default of 100,000ms should work for most cases.fairness
- RateLimiter accepts high-pri requests and low-pri requests.
A low-pri request is usually blocked in favor of hi-pri request.
Currently, RocksDB assigns low-pri to request from compaction and
high-pri to request from flush. Low-pri requests can get blocked if
flush requests come in continuously. This fairness parameter grants
low-pri requests permission by fairness chance even though high-pri
requests exist to avoid starvation.
You should be good by leaving it at default 10.public RateLimiter(long rateBytesPerSecond, long refillPeriodMicros, int fairness, RateLimiterMode rateLimiterMode)
rateBytesPerSecond
- this is the only parameter you want to set
most of the time. It controls the total write rate of compaction
and flush in bytes per second. Currently, RocksDB does not enforce
rate limit for anything other than flush and compaction, e.g. write to
WAL.refillPeriodMicros
- this controls how often tokens are refilled. For
example,
when rate_bytes_per_sec is set to 10MB/s and refill_period_us is set to
100ms, then 1MB is refilled every 100ms internally. Larger value can
lead to burstier writes while smaller value introduces more CPU
overhead. The default of 100,000ms should work for most cases.fairness
- RateLimiter accepts high-pri requests and low-pri requests.
A low-pri request is usually blocked in favor of hi-pri request.
Currently, RocksDB assigns low-pri to request from compaction and
high-pri to request from flush. Low-pri requests can get blocked if
flush requests come in continuously. This fairness parameter grants
low-pri requests permission by fairness chance even though high-pri
requests exist to avoid starvation.
You should be good by leaving it at default 10.rateLimiterMode
- indicates which types of operations count against
the limit.public RateLimiter(long rateBytesPerSecond, long refillPeriodMicros, int fairness, RateLimiterMode rateLimiterMode, boolean autoTune)
rateBytesPerSecond
- this is the only parameter you want to set
most of the time. It controls the total write rate of compaction
and flush in bytes per second. Currently, RocksDB does not enforce
rate limit for anything other than flush and compaction, e.g. write to
WAL.refillPeriodMicros
- this controls how often tokens are refilled. For
example,
when rate_bytes_per_sec is set to 10MB/s and refill_period_us is set to
100ms, then 1MB is refilled every 100ms internally. Larger value can
lead to burstier writes while smaller value introduces more CPU
overhead. The default of 100,000ms should work for most cases.fairness
- RateLimiter accepts high-pri requests and low-pri requests.
A low-pri request is usually blocked in favor of hi-pri request.
Currently, RocksDB assigns low-pri to request from compaction and
high-pri to request from flush. Low-pri requests can get blocked if
flush requests come in continuously. This fairness parameter grants
low-pri requests permission by fairness chance even though high-pri
requests exist to avoid starvation.
You should be good by leaving it at default 10.rateLimiterMode
- indicates which types of operations count against
the limit.autoTune
- Enables dynamic adjustment of rate limit within the range
[rate_bytes_per_sec / 20, rate_bytes_per_sec]
, according to
the recent demand for background I/O.public void setBytesPerSecond(long bytesPerSecond)
This API allows user to dynamically change rate limiter's bytes per second. REQUIRED: bytes_per_second > 0
bytesPerSecond
- bytes per second.public long getBytesPerSecond()
public void request(long bytes)
Request for token to write bytes. If this request can not be satisfied,
the call is blocked. Caller is responsible to make sure
bytes < GetSingleBurstBytes()
.
bytes
- requested bytes.public long getSingleBurstBytes()
Max bytes can be granted in a single burst.
public long getTotalBytesThrough()
Total bytes that go though rate limiter.
public long getTotalRequests()
Total # of requests that go though rate limiter.
protected final void disposeInternal(long handle)
disposeInternal
in class RocksObject