This sample project demonstrates the usage of interceptors for improving response times and thorouhput of NestJS apps.
See the full article and benchmark results here: https://medium.com/@dkhorev/improve-response-time-10x-by-introducing-an-interceptor-in-nestjs-590695692360
npm i
npm run start
I used autocannon.
All load tests run for 60 second with variable concurrency levels: 10, 50 and 100.
Your results may very depending on your machine.
x10 - x100 Blocking
autocannon -d 60 -c 10 http://127.0.0.1:3000/blocking-5ms
autocannon -d 60 -c 50 http://127.0.0.1:3000/blocking-5ms
autocannon -d 60 -c 100 http://127.0.0.1:3000/blocking-5ms
x10 - x100 Non-blocking
autocannon -d 60 -c 10 http://127.0.0.1:3000/non-blocking-5ms
autocannon -d 60 -c 50 http://127.0.0.1:3000/non-blocking-5ms
autocannon -d 60 -c 100 http://127.0.0.1:3000/non-blocking-5ms
x10 - x100 Blocking
autocannon -d 60 -c 10 http://127.0.0.1:3000/blocking-25ms
autocannon -d 60 -c 50 http://127.0.0.1:3000/blocking-25ms
autocannon -d 60 -c 100 http://127.0.0.1:3000/blocking-25ms
x10 - x100 Non-blocking
autocannon -d 60 -c 10 http://127.0.0.1:3000/non-blocking-25ms
autocannon -d 60 -c 50 http://127.0.0.1:3000/non-blocking-25ms
autocannon -d 60 -c 100 http://127.0.0.1:3000/non-blocking-25ms
You need to set up Redis conenction first.
first run redis with persistence
docker run -p 6379:6379 --name redis -d redis --save 60 1 --loglevel warning
start service
docker start redis
copy env values
cp .env.example .env
for default Redis container keep everything as is
for custom Redis connection replace the values in .env
x10 - x100 Blocking
autocannon -d 60 -c 10 http://127.0.0.1:3000/redis/blocking
autocannon -d 60 -c 50 http://127.0.0.1:3000/redis/blocking
autocannon -d 60 -c 100 http://127.0.0.1:3000/redis/blocking
x10 - x100 Non-blocking
autocannon -d 60 -c 10 http://127.0.0.1:3000/redis/non-blocking
autocannon -d 60 -c 50 http://127.0.0.1:3000/redis/non-blocking
autocannon -d 60 -c 100 http://127.0.0.1:3000/redis/non-blocking