News for hackers. Stuff that matters.
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by mrb on Wednesday October 13, 2010 @03:35AM (#1786435)
His fastest "node.js+net" case is not optimal. I could easily come up with an even faster implementation by using Buffers instead of strings by not calling setEncoding(), which makes it 30% faster on my machine. This should translate to about 37500 queries/sec on his machine:

  var net = require('net');
  var server = net.createServer(function (stream) {
   stream.on('connect', function () {});
   stream.on('data', function (data) {
      var l = data.length;
      if (l >= 4 && data[l - 4] == 0xd && data [l - 3] == 0xa && data[l - 2] == 0xd && data[l - 1] == 0xa) {
       stream.write('HTTP/1.0 200 OK\r\nConnection: Keep-Alive\r\nContent-Type: text/html\r\nContent-Length: 13\r\n\r\nHello World\r\n');
     }
   });
   stream.on('end', function () {stream.end();});
  });
  server.listen(8124, 'localhost');
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by mrb on Wednesday October 13, 2010 @03:57AM (#1786472)
And this other version that doesn't check for "\r\n\r\n" is 47% faster than his "node.js+net" case. This should translate to about 42000 queries/sec on his machine:

  var net = require('net');
  var server = net.createServer(function (stream) {
   stream.on('connect', function () {});
   stream.on('data', function (data) {
       stream.write('HTTP/1.0 200 OK\r\nConnection: Keep-Alive\r\nContent-Type: text/html\r\nContent-Length: 13\r\n\r\nHello World\r\n');
   });
   stream.on('end', function () {stream.end();});
  });
  server.listen(8124, 'localhost');
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by kurokikaze on Wednesday October 13, 2010 @04:27AM (#1786527)
Why empty callback on 'connect'? It will go to event loop for every client, and yet do nothing of value.
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by mrb on Wednesday October 13, 2010 @04:33AM (#1786536)
Good point. I inherited this design flaw from the snippet he posted on his blog.
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by simonhf on Friday October 15, 2010 @01:09PM (#1795314)
mrb, please note that the connections per second and queries per second are handled individually in the benchmark. So the connect handler should make no difference to the queries per second.
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by simonhf on Friday October 15, 2010 @01:14PM (#1795326)
mrb, thanks for the optimized version of the 'node.js+net' script. But what is difference with the original script? I copy and pasted your script and the queries per second result remains unchanged... so where does the 47% faster come from?
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by mrb on Sunday October 17, 2010 @07:27AM (#1800115)
The difference with the original script is, as I said, that mine does NOT call setEncoding (if you call setEncoding, node will decode Buffers to strings, thereby wasting CPU time). My 47% faster number comes from benchmarking node.js+net against my optimized version (both on my machine).
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by simonhf on Sunday October 17, 2010 @11:38AM (#1800549)
Hmmm... I'm confused because my node.js+net script also doesn't call setEncoding() and looks the same as your node.js+net script. The node.js+net+crcr script of yours is a nice optimization though on my test box it reaches 23,224 queries per second.

We are getting closer to open sourcing SXELua :-) It would be great if we could think up a better benchmark then the "Hello World" benchmark :-) What do you think about the suggestion described higher up in this thread?

Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by mrb on Sunday October 17, 2010 @03:34PM (#1801172)
I see. I must have gotten confused somewhere then. node.js+net+crcr was calling setEncoding, but you are indeed not calling setEncoding in node.js+net...

I think the ideal is a bunch of little synthetic benchmarks, similar to the Hello World, plus a handful of real-world examples like the one checking a password. You want something that stresses the CPU / RAM (not network), since that's where the interesting differences are between these scripting environments.

Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by simonhf on Sunday October 17, 2010 @05:56PM (#1801549)
Sounds good. How many lines of code do you think the password check test would be in node.js? If it's not too long then could you imagine doing the node.js version?
Re:Node.js Versus LUA "Hello World" HTTP Server Showdown by simonhf on Friday October 15, 2010 @01:08PM (#1795312)
mrb, thanks for the optimized node.js code. I re-ran the benchmark and the queries per second increased to 23,224 queries per second... so I agree with the 30% faster but not your queries per second estimate (which math did you do? ~ 18k * 130% = ~ 23k or?). I will update the blog later to reflect this.