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-5msautocannon -d 60 -c 50 http://127.0.0.1:3000/blocking-5msautocannon -d 60 -c 100 http://127.0.0.1:3000/blocking-5msx10 - x100 Non-blocking
autocannon -d 60 -c 10 http://127.0.0.1:3000/non-blocking-5msautocannon -d 60 -c 50 http://127.0.0.1:3000/non-blocking-5msautocannon -d 60 -c 100 http://127.0.0.1:3000/non-blocking-5msx10 - x100 Blocking
autocannon -d 60 -c 10 http://127.0.0.1:3000/blocking-25msautocannon -d 60 -c 50 http://127.0.0.1:3000/blocking-25msautocannon -d 60 -c 100 http://127.0.0.1:3000/blocking-25msx10 - x100 Non-blocking
autocannon -d 60 -c 10 http://127.0.0.1:3000/non-blocking-25msautocannon -d 60 -c 50 http://127.0.0.1:3000/non-blocking-25msautocannon -d 60 -c 100 http://127.0.0.1:3000/non-blocking-25msYou 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 warningstart service
docker start rediscopy env values
cp .env.example .envfor 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/blockingautocannon -d 60 -c 50 http://127.0.0.1:3000/redis/blockingautocannon -d 60 -c 100 http://127.0.0.1:3000/redis/blockingx10 - x100 Non-blocking
autocannon -d 60 -c 10 http://127.0.0.1:3000/redis/non-blockingautocannon -d 60 -c 50 http://127.0.0.1:3000/redis/non-blockingautocannon -d 60 -c 100 http://127.0.0.1:3000/redis/non-blocking