From 82561693ee5ba6d27f68b3c1d32b86f9f09c4230 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Sun, 7 Oct 2018 19:23:22 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20option=20for=20unlimited=20ca?= =?UTF-8?q?pacity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rateLimiter.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/rateLimiter.c b/src/rateLimiter.c index 046ce63..679a62c 100644 --- a/src/rateLimiter.c +++ b/src/rateLimiter.c @@ -8,12 +8,12 @@ #include "rateLimiter.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 /** 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 * 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 #define CAPACITY_MAX DISK_SPEED * MAX_IDLE_TIME @@ -39,6 +39,11 @@ void increaseCapacity() { /** Pauses execution until the given amount of capacity is available */ void consumeCapacity(unsigned long numBytes) { + //Exit early if there is no capacity limit + if (CAPACITY_MAX == 0UL) { + return; + } + if (numBytes > CAPACITY_MAX) { fprintf(stderr, "Could not consume %lu bytes in rate limiter; maximum is %lu.\n", numBytes, CAPACITY_MAX); errorAndExit();