Strange bug in benchmark, Express.js is slower than Ruby on Rails

729 views
Skip to first unread message

Alexey Petrushin

unread,
Jan 23, 2014, 4:57:58 AM1/23/14
to nod...@googlegroups.com
I ran a benchmark for Ruby on Rails and Express.js using `siege` - and Express for some reason performed worse than Rails.

How benchmark works - application query some text from remote HTTP service (service delays each
request for 200ms) and render HTML page using that text.

Results

- transactions rate are the same (already strange, I expected node.js to outperform rails by at least a couple of times)
- average response time in rails is 0.8s and in express 4s (siege doesn't show average time it in the report, but it can be seen from its logs).

Details




Siege command `siege -b -t10s -c100 http://localhost:3000`

All application has been run in production mode.

How is that possible and where is the bug in this benchmark, what's I'm doing wrong?

Fedor Indutny

unread,
Jan 23, 2014, 5:15:19 AM1/23/14
to nod...@googlegroups.com
I think you could be hitting this:
http://nodejs.org/api/http.html#http_agent_maxsockets
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nodejs+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Matt

unread,
Jan 23, 2014, 9:17:56 AM1/23/14
to nod...@googlegroups.com
Also important that your node code is only using one CPU. See http://nodejs.org/docs/v0.10.22/api/cluster.html

Alexey Petrushin

unread,
Jan 23, 2014, 9:33:28 AM1/23/14
to nod...@googlegroups.com
Single core shouldn't be a problem as far as I know ruby also uses only one CPU it doesn't have real threads.
You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/tgATyqF-HIc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.


--
Best regards, Alex.

Matt

unread,
Jan 23, 2014, 9:47:53 AM1/23/14
to nod...@googlegroups.com

On Thu, Jan 23, 2014 at 9:33 AM, Alexey Petrushin <alexey.p...@gmail.com> wrote:
Single core shouldn't be a problem as far as I know ruby also uses only one CPU it doesn't have real threads.

Apparently for Puma this changes if you're running under Rubinius or JRuby.

But I strongly suggest looking into what Fedor suggested.

Alexey Petrushin

unread,
Jan 23, 2014, 10:19:06 AM1/23/14
to nod...@googlegroups.com, fe...@indutny.com
Fedor, you are right, thanks. That was the problem, after fixing it node became more than 10 times faster.

Issue resolved.

Fedor Indutny

unread,
Jan 23, 2014, 10:21:30 AM1/23/14
to Alexey Petrushin, nod...@googlegroups.com
You are welcome!

On Thu, Jan 23, 2014 at 7:19 PM, Alexey Petrushin

Reza Razavipour

unread,
Jan 23, 2014, 11:35:18 AM1/23/14
to nod...@googlegroups.com, fe...@indutny.com
what was the fix? You changed the 5 to what?

Alexey Petrushin

unread,
Jan 23, 2014, 12:37:44 PM1/23/14
to nod...@googlegroups.com, fe...@indutny.com

tjholowaychuk

unread,
Jan 23, 2014, 10:33:59 PM1/23/14
to nod...@googlegroups.com
plus this benchmark doesn't really test express, it tests outbound requests AND express :p so that's really misleading 

Alexey Petrushin

unread,
Jan 24, 2014, 2:25:15 AM1/24/14
to nod...@googlegroups.com
Yes, but I wanted to see a test that more or less close to what's used in real projects. Express usually don't work in isolation, usually it uses some sort of database. And request seems like a good approximation for DB connection.

Paul Vencill

unread,
Jan 24, 2014, 9:36:32 AM1/24/14
to nod...@googlegroups.com, fe...@indutny.com
I didn't know about this either, good info.  Is there a good method for determining what the optimum # max connections should be? I assume there's some practical limit, or way of figuring out the point of diminishing returns for a given app?  for example, if you open up (as the OP did) 1000 concurrent connections, but your db connection pool is only 10, then you're probably going to run into issues.  Other than dependencies like that, any good rubrics y'all can think of?

Stefan Klein

unread,
Jan 24, 2014, 9:58:10 AM1/24/14
to nod...@googlegroups.com



2014/1/24 Paul Vencill <paul.v...@gmail.com>

I didn't know about this either, good info.  Is there a good method for determining what the optimum # max connections should be? I assume there's some practical limit, or way of figuring out the point of diminishing returns for a given app?  for example, if you open up (as the OP did) 1000 concurrent connections, but your db connection pool is only 10, then you're probably going to run into issues.  Other than dependencies like that, any good rubrics y'all can think of?

I think this will be absolutely app specific.
For your example, it could be fine to have 1000 concurrent connections (maybe even much more) and just 10 database connections if your app uses long polling to notify clients on new messages.

Alexey Petrushin

unread,
Jan 24, 2014, 11:26:51 AM1/24/14
to nod...@googlegroups.com, fe...@indutny.com
by the way, 100 connections work the same and give the same numbers, I set 1000 just in case :)

Alexey Petrushin

unread,
Jan 27, 2014, 3:07:10 PM1/27/14
to nod...@googlegroups.com
Update, after tuning the Rails with Puma Server ( thanks to https://github.com/antage ) its speed increased in ten times and is almost the same as Node (it uses only one process and it seems only one core).

Updated benchmark https://github.com/alexeypetrushin/web-frameworks-benchmarks

Rails

Transactions:               2258 hits
Longest transaction:            0.52

Express

Transactions:               3158 hits
Longest transaction:            0.34

Alexey Petrushin

unread,
Jan 31, 2014, 2:19:11 PM1/31/14
to nod...@googlegroups.com
Maybe there's some other resource limit that prevents node to work in full power? Node.js process uses only 50% of CPU but if I raise concurrency over 100 it starts to generate connection errors. 

What maybe the cause?
Reply all
Reply to author
Forward
0 new messages