Commit 6b517ff
committed
fix(rate-limiter): address review findings across engine, tests, and benchmarks
Correctness:
- Fix sliding window member collision in multi-process Redis by including
PID in sorted-set member string (redis_backend.rs)
- Reject zero-count rate strings in Python _parse_rate() to match Rust (rate_limiter.py)
- Fix allow_many() returning fewer results than input checks (rate_limiter.py)
- Guard sub-second window_nanos producing reset_timestamp == now (memory.rs)
- Fix EvalDimension docstring incorrectly describing EvalResult (types.rs)
- Deduplicate from_dims empty case via unlimited(0) (types.rs)
Performance:
- Add EVALSHA caching with NOSCRIPT fallback to Rust Redis backend,
matching the Python _ensure_scripts_loaded/_evalsha pattern (redis_backend.rs)
- Cache parsed rate strings in Python MemoryBackend to avoid per-request
_parse_rate() overhead (rate_limiter.py)
- Fix Criterion benchmarks to advance clock between iterations so they
measure steady-state under-limit path, not blocked path (benches/rate_limiter.rs)
Tests:
- Add TokenBucketAlgorithm.sweep() eviction tests
- Add _extract_user_identity dict fallback chain tests (email/id/sub)
- Add prompt_pre_fetch Rust async Redis path coverage
- Remove unused jwt_token_alice/jwt_token_bob fixtures from integration tests
- Fix time.sleep() -> asyncio.sleep() in async integration tests
Load tests and Makefile:
- Fix response misclassification: HTTP 429 now classified as [rate-limited]
instead of [infra-error] in backend correctness and scale load tests
- Use HTTP 429 as primary signal in capacity test, keep 422 string match
as secondary fallback
- Add missing RL_REQS_PER_SECOND and RL_PROMPT_ID Makefile defaults
- Fix misleading "500 users" comment to reflect actual default of 100
Signed-off-by: Pratik Gandhi <gandhipratik203@gmail.com>1 parent 28a4eb8 commit 6b517ff
11 files changed
Lines changed: 304 additions & 111 deletions
File tree
- plugins_rust/rate_limiter
- benches
- src
- plugins/rate_limiter
- tests
- integration
- loadtest
- unit/mcpgateway/plugins/plugins/rate_limiter
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2326 | 2326 | | |
2327 | 2327 | | |
2328 | 2328 | | |
| 2329 | + | |
| 2330 | + | |
2329 | 2331 | | |
2330 | 2332 | | |
2331 | 2333 | | |
| |||
2446 | 2448 | | |
2447 | 2449 | | |
2448 | 2450 | | |
2449 | | - | |
| 2451 | + | |
2450 | 2452 | | |
2451 | 2453 | | |
2452 | 2454 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
| 122 | + | |
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
| |||
449 | 451 | | |
450 | 452 | | |
451 | 453 | | |
| 454 | + | |
452 | 455 | | |
453 | 456 | | |
454 | 457 | | |
| |||
470 | 473 | | |
471 | 474 | | |
472 | 475 | | |
473 | | - | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
474 | 481 | | |
475 | 482 | | |
476 | 483 | | |
| |||
826 | 833 | | |
827 | 834 | | |
828 | 835 | | |
829 | | - | |
830 | | - | |
831 | | - | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
832 | 840 | | |
| 841 | + | |
833 | 842 | | |
834 | 843 | | |
835 | 844 | | |
836 | 845 | | |
837 | 846 | | |
838 | 847 | | |
839 | 848 | | |
840 | | - | |
841 | | - | |
842 | | - | |
843 | | - | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
844 | 854 | | |
845 | 855 | | |
846 | 856 | | |
847 | 857 | | |
848 | | - | |
849 | | - | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
850 | 867 | | |
851 | 868 | | |
852 | 869 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
6 | 11 | | |
7 | 12 | | |
8 | 13 | | |
9 | 14 | | |
10 | 15 | | |
11 | 16 | | |
12 | | - | |
| 17 | + | |
13 | 18 | | |
14 | 19 | | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
18 | | - | |
| 23 | + | |
| 24 | + | |
19 | 25 | | |
20 | | - | |
21 | | - | |
| 26 | + | |
| 27 | + | |
22 | 28 | | |
23 | | - | |
| 29 | + | |
24 | 30 | | |
25 | 31 | | |
26 | 32 | | |
27 | 33 | | |
28 | | - | |
| 34 | + | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
32 | | - | |
| 38 | + | |
33 | 39 | | |
34 | 40 | | |
| 41 | + | |
| 42 | + | |
35 | 43 | | |
36 | 44 | | |
37 | | - | |
38 | | - | |
| 45 | + | |
| 46 | + | |
39 | 47 | | |
40 | 48 | | |
41 | 49 | | |
42 | 50 | | |
43 | 51 | | |
44 | 52 | | |
45 | 53 | | |
46 | | - | |
| 54 | + | |
47 | 55 | | |
48 | 56 | | |
| 57 | + | |
49 | 58 | | |
50 | 59 | | |
51 | | - | |
52 | | - | |
| 60 | + | |
| 61 | + | |
53 | 62 | | |
54 | 63 | | |
55 | 64 | | |
56 | 65 | | |
57 | 66 | | |
58 | 67 | | |
59 | 68 | | |
60 | | - | |
| 69 | + | |
61 | 70 | | |
62 | 71 | | |
| 72 | + | |
63 | 73 | | |
64 | 74 | | |
65 | | - | |
66 | | - | |
| 75 | + | |
| 76 | + | |
67 | 77 | | |
68 | 78 | | |
69 | 79 | | |
70 | 80 | | |
71 | 81 | | |
72 | 82 | | |
73 | 83 | | |
74 | | - | |
| 84 | + | |
75 | 85 | | |
76 | 86 | | |
| 87 | + | |
77 | 88 | | |
78 | 89 | | |
79 | 90 | | |
80 | | - | |
81 | | - | |
82 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
83 | 94 | | |
84 | | - | |
| 95 | + | |
85 | 96 | | |
86 | 97 | | |
87 | 98 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
210 | 213 | | |
211 | 214 | | |
212 | 215 | | |
| |||
0 commit comments