current position:Home>How to optimize the performance of nginx supporting SSL

How to optimize the performance of nginx supporting SSL

2022-04-29 19:27:10Billion cloud speed

What's wrong Nginx Support SSL To optimize the performance of

This article mainly introduces “ What's wrong Nginx Support SSL To optimize the performance of ”, In daily operation , I believe a lot of people are talking about Nginx Support SSL There are doubts about optimizing the performance of , Xiao Bian consulted all kinds of materials , Sort out simple and easy-to-use operation methods , I hope to answer ” What's wrong Nginx Support SSL To optimize the performance of ” Your doubts help ! Next , Please follow Xiaobian to learn !


initialization The server

This web The server runs on a ec2 t1.micro Environmental Science . I choose nginx + php5-fpm To run the php page , For safety reasons, I use ssl.
Test performance

I use blitz.io To conduct pressure and performance tests . Here are my stress test commands . The function is to 60 Gradually increase users in seconds . In the whole process ,blitz.io Create one request per second and add 4 Users (rise/run = 260/60).

Copy code   The code is as follows :

-p 1-250:60 https://mydomian.com

Detailed explanation

For fans , Here is a detailed explanation . I will lead you through my thinking process in the following chapters .
If you edit nginx To configure , So restart nginx The server . If you edit php5-fpm To configure , Then restart the service .

Try #1: Enhanced hardware

For improving performance , My instinct is to enhance the server hardware , I hope everything will work properly . I will ec2 Instance from t1.micro Upgrade to c1.medium( Optimized for high traffic servers , Not a general-purpose server ).

After that , I ran blitz.io The load test . This is a screenshot of the result

 What's wrong Nginx Support SSL To optimize the performance of

  The peak performance of the server can reach... Per second 50 A successful hit . As the load continues to increase , The number of timeouts increased , And the number of hits decreased .

Try #2: Effect evaluation cpu performance

I rerun the test , Running in the background at the same time htop. I noticed two cpu The utilization rate of does not exceed 13%. Memory used 300mb. It seems that the server is not fully utilized . So I made the following changes . I edited it /etc/ngnix/nginx.conf

Copy code   The code is as follows :

worker_processes 2;

Try #3, #4, #5: fine-tuning nginx + php5-fpm

In the following attempts , I changed the following values , Still get and try #1 The same result .

Try #3

Copy code   The code is as follows :

/etc/ngnix/nginx.conf

worker_processes 2;
events {
worker_connections 19000;
multi_accept on;
}
...

_________

Try #4

Copy code   The code is as follows :

/etc/ngnix/nginx.conf

worker_processes 2;
events {
  worker_connections 19000;
  multi_accept on;
}
http {
  gzip on;
  gzip_disable "msie6";

  gzip_min_length  1000;
  gzip_proxied     expired no-cache no-store private auth;
  gzip_types       text/plain application/xml application/javascript text/css application/x-javascript;

}
...

________

Try #5
I didn't cancel the attempt #4 Changes

Copy code   The code is as follows :

/etc/php5/fpm/pool.d/www.conf

pm.max_children = 160
pm.start_servers = 24
pm.min_spare_servers = 20
pm.max_spare_servers = 35
pm.max_requests = 1500

Try #6: Deploy another server


I have another one linode The server . have 1.5gb Memory and 8 individual cpu. I copy all nginx and php5-fpm To this server .

This is what I use blitz.io The order to do the stress test

Copy code   The code is as follows :

-p 1-250:60 http://labs.mydomian2.com

This is the result :

 What's wrong Nginx Support SSL To optimize the performance of

 linode The server is great ! I was thinking “linode Than ec2 Good yao ?”. After I decided to follow this line of thought , Migrate the code to linode Before , I want to make sure there is no difference between the two servers .


Try #7: Great enlightenment

I searched for , Find out nginx There are some ssl Related issues . Default nginx Use dhe Algorithm to create password (cipher). Disabling this algorithm will improve performance .

All I edit /etc/nginx/nginx.conf Removed kedh cryptographic algorithm .

Copy code   The code is as follows :

worker_processes 2;
events {
  worker_connections 1024;
}
http {
  gzip on;
  gzip_disable "msie6";

  gzip_min_length  1000;
  gzip_proxied     expired no-cache no-store private auth;
  gzip_types       text/plain application/xml application/javascript text/css application/x-javascript;
  ssl_ciphers all:!kedh!adh:rc4+rsa:+high:+medium:+low:+sslv2:+exp; 

}
...

I repeated the original stress test :

Copy code   The code is as follows :

-p 1-250:60 https://mydomian.com

This is the result :

 What's wrong Nginx Support SSL To optimize the performance of

  It really works !!!!

Try #8: I really need to enhance the hardware

fantastic ,ec2 And linode Very close in performance . But I really need c1.medium Examples to achieve this performance ? It may not be necessary ... So I will ec2 The instance type of is changed back to t1.micro.

i because micro There is only one instance cpu, All I am /etc/nginx/nginx.conf There's less worker_processes.

Copy code   The code is as follows :

worker_processes 1;
...

This is the result :

 What's wrong Nginx Support SSL To optimize the performance of

Here we are , About “ What's wrong Nginx Support SSL To optimize the performance of ” That's the end of my study , I hope we can solve your doubts . The combination of theory and practice can better help you learn , Let's try ! If you want to continue to learn more related knowledge , Please continue to pay attention to Yisu cloud website , Xiaobian will continue to strive to bring you more practical articles !

copyright notice
author[Billion cloud speed],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204291744570664.html

Random recommended