Skip to content

Performance ​

What the middleware adds to a request, against no limiter and against Laravel's own throttle, each counting on the same Redis. Measured through the whole HTTP kernel, with 200 requests per case, twice (the full results).

Casep50p95Added at p50Redis callsDatabase queries
No limiter0.18–0.19 ms0.30–0.32 ms00
Laravel's throttle1.16–1.22 ms1.9–2.2 ms1.0 ms50
Laravel's throttle, with throttleWithRedis()0.74–0.80 ms1.2–1.4 ms0.55–0.6 ms20
Dynamic Throttle, 1 rule, Octane0.92–0.95 ms1.3–1.5 ms0.75 ms10
Dynamic Throttle, 1 rule, PHP-FPM with APCu0.98–0.99 ms1.5 ms0.8 ms10
Dynamic Throttle, 1 rule, PHP-FPM without APCu1.09–1.24 ms1.9 ms0.9–1.06 ms20
Dynamic Throttle, 100 rules, Octane1.03–1.04 ms1.6 ms0.85 ms10
Dynamic Throttle, 100 rules, PHP-FPM with APCu1.13–1.17 ms1.6–1.7 ms0.95–0.98 ms10
Dynamic Throttle, 100 rules, PHP-FPM without APCu1.77–1.82 ms2.5–2.8 ms1.6 ms20

The times run until the response is sent. With 100 rules, 3 match the request.

  • Against Laravel's throttle, a request costs a little less with Dynamic Throttle on Octane or PHP-FPM with APCu. throttleWithRedis() is cheaper still: Dynamic Throttle's one Redis call runs a longer script, and it matches the rules and hashes the client's identity first.
  • Enable APCu on PHP-FPM. Without it, each request also reads the rules from Redis: with 100 rules, that nearly doubles what the package adds (storage and runtimes).
  • After the response, Dynamic Throttle writes its telemetry in one more Redis call. The client doesn't wait for it on PHP-FPM, but the worker stays busy 0.5 to 0.6 ms longer. DYNAMIC_THROTTLE_TELEMETRY=false turns it off, and DYNAMIC_THROTTLE_SAMPLE_RATE records a share of requests.
  • No database queries, in any case: the rules are compiled into your cache (ADR-0007).
  • Your Redis is likely further away. Here it is local, about 0.15 ms per round trip. Across a network, each call costs more, so the number of calls counts: 5 for Laravel's throttle, 2 for throttleWithRedis(), and 1 for Dynamic Throttle, 2 on PHP-FPM without APCu.

The machine: a cloud VM with 4 vCPUs of an Intel Xeon at 2.10 GHz, shared with other tenants. PHP 8.4 with OPcache and APCu, phpredis 6.3, Laravel 13.33, and Redis 7.4 in Docker on the same machine. Your numbers will differ; the comparison between cases is what carries over.

Run it yourself ​

bash
docker compose up -d redis
vendor/bin/phpbench run benchmarks/Http/ComparisonBench.php --report=engine --dump-file=run.xml
php benchmarks/percentiles.php run.xml
php -d apc.enable_cli=1 benchmarks/round-trips.php

The first command takes about 20 minutes: each request runs in a process of its own, so the 200 per case give the spread of single requests (ADR-0016).

Released under the MIT License. An independent package, not affiliated with or endorsed by Laravel.