Improve Response Time 10X by Introducing an Interceptor In NestJS

Overview

Improve response times 10x by introducing an interceptor in NestJS

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

Start the app

npm i

npm run start

Install load test tool

I used autocannon.

Load test commands

All load tests run for 60 second with variable concurrency levels: 10, 50 and 100.

Your results may very depending on your machine.

5ms delay on fake job

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

25ms delay on fake job

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

Redis - local and remote

You need to set up Redis conenction first.

Redis localhost

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

Load test

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
You might also like...

Create a html response with JSX.

Htm Create a text/html response with JSX, powered by Preact and UnoCSS. Usage To use Htm, create a server.tsx file like this: /** @jsx h */ import {

Dec 9, 2022

a vscode extension for http response data auto transform ts type.

a vscode extension for http response data auto transform ts type.

Api2ts 这是一个自动将 http 的响应数据转化为 ts 的类型,使用 json-to-ts 做的。 Features 框选配置项后,使用快捷键 alt+Q : 请求参数配置文件 在根目录下创建 Api2ts.config.json 文件,配置项如下: { "baseURL": "http

Jun 30, 2022

A jQuery plugin to submit forms with files via AJAX and to get a response with errors.

jquery-ajaxform A jQuery plugin to submit form with files via AJAX and to get a response with errors. Browsers without FormData uses iframe transport

Mar 30, 2021

Modify Request & Response Headers Chrome Extension (Manifest V3)

Modify Request & Response Headers Chrome Extension (Manifest V3)

Modify request & response headers (Chrome Extension Manifest V3) This Chrome extension will add request header and response header to few network requ

Dec 9, 2022

Open Source projects are a project to improve your JavaScript knowledge with JavaScript documentation, design patterns, books, playlists.

Open Source projects are a project to improve your JavaScript knowledge with JavaScript documentation, design patterns, books, playlists.

It is a project I am trying to list the repos that have received thousands of stars on Github and deemed useful by the JavaScript community. It's a gi

Aug 14, 2022

A VS Code extension to practice and improve your typing speed right inside your code editor. Practice with simple words or code snippets.

A VS Code extension to practice and improve your typing speed right inside your code editor. Practice with simple words or code snippets.

Warm Up 🔥 👨‍💻 A VS Code extension to practice and improve your typing speed right inside your code editor. Practice with simple words or code snipp

Dec 12, 2022

This Plugin adds shortcodes with various prewritten phrases to improve quality and productivity of your writing.

Obsidian Phrasebank This Plugin adds shortcodes with various prewritten phrases to improve quality and productivity of your writing. Example :intro_pr

Jan 1, 2023

Tools to help you improve performance of your Vue application.

Tools to help you improve performance of your Vue application.

Why did you update Tools to help you improve performance of your Vue application. Usage If we want to know how many times that (one of or all of) watc

Nov 3, 2022
Comments
  • Bump qs and formidable

    Bump qs and formidable

    Bumps qs and formidable. These dependencies needed to be updated together. Updates qs from 6.9.3 to 6.10.3

    Changelog

    Sourced from qs's changelog.

    6.10.3

    • [Fix] parse: ignore __proto__ keys (#428)
    • [Robustness] stringify: avoid relying on a global undefined (#427)
    • [actions] reuse common workflows
    • [Dev Deps] update eslint, @ljharb/eslint-config, object-inspect, tape

    6.10.2

    • [Fix] stringify: actually fix cyclic references (#426)
    • [Fix] stringify: avoid encoding arrayformat comma when encodeValuesOnly = true (#424)
    • [readme] remove travis badge; add github actions/codecov badges; update URLs
    • [Docs] add note and links for coercing primitive values (#408)
    • [actions] update codecov uploader
    • [actions] update workflows
    • [Tests] clean up stringify tests slightly
    • [Dev Deps] update eslint, @ljharb/eslint-config, aud, object-inspect, safe-publish-latest, tape

    6.10.1

    • [Fix] stringify: avoid exception on repeated object values (#402)

    6.10.0

    • [New] stringify: throw on cycles, instead of an infinite loop (#395, #394, #393)
    • [New] parse: add allowSparse option for collapsing arrays with missing indices (#312)
    • [meta] fix README.md (#399)
    • [meta] only run npm run dist in publish, not install
    • [Dev Deps] update eslint, @ljharb/eslint-config, aud, has-symbols, tape
    • [Tests] fix tests on node v0.6
    • [Tests] use ljharb/actions/node/install instead of ljharb/actions/node/run
    • [Tests] Revert "[meta] ignore eclint transitive audit warning"

    6.9.7

    • [Fix] parse: ignore __proto__ keys (#428)
    • [Fix] stringify: avoid encoding arrayformat comma when encodeValuesOnly = true (#424)
    • [Robustness] stringify: avoid relying on a global undefined (#427)
    • [readme] remove travis badge; add github actions/codecov badges; update URLs
    • [Docs] add note and links for coercing primitive values (#408)
    • [Tests] clean up stringify tests slightly
    • [meta] fix README.md (#399)
    • Revert "[meta] ignore eclint transitive audit warning"
    • [actions] backport actions from main
    • [Dev Deps] backport updates from main

    6.9.6

    • [Fix] restore dist dir; mistakenly removed in d4f6c32

    6.9.5

    • [Fix] stringify: do not encode parens for RFC1738
    • [Fix] stringify: fix arrayFormat comma with empty array/objects (#350)
    • [Refactor] format: remove util.assign call
    • [meta] add "Allow Edits" workflow; update rebase workflow
    • [actions] switch Automatic Rebase workflow to pull_request_target event

    ... (truncated)

    Commits
    • f92ddb5 v6.10.3
    • d9e9529 [Dev Deps] update eslint
    • 8b4cc14 [Fix] parse: ignore __proto__ keys
    • ad63d36 [actions] reuse common workflows
    • c028385 [Dev Deps] update eslint, @ljharb/eslint-config, object-inspect, tape
    • 0a1d3e8 [Robustness] stringify: avoid relying on a global undefined
    • 408ff95 v6.10.2
    • 3cea04d [Dev Deps] update @ljharb/eslint-config
    • 28fba8f [Dev Deps] update eslint, @ljharb/eslint-config, tape
    • 9aee773 [Fix] stringify: actually fix cyclic references
    • Additional commits viewable in compare view

    Updates formidable from 2.0.1 to 2.1.1

    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Owner
Dmitry Khorev
Software Engineer, IT consulting
Dmitry Khorev
A set of utilities and additional features for my creative coding class aiming to help students while introducing the algorithmic thinking.

p5.utils A set of utilities and additional features for my creative coding class aiming to help students while introducing the algorithmic thinking. T

alp tuğan 15 Dec 25, 2022
Angular JWT refresh token with Interceptor, handle token expiration in Angular 14 - Refresh token before expiration example

Angular 14 JWT Refresh Token example with Http Interceptor Implementing Angular 14 Refresh Token before Expiration with Http Interceptor and JWT. You

null 8 Nov 30, 2022
An interceptor to validate and decode Pub/Sub push messages for endpoints

NestJS GCP Pub/Sub Interceptor Provides an Interceptor for NestJS to automagically validate and unwrap HTTP push messages from Google Cloud Platform's

Hiphops 3 Dec 15, 2022
Uptime monitoring RESTful API server that allows authenticated users to monitor URLs, and get detailed uptime reports about their availability, average response time, and total uptime/downtime.

Uptime Monitoring API Uptime monitoring RESTful API server that allows authenticated users to monitor URLs, and get detailed uptime reports about thei

Mohamed Magdi 2 Jun 14, 2022
Pfapi plugin uses local and redis caches to achieve single digit milliseconds on average api response time.

Strapi plugin pfapi Pfapi plugin provides configurable, secure and fast API services. APIs are configurable through the admin panel with components an

null 5 Sep 17, 2022
A fast and powerful http toolkit that take a list of domains to find active domains and other information such as status-code, title, response-time , server, content-type and many other

HTTPFY curently in beta so you may see problems. Please open a Issue on GitHub and report them! A Incredible fast and Powerful HTTP toolkit Report Bug

DevXprite 44 Dec 22, 2022
A tool to check for response status codes with ease

About Archer Archer is an cross-platform tool developed using Nodejs which focuses on the reconnaissance phase of a penetration test. Got a bunch of l

Umair 14 Oct 19, 2022
Ping.js is a small and simple Javascript library for the browser to "ping" response times to web servers in Javascript

Ping.js Ping.js is a small and simple Javascript library for the browser to "ping" response times to web servers in Javascript! This is useful for whe

Alfred Gutierrez 353 Dec 27, 2022
Room impulse response measurement in the browser.

Room impulse response measurement - in the browser! Check it out on danielrudrich.github.io/Broom. Behind the scenes Broom uses the WebAudioAPI to pla

Daniel Rudrich 47 Sep 13, 2022
A plugin for Strapi Headless CMS that provides the ability to transform the API request or response.

strapi-plugin-transformer A plugin for Strapi that provides the ability to transform the API request and/or response. Requirements The installation re

daedalus 71 Jan 6, 2023