✨ Add option for unlimited capacity
This commit is contained in:
parent
06a33676dd
commit
82561693ee
1 changed files with 7 additions and 2 deletions
|
@ -8,12 +8,12 @@
|
||||||
#include "rateLimiter.h"
|
#include "rateLimiter.h"
|
||||||
#include "utils/min.h"
|
#include "utils/min.h"
|
||||||
|
|
||||||
//How many bytes we can write to disk per second: 30 MB/s
|
//How many bytes we can write to disk per second: 30 MB/s. Use 0 to specify no limit
|
||||||
#define DISK_SPEED 30UL * 1024UL * 1024UL
|
#define DISK_SPEED 30UL * 1024UL * 1024UL
|
||||||
/** If we are not writing to disk, how many seconds the capacity can keep increasing before it reaches the limit.
|
/** If we are not writing to disk, how many seconds the capacity can keep increasing before it reaches the limit.
|
||||||
* Increasing this value can result in a spike of data once we are writing to disk again, but then allows the data
|
* Increasing this value can result in a spike of data once we are writing to disk again, but then allows the data
|
||||||
* to quickly be written without having to wait for capacity to be available. */
|
* to quickly be written without having to wait for capacity to be available. */
|
||||||
#define MAX_IDLE_TIME 5UL
|
#define MAX_IDLE_TIME 3UL
|
||||||
//Capacity can be filled up to this maximum amount
|
//Capacity can be filled up to this maximum amount
|
||||||
#define CAPACITY_MAX DISK_SPEED * MAX_IDLE_TIME
|
#define CAPACITY_MAX DISK_SPEED * MAX_IDLE_TIME
|
||||||
|
|
||||||
|
@ -39,6 +39,11 @@ void increaseCapacity() {
|
||||||
|
|
||||||
/** Pauses execution until the given amount of capacity is available */
|
/** Pauses execution until the given amount of capacity is available */
|
||||||
void consumeCapacity(unsigned long numBytes) {
|
void consumeCapacity(unsigned long numBytes) {
|
||||||
|
//Exit early if there is no capacity limit
|
||||||
|
if (CAPACITY_MAX == 0UL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (numBytes > CAPACITY_MAX) {
|
if (numBytes > CAPACITY_MAX) {
|
||||||
fprintf(stderr, "Could not consume %lu bytes in rate limiter; maximum is %lu.\n", numBytes, CAPACITY_MAX);
|
fprintf(stderr, "Could not consume %lu bytes in rate limiter; maximum is %lu.\n", numBytes, CAPACITY_MAX);
|
||||||
errorAndExit();
|
errorAndExit();
|
||||||
|
|
Loading…
Reference in a new issue