ELB vs Nginx

    Hi again!

    I had a gorgeous task for research, and I want to share my results with the community. The meaning of the task is to determine the best version of the NGINX deployment in AWS EC2 / VPC. It should be the best from many angles, especially from the High Availability side and response speed. A particularly important factor is the speed of processing SSL requests, so tests were performed on SSL-performance.

    All instances are in the same VPC network, ELB also rises in the same network.

    Several variations of the deployment were considered, but the choice fell on 2 main configurations, the tests on which I conducted.

    Configuration 1. ELB

    • The usual scheme for many applications. ELB stands in front of two or more NGINX instances, passes traffic, thereby making the configuration highly reliable (HA). If one of the nodes fails, traffic does not go to it.
    • Easily scalable design.

    • Plus one hop to the network.
    • Not under control.

    Configuration 2. NGINX

    • Direct access to the balancer without extraneous proxies.
    • Full control over the infrastructure.

    • Configuring high reliability is complicated by the use of heartbeat checks and communication between servers.
    • Heavily scalable


    Testing took place on m1.medium instances (3.75 GiB memory, 2 EC2 Compute Unit (1 virtual core with 2 EC2 Compute Unit)). As a web server, nginx was used with a default page. The test was conducted from another AWS region using Apache Bench: 6 competing users asked 400 times for a page. The test was repeated 100 times in each case.

    So, 4 tests were conducted. Both configurations responded to http and https requests.

    Non SSL

    Tests are aimed at identifying the effect of ELB on the response rate of the structure. It is assumed that configurations with ELB will respond more slowly, as there is an additional node on the network. But you also need to take into account that there can be more than one (in our case 2) NGINX instance for ELB, which can be more productive than one.

    Average response time graph

    The average result of all answers (in ms):
    ELB: 209.586
    NGINX: 207.934


    As you can see, the results are practically the same. Although the NGINX configuration is constantly faster than ELB on the graph, the difference of 1-2% is absolutely acceptable. And since the ELB configuration is much easier to configure, more stable and has almost the same response time as NGINX, we can give it preference.


    Tests are aimed at finding out the performance of configurations regarding SSL encryption. In the ELB configuration, SSL is encrypted by ELB; in the NGINX configuration, one NGINX balancer is used.

    Average response time graph

    The average result of all answers (in ms):
    ELB: 455.921
    NGINX: 437.745


    At the beginning of testing, the ELB was significantly lagging behind in the responses. But after the 30th request, we see an increase in productivity. This is because the ELB has been scaled vertically. After increasing computing power, the performance became almost the same, as can be seen on the schedule.

    As you know, ELB is an m1.micro instance that can be scaled vertically if it does not cope with the tasks. This is not controlled in any way and is done automatically. But thanks to partnerships with AWS, you can achieve the installation of a minimum shape for ELB, and, for example, ELB will never be less than m1.medium. This is done in order to maximize the speed of the infrastructure. If you use this enterprise option, the choice of location for SSL encryption depends on the ease of configuration and other factors. So far, these issues have not been considered, but the test results have shown that both configurations are approximately equivalent.


    Performance tests were performed on configurations with and without ELB in AWS EC2 / VPC. The indicators show that the presence of ELB has very little effect on the response time, although this makes it easier to configure highly available solutions. Also, using additional AWS options, it is not really important where to perform SSL processing. In other cases, with sufficient capacities ( at least not t1.micro ), it should not be carried out on ELB.

    If you have any other interesting ideas on how to compare these configurations, I am open to them. Now everything is running and you can easily run a few more tests.

    Tests have been conducted for HAproxy. As expected, HAproxy is slightly faster than NGINX.
    Average request timing:
    • HAproxy: 203.345 ms
    • ELB over HAproxy: 204.97 ms

    The overall picture is as follows:

    Also popular now: