NNB - Node native stress testing benchmark

In the last days of 2015 I released nnb - native Node.js addon for stress testing

Processes vs threads

There is no sufficient difference between them, accept shared memory and more expensive processes spawning. But we can make processes once in advance. And now we need a communication channel between them. Let’s see what we have:

  • Signals

Fast and universal (supports by almost every platform) one. But the problem is that originaly signals were created for another purposes. That’s not a channel for data transferring.

  • Sockets

That’s exactly how Node.js Cluster implemented. process.send method calls sending data to another process by TCP. What does it mean for us? That means a new descriptor for every new request, a lot of I/O and idle CPU.

There are some other communication methods, but anyway they are all not crossplatform ones or depend on I/O.
Now let’s see at the system performance, while creating 100 processes:

and 100 threads:

Obviously, now CPU is only busy with supporting communication between these simple processes (everyone must perform only one request, otherwise V8 will put them into the event lopp queue)

But Node has only one thread. How to reach high performance?

The solution is a native C++ addon, with using POSIX multithreading. You can think of it as ab tool, which takes concurency as input and output result of all requests performed simultaneously.
Rather than ab we can do whatever we want, using all js functionality:

1
2
3
4
5
[ { time: 80,
body: '<!doctype html><html itemscope=...',
headers: 'HTTP/1.1 200 OK\r\nDate: Mon, 28 Dec 2015 10:37:35 GMT\r\nConnection: close\r\n\r\n' },
....
]

It supports additional headers, POST payload, but that’s POSIX, so your OS should support it. Sometimes it needs to read from remote socket only headers, so you can use headersOnly options for it. Please check out other options: https://github.com/yarax/nnb

You can gain performance up to ab does.