www.digitalocean.com/community/tutorials/how-to-optimize-nginx-configuration
How To Optimize Nginx Configuration | DigitalOcean
Nginx is a fast and lightweight alternative to the sometimes overbearing Apache 2. However, Nginx just like any kind of server or software must be tuned to help attain optimal performance. Here's how to optimize Nginx configuration.
www.digitalocean.com
How To Optimize Nginx Configuration
-
By Alex Kavon
Last Validated onMarch 26, 2020 Originally Published onMarch 17, 2014 643.1k views
Introduction
Nginx
Nginx is a fast and lightweight alternative to the sometimes overbearing Apache 2. However, Nginx just like any kind of server or software must be tuned to help attain optimal performance.
Requirements
-
A fresh Debian 7 droplet with the intial setup completed.
-
The droplet must also have a freshly installed and configured Nginx server running. Try the Debian LEMP Stack tutorial, or for something a little more basic, try the Debian Nginx Server Blocks tutorial.
-
A good understanding of Linux basics.
Worker Processes and Worker Connections
The first two variables we need to tune are the worker processes and worker connections. Before we jump into each setting, we need to understand what each of these directives control. The worker_processes directive is the sturdy spine of life for Nginx. This directive is responsible for letting our virtual server know how many workers to spawn once it has become bound to the proper IP and port(s). It is common practice to run 1 worker process per core. Anything above this won’t hurt your system, but it will leave idle processes usually just lying about.
To figure out what number you’ll need to set worker_processes to, simply take a look at the amount of cores you have on your setup. If you’re using the DigitalOcean 512MB setup, then it’ll probably be one core. If you end up fast resizing to a larger setup, then you’ll need to check your cores again and adjust this number accordingly. We can accomplish this by greping out the cpuinfo:
grep processor /proc/cpuinfo | wc -l
Let’s say this returns a value of 1. Then that is the amount of cores on our machine!
The worker_connections command tells our worker processes how many people can simultaneously be served by Nginx. The default value is 768; however, considering that every browser usually opens up at least 2 connections/server, this number can half. This is why we need to adjust our worker connections to its full potential. We can check our core’s limitations by issuing a ulimit command:
ulimit -n
On a smaller machine (512MB droplet) this number will probably read 1024, which is a good starting number.
Let’s update our config:
sudo nano /etc/nginx/nginx.conf
worker_processes 1; worker_connections 1024;
Remember, the amount of clients that can be served can be multiplied by the amount of cores. In this case, we can server 1024 clients/second. This is, however, even further mitigated by the keepalive_timeout directive.
'성능테스트' 카테고리의 다른 글
swap이란 무엇인가 (0) | 2021.07.05 |
---|---|
HP-UX 물리 메모리 Size 확인 (1) | 2021.07.05 |
[ Loadrunner ] fiddler레코딩 시 utf-8변환 (0) | 2021.04.19 |
encoding decoding 정리 (1) | 2021.04.19 |
[ Loadrunner ] LR부하테스트 중 응답시간이 일부 튀는 현상이 있을 때 확인해볼 사항 (0) | 2021.01.20 |