On Dec 8, 3:45 pm, Malte Ubl <
malte....@gmail.com> wrote:
> On Mon, Dec 7, 2009 at 4:47 PM, David <
david.sk...@gmail.com> wrote:
> > Thanks for the thoughts and info. I am proceeding down the use-child-
> > processes path (via process.createChildProcess() and then
> > communication over stdio). If/when I have some useful data, I'll post
> > some benchmarking numbers on the overhead of bouncing things through
> > the parent process.
>
> Hey,
>
> did you see my recent post regarding the Worker API. That might be a
> good starting point.
>
> Cheers
> Malte
Hi, Malte. Indeed I did (and it is a good starting point.)
Here are some initial and not excruciatingly scientific benchmarks:
Starting with
http://github.com/cramforce/node/blob/662e03b3861942cf0b8a890c7d9775b2ae6917ca/lib/worker.js,
I:
- commented out the calls to sys.error()
- added a few semicolons to make Emacs js2-mode happy
- used the following for my child.js:
===
//child.js
var worker = require('./worker').worker;
worker.onmessage = function (msg) {
worker.postMessage({
call: msg.call,
data: "Hello, World"
});
};
===
- Used server.js as posted at
http://pastebin.com/f7aa16f50 (except I
commented out the sys.puts() call inside the handler function passed
to createServer().
With this ultra-simple "Hello World" child, and 20 Worker processes,
"ab -n 500 -c 20 '
http://127.0.0.1:8000/'" (20 concurrent requests,
500 requests total) gives me about 195 requests/second, or a mean
request time of 102.670 millis.
This is on a Mac Pro with 2 dual-core 2.66GHz Xeon's running OS X
10.5.8 / Kernel 9.8.0.
In comparison, the following hello-world.js server:
===
var http = require('http');
var sys = require('sys');
http.createServer(function(req,res) {
res.sendHeader(200, {'Content-Type': 'text/plain'});
res.sendBody("Hello, World");
res.finish();
}).listen(8001);
sys.puts('Server running at
http://127.0.0.1:8001/');
===
does about 5416 requests/second with a mean request time of 3.692
millis. (using the same ApacheBench command.)
I got suspicious that the difference was about 100ms, the same as the
setTimeout() call in the WorkerCild to send the extra message
splitter.
So then I modified worker.js to use a 10ms timeout in postMessage for
WorkerChild and WorkerProcess and the ab numbers go to 1653 req/sec
with a mean of 12.093 millis per request.
Changing that timeout to 5ms brings it to 2195.51 req/sec and mean
9.110 millis per request. So, solving that flushing issue will
definitely help perf and bring down the overhead of using the Web
Worker API infrastructure.
David