1

I'm building an HTTP Proxy in node.js. When the incoming request meets some conditions, a long running job is executed. When this happens, all the subsequent requests must wait for the job to end (due to the node's architecture):

function proxy(request, response) {
    if(isSpecial(request)) {
        // Long running job
    }
    // Proxy request
}

This is not good.
So let's say that the long running job can be implemented in Java, and for this purpose I build a Java server application that executes the long running job in a separate thread every time a request is made by the node application.

So, when the conditions are met, node.js makes a connection (TCP, HTTP, whatever) to the Java server. The Java server initializes a new Thread for the request, executes the long running job in this separate thread, and returns back, let's say, a JSON response (can be binary, whatever) that node can easily, asynchronously, handle:

var javaServer = initJavaServer(); // pseudo-code

function proxy(request, response) {
    var special = isSpecial(request);
    if (special) {
        var jobResponse;
        javaServer.request( ... );
        javaServer.addListener("data", function(chunk)) {
            // Read response
            // jobResponse = ...
        }
        javaServer.addListener("end", function(jobResult)) {
            doProxy(jobResponse, request, response);
        }
    } else {
        doProxy(null, request, response);
    }
}

In this way, I can execute long running jobs for those request that meet the conditions, without blocking the whole node application.

So here the requirements are:

  1. Speed
  2. Scalability of both apps (the node proxy runs on a cluster, and the Java app on another one)

Maybe a messaging broker service like RabbitMQ may help (node pushes messages, Java subscribes to them and pushes the response back).

Thoughts?

SheetJS
  • 22,470
  • 12
  • 65
  • 75
Mark
  • 67,098
  • 47
  • 117
  • 162
  • Take a look at this post from Dave Dopson: http://stackoverflow.com/questions/2387724/node-js-on-multi-core-machines. – shmuli Sep 24 '13 at 19:57

1 Answers1

0

Take a look at Q-Oper8 ( https://github.com/robtweed/Q-Oper8 ) which is designed to provide a native Node.js solution to situations such as this

Rob
  • 54
  • 1
  • How can this help me if the proxy cluter handles a lot of concurrent connections? I can't rely just on the machine's cores since they won't handle it all without a significant delay. It's not scalable. – Mark Sep 19 '11 at 18:20