Bump scaling to 1000.
Note the error in integer arithmetic
This commit is contained in:
@@ -34,6 +34,13 @@
|
|||||||
*
|
*
|
||||||
* uc_ratelimit_init(&r,20, 1, time(NULL));
|
* uc_ratelimit_init(&r,20, 1, time(NULL));
|
||||||
*
|
*
|
||||||
|
* NOTE. The the internals uses integer arithmetic to replenish the tickets,
|
||||||
|
* this can lead to greater errors estimating the available tickets the smaller
|
||||||
|
* the number of tickets is in relation to the period. The arithmetic is scaled
|
||||||
|
* by 1000 currently, so if ticket = 1 and period = 60, we get 1000/60 = 16. This
|
||||||
|
* should be 16.6667, which is an error of about 3.6%, which means we really just
|
||||||
|
* rate limit to 1 per 62 seconds.
|
||||||
|
*
|
||||||
* for (;;) {
|
* for (;;) {
|
||||||
* int fd = accept(..);
|
* int fd = accept(..);
|
||||||
* if (uc_ratelimit_allow(&r, time(NULL)) {
|
* if (uc_ratelimit_allow(&r, time(NULL)) {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#include "ucore/rate_limit.h"
|
#include "ucore/rate_limit.h"
|
||||||
|
|
||||||
#define SCALE_FACTOR 100
|
#define SCALE_FACTOR 1000
|
||||||
|
|
||||||
|
|
||||||
void uc_ratelimit_init(struct RateLimit *r, long tickets, long period, long current_ts)
|
void uc_ratelimit_init(struct RateLimit *r, long tickets, long period, long current_ts)
|
||||||
|
|||||||
Reference in New Issue
Block a user