Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vigneshshanmugam/node-inflight-requests
Measure the number of inflight requests at any given time in your Node.js server.
https://github.com/vigneshshanmugam/node-inflight-requests
congestion inflight nodejs requests
Last synced: 16 days ago
JSON representation
Measure the number of inflight requests at any given time in your Node.js server.
- Host: GitHub
- URL: https://github.com/vigneshshanmugam/node-inflight-requests
- Owner: vigneshshanmugam
- License: mit
- Created: 2019-06-19T15:33:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T17:52:35.000Z (about 2 years ago)
- Last Synced: 2024-12-08T12:07:37.419Z (28 days ago)
- Topics: congestion, inflight, nodejs, requests
- Language: JavaScript
- Homepage:
- Size: 48.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-inflight-requests
Measure the number of inflight requests at any given time in your Node.js server.
### Why?
When the application is under extreme load (DDOS) and lots of services are involved in serving the page requests, It becomes quite difficult to avoid the cascading service failures. As a result, the request queue grows so will latency until all the requests starts timing out and system will ultimately run our of memory and crash.
By analysing the concurrency(number of requests an application can service at any given time) limit of the application through performance and load testing, We can configure the fixed limit on the application level and reject the queued requests.
There are also other patterns like using eventloop as a tipping point for dropping requests. Combining both of these techniques, We can tune the application in much better way.
### Install
```
npm install node-inflight-requests
```### Usage
```js
const http = require("http");
const congestion = require("node-inflight-requests")();const server = http.createServer(serve);
function serve(req, res) {
const inflightReqs = congestion(res);console.log("No of requests in flight", inflightReqs);
reportMetrics(inflightReqs);
// 100 -denotes the limit the system can handle at any given time
if (inflightReqs > 100) {
res.statusCode = 503; // Service Unavailable
res.setHeader("Retry-After", 10);
}res.end();
}
```### License
The MIT License (MIT)
Copyright (c) 2019 [Vignesh Shanmugam](https://vigneshh.in)