File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 53
53
run : cd benchmarks/api-discovery && node benchmark.js
54
54
- name : Run Express Benchmark
55
55
run : cd benchmarks/express && node benchmark.js
56
+ - name : Check Rate Limiter memory usage
57
+ run : cd benchmarks/rate-limiting && node --expose-gc memory.js
Original file line number Diff line number Diff line change
1
+ const { RateLimiter } = require ( "../../build/ratelimiting/RateLimiter" ) ;
2
+
3
+ const ttl = 60000 ; // 1 minute in milliseconds
4
+ const keyCount = 1_000_000 ;
5
+
6
+ ( async ( ) => {
7
+ const keys = Array . from ( { length : keyCount } , ( _ , i ) => `user${ i } ` ) ;
8
+ const limiter = new RateLimiter ( 100_000_000 , ttl ) ;
9
+
10
+ // Warmup, block all keys
11
+ for ( const key of keys ) {
12
+ limiter . isAllowed ( key , ttl , 2 ) ;
13
+ limiter . isAllowed ( key , ttl , 2 ) ;
14
+ }
15
+
16
+ global . gc ( ) ;
17
+
18
+ const heapUsedBefore = process . memoryUsage ( ) . heapUsed ;
19
+
20
+ for ( const key of keys ) {
21
+ limiter . isAllowed ( key , ttl , 2 ) ;
22
+ }
23
+
24
+ global . gc ( ) ;
25
+
26
+ const heapUsedAfter = process . memoryUsage ( ) . heapUsed ;
27
+ const heapUsedDiff = heapUsedAfter - heapUsedBefore ;
28
+
29
+ if ( heapUsedDiff > 0 ) {
30
+ console . error (
31
+ `Higher heap usage after rate limiting: +${ heapUsedDiff } bytes`
32
+ ) ;
33
+ process . exit ( 1 ) ;
34
+ }
35
+
36
+ console . info ( `No memory leak detected` ) ;
37
+ process . exit ( 0 ) ;
38
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments