Apache vs. Nginx performance benchmark

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we'll compare nginx and Apache HTP server we'll use parameters and grafana to collect and visualize metrics we'll get CPU usage and memory usage from the node exporter as a backend we'll use a simple app based on the rust axon framework for building HTTP and rest apis and to collect traffic we'll use a native parameters rust client for the framework first of all we'll create VPC and ec2 instances in AWS using terraform to install software and configure our reverse proxies we'll use ansible with Dynamic inventory in the first test we'll forward plain HTTP requests to the backend in the second test we'll use https and upgrade our protocols in both proxies to http 2. as always you can find up-to-date code in my GitHub repository for example if you want to deploy parameters to AWS and use ec2 tags to dynamically discover targets you'll need to create instance profile and Grant Amazon easy to read only access then in the parameters config you can use ec2 labels instead of hardcoding IP addresses or host names now to leverage ansible Dynamic inventory first of all you need to create inventory file and specify ec2 tags that you want to use then you can automatically convert those tags to ansible groups in the ansible Playbook you can use the following pattern first is attack then the attack key and while you always try to use Dynamic configuration and do not hardcode any IP or host names anywhere it will simplify your life in the long run unfortunately Apache server does not support grpc so I limited tests only to http in nginx we use server name and proxy pass directives to forward requests to secure our API we can either obtain with third bot certificates from let's encrypt or we can generate self-sign CA and issue a couple of certificates for nginx and Apache location directive stays the same also keep in mind by default nginx will use HTTP 1 protocol you need to explicitly upgrade it to http 2. now to generate self-signed certificates you can use CF SSL since it's a self-signed certificate we also need to add our certificate authority to ca certificates and run update CA certificates command in that way you won't get a warning that it is a self-signed certificate when we install Apache to use proxy mode and https we need to explicitly enable a few Apache modules to use Apache as a reverse proxy use proxy pass and proxy directive and specify your backend servers in my case it's just one to secure Apache server you also need to provide certificates and enable HTTP 2 protocol in the first test we slowly scale the load from one virtual user to 1000 during the 5 minute interval then immediately increase it to 2000 and run it for another 5 minutes finally just keep increasing the low mode till one of the servers fail now to collect traffic we create two separate endpoints in the rust application and use Prometheus to record every single request and expose it at the slash Matrix endpoint let's go ahead and run the first test for both Apache and nginx proxy I'm fully aware that you can tune each proxy to increase its performance but in most cases people will run those servers with default settings so I also use default settings in this test you can notice that by the time we reach 450 requests per second Apache starts to drop requests even if it only uses six percent of the CPU in this test nginx was able to handle almost 6 000 requests per second compared to Apache with 450 requests per second memory usage stays more or less flat and CPU usage for nginx reaches around 70 max if you decide to use Apache make sure you learn all the configuration options and load tested because with default settings it's not quite impressive but both of those proxies are written in the C programming language so I expect similar performance in the best case scenario now let's run the second test with https as you can expect with https proxy needs to terminate jealous with each request and create a new connection toward the back end which will significantly increase CPU usage in this test again Apache only handles around 450 requests per second even if the CPU increased from 6 to 12 percent and nginx with https can only take care of 1500 requests per second I use g3a small ec2 instance of course if you use larger instance types you can get more requests per second for nginx however not so sure about Apache I have plenty of other tests on my channel if you're interested for example go Link versus node.js or golink versus rust and others you can find them in the playlist thank you for watching and I'll see you in another video
Info
Channel: Anton Putra
Views: 11,163
Rating: undefined out of 5
Keywords: nginx vs apache 2022, nginx vs apache, apache2, apache vs nginx, apache vs nginx performance, apache2 web server, nginx tutorial, nginx reverse proxy, nginx web server, nginx load balancing, apache tutorial, ansible, terraform, aws, ec2, anton putra, devops, apache http server, apache httpd, apache httpd server, apache httpd reverse proxy, apache reverse proxy, apache reverse proxy configuration step by step, apache reverse proxy tutorial, nginx https, nginx http2, apache http 2
Id: Fx8afVZJLd4
Channel Id: undefined
Length: 4min 59sec (299 seconds)
Published: Sun Jan 15 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.