Slow performance for Node.js running on AWS

Question:

I am running a very simple RESTful API on AWS using Node.js. The API takes a request in the form of ‘/rest/users/jdoe’ and returns the following (it’s all done in memory, no database involved):

The performance of this API on Node.js + AWS is horrible compared to the local network – only 9 requests/sec vs. 2,214 requests/sec on a local network. AWS is running a m1.medium instance whereas the local Node server is a desktop machine with an Intel i7-950 processor. Trying to figure out why such a huge difference in performance.

Benchmarks using Apache Bench are as follows:

Local Network

10,000 requests with concurrency of 100/group

AWS

1,000 requests with concurrency of 100/group
(10,000 requests would have taken too long)

Questions:

  • Connect time for AWS is 105 ms (avg) compared to 0 ms on local network. I assume that this is because it takes a lot more time to open a socket to AWS then to a server on a local network. Is there anything to be done here for better performance under load assuming requests are coming in from multiple machines across the globe.
  • More serious is the server processing time – 45 ms for local server compared to 9.9 seconds for AWS! I can’t figure out what’s going on in here. The server is only pressing 9.46 requests/sec. which is peanuts!

Any insight into these issues much appreciated. I am nervous about putting a serious application on Node+AWS if it can’t perform super fast on such a simple application.

For reference here’s my server code:

Edit

Single request sent in isolation (-n 1 -c 1)

10 request all sent concurrently (-n 10 -c 10)

Results using wrk

As suggested by Andrey Sidorov. The results are MUCH better – 2821 requests per second:

So it certainly looks like the culprit is ApacheBench! Unbelievable!

Answer:

It’s probably ab issue (see also this question). There is nothing wrong in your server code. I suggest to try to benchmark using wrk load testing tool. Your example on my t1.micro:

Leave a Reply