Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backlog not respected when using throng #28

Closed
cesarizu opened this issue Jun 26, 2019 · 1 comment
Closed

Backlog not respected when using throng #28

cesarizu opened this issue Jun 26, 2019 · 1 comment

Comments

@cesarizu
Copy link

cesarizu commented Jun 26, 2019

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
@hunterloftis
Copy link
Owner

This is an issue with node's cluster module. You can track progress on it at nodejs/node#33827.

I would encourage you to run some tests to ensure that backlog is doing what you think it's doing. My understanding is that backlog limits the maximum pending connection queue depth - not that it limits the level of concurrency of your http handlers, as you described. I could be wrong, though, as it isn't something I've tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants