Cluster process blocking in Node.js/Express application

Outoluku

I am working on a Node.js application using Express framework and I use cluster to handle load. In testing I notice that if for some reason one of the processes is taking a long time to load, it affect other subsequent requests too. I made a simple test case for this:

https://gist.github.com/anonymous/7325816

running the example with "node app.js" and trying to load http://localhost:8080/slow (which has a blocking calculation taking several seconds) in one browser window and http://localhost:8080/fast immediately in another window, the latter also takes several seconds to load.

If I understand correctly, this is because the same process which is running the calculation is trying to process the new request: but how to avoid this?

Edit:

Here is output of HTTP requests running Siege after running /slow:

HTTP/1.1 200   0.01 secs:      89 bytes ==> GET  /fast
HTTP/1.1 200   6.32 secs:      89 bytes ==> GET  /fast
HTTP/1.1 200   0.01 secs:      89 bytes ==> GET  /fast
HTTP/1.1 200   6.84 secs:      89 bytes ==> GET  /fast
HTTP/1.1 200   0.00 secs:      89 bytes ==> GET  /fast
HTTP/1.1 200   7.41 secs:      89 bytes ==> GET  /fast
HTTP/1.1 200   0.00 secs:      89 bytes ==> GET  /fast
HTTP/1.1 200   9.04 secs:      89 bytes ==> GET  /fast

Edit 2:

Problem was with the latest Git version (v0.11.9-pre) of Node.js running on OSX: running current release v0.10.21 it works fine without transferring requests to the blocked process. Thanks @goten for the suggestion!

goten

If you have several CPU cores cluster should run several process. It's pretty well explain there http://rowanmanning.com/posts/node-cluster-and-express/

var http = require('http');
var cluster = require('cluster');
var express = require('express');

if(cluster.isMaster){
    //count the CPU
    var cpuCount = require('os').cpus().length;

    // Create a worker for each CPU
    for (var i = 0; i < cpuCount; i += 1) {
        cluster.fork();
    }
}
else{
    var app = express();
    var server = http.createServer(app);

    app.get('/slow', function(req, res){
        someSlowFunction();
    });
    app.get('/fast', function(req, res){
        someFasterFunction();
    });

    server.listen(3000);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Blocking function in node.js application

From Dev

Reactive IP-Blocking in Nodejs, Node application security

From Dev

Why use child_process instead of cluster in Node?

From Dev

Node.js Cluster to Process Data as Often As Possible

From Dev

How does master node start all the process in a hadoop cluster?

From Dev

Single process blocking queue

From Dev

Blocking process in storm spout

From Dev

lvmetad is blocking boot process

From Dev

lvmetad is blocking boot process

From Dev

Single process blocking queue

From Dev

Python Twisted TCP application - How to prevent incoming message loss by blocking process

From Dev

flink 1.12.1 example application failing on a single node yarn cluster

From Java

Node.js app can't run on port 80 even though there's no other process blocking the port

From Dev

Node.js process.nextTick still blocking server from getting requests

From Dev

Itune Application sharing blocking

From Dev

Blocking issue in Express / Node

From Dev

Should I consider a bad practice doing blocking I/O during the application bootstrap? (node.js)

From Dev

Writting to a Node WebSocket is blocking or non-blocking?

From Dev

Writting to a Node WebSocket is blocking or non-blocking?

From Dev

Publish to redis is blocking my process

From Dev

Boolean output blocking the whole process

From Dev

Write system call and blocking the process

From Dev

Publish to redis is blocking my process

From Dev

How can a process be blocking another process (that it spawned)?

From Dev

'exit'-Event in worker process when killed from master within a node.js cluster

From Dev

Can I use child process or cluster to do custom function calls in node?

From Dev

Delphi: FireDac Connection blocking the application

From Dev

Delphi: FireDac Connection blocking the application

From Dev

Having trouble with port application blocking

Related Related

  1. 1

    Blocking function in node.js application

  2. 2

    Reactive IP-Blocking in Nodejs, Node application security

  3. 3

    Why use child_process instead of cluster in Node?

  4. 4

    Node.js Cluster to Process Data as Often As Possible

  5. 5

    How does master node start all the process in a hadoop cluster?

  6. 6

    Single process blocking queue

  7. 7

    Blocking process in storm spout

  8. 8

    lvmetad is blocking boot process

  9. 9

    lvmetad is blocking boot process

  10. 10

    Single process blocking queue

  11. 11

    Python Twisted TCP application - How to prevent incoming message loss by blocking process

  12. 12

    flink 1.12.1 example application failing on a single node yarn cluster

  13. 13

    Node.js app can't run on port 80 even though there's no other process blocking the port

  14. 14

    Node.js process.nextTick still blocking server from getting requests

  15. 15

    Itune Application sharing blocking

  16. 16

    Blocking issue in Express / Node

  17. 17

    Should I consider a bad practice doing blocking I/O during the application bootstrap? (node.js)

  18. 18

    Writting to a Node WebSocket is blocking or non-blocking?

  19. 19

    Writting to a Node WebSocket is blocking or non-blocking?

  20. 20

    Publish to redis is blocking my process

  21. 21

    Boolean output blocking the whole process

  22. 22

    Write system call and blocking the process

  23. 23

    Publish to redis is blocking my process

  24. 24

    How can a process be blocking another process (that it spawned)?

  25. 25

    'exit'-Event in worker process when killed from master within a node.js cluster

  26. 26

    Can I use child process or cluster to do custom function calls in node?

  27. 27

    Delphi: FireDac Connection blocking the application

  28. 28

    Delphi: FireDac Connection blocking the application

  29. 29

    Having trouble with port application blocking

HotTag

Archive