-
Notifications
You must be signed in to change notification settings - Fork 48
Closed
Description
When running a http server with throng, the backlog value is not respected. I'm not really sure why. This parameter is very useful if you have multiple concurrent connections and you want to limit how many are processed at the same time. Is this the expected behavior?
This is a minimum example that illustrates this issue:
const http = require('http'),
throng = require('throng');
// ================================================
let useThrong = true;
// ================================================
let n = 0;
const server = http.createServer(async (req, res) => {
let ln = ++n;
console.log(`[${new Date().getSeconds()}] Received request ${ln}`);
setTimeout(() => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end(`Pong ${ln}\n`);
console.log(`[${new Date().getSeconds()}] Sent response ${ln}`);
}, 1000)
});
if (useThrong) {
throng({
workers: 1
}, (id) => {
server.listen(3000, '0.0.0.0', 3, () => {
console.log(`Server ${id} running`);
});
});
} else {
server.listen(3000, '0.0.0.0', 3, () => {
console.log(`Server running`);
});
}Without throng, 10 concurrent requests:
Server running
[4] Received request 1
[5] Sent response 1
[5] Received request 2
[5] Received request 3
[5] Received request 4
[5] Received request 5
[6] Sent response 2
[6] Sent response 3
[6] Sent response 4
[6] Sent response 5
[6] Received request 6
[6] Received request 7
[6] Received request 8
[6] Received request 9
[6] Received request 10
[7] Sent response 6
[7] Sent response 7
[7] Sent response 8
[7] Sent response 9
[7] Sent response 10
With throng:
Server 1 running
[4] Received request 1
[5] Sent response 1
[5] Received request 2
[5] Received request 3
[5] Received request 4
[5] Received request 5
[5] Received request 6
[5] Received request 7
[5] Received request 8
[5] Received request 9
[5] Received request 10
[6] Sent response 2
[6] Sent response 3
[6] Sent response 4
[6] Sent response 5
[6] Sent response 6
[6] Sent response 7
[6] Sent response 8
[6] Sent response 9
[6] Sent response 10
Metadata
Metadata
Assignees
Labels
No labels