최고의 성능 을 위 한 Nginx
6911 단어 성능 테스트성능 테스트 (도구)
일반적으로 최적화 된 Nginx Linux 서버 는 500, 000 – 600, 000 회 / 초의 요청 처리 성능 에 도달 할 수 있 지만 나의 Nginx 서버 는 904, 000 회 / 초의 처리 성능 에 안정 적 으로 도달 할 수 있 고 나 는 이 고부 하 테스트 를 12 시간 이상 하면 서버 작업 이 안정 적 이다.
여기 서 특별히 설명해 야 할 것 은 본 논문 에 열 거 된 모든 설정 은 나의 테스트 환경 에서 검 증 된 것 이 고 서버 의 상황 에 따라 설정 해 야 한 다 는 것 이다.
EPEL 소스 에서 Nginx 설치 하기:
yum -y install nginx
프로필 을 백업 하고 필요 에 따라 설정 합 니 다:
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig
vim /etc/nginx/nginx.conf
# This number should be, at maximum, the number of CPU cores on your system.
# (since nginx doesn't benefit from more than one worker per CPU.)
# CPU , 1 Nginx 。
worker_processes 24;
# Number of file descriptors used for Nginx. This is set in the OS with 'ulimit -n 200000'
# or using /etc/security/limits.conf
# Nginx , "ulimit -n 200000", /etc/security/limits.conf 。
worker_rlimit_nofile 200000;
# only log critical errors
# critical
error_log /var/log/nginx/error.log crit
# Determines how many clients will be served by each worker process.
# (Max clients = worker_connections * worker_processes)
# "Max clients" is also limited by the number of socket connections available on the system (~64k)
# Nginx ,( = * )
# socket ( 64K )
worker_connections 4000;
# essential for linux, optmized to serve many clients with each thread
# Linux , 。
use epoll;
# Accept as many connections as possible, after nginx gets notification about a new connection.
# May flood worker_connections, if that option is set too low.
# , worker_connections , 。
multi_accept on;
# Caches information about open FDs, freqently accessed files.
# Changing this setting, in my environment, brought performance up from 560k req/sec, to 904k req/sec.
# I recommend using some varient of these options, though not the specific values listed below.
# FDs( / )
# , , 560k / 904k / 。
# , 。
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
# Buffer log writes to speed up IO, or disable them altogether
# IO , 。
# access_log /var/log/nginx/access.log main buffer=16k;
access_log off;
# Sendfile copies data between one FD and other from within the kernel.
# More efficient than read() + write(), since the requires transferring data to and from the user space.
# sendfile , FD , read() + write() 。
sendfile on;
# Tcp_nopush causes nginx to attempt to send its HTTP response head in one packet,
# instead of using partial frames. This is useful for prepending headers before calling sendfile,
# or for throughput optimization.
# tcp_nopush ,Nginux HTTP 。
# sendfile HTTP , 。
tcp_nopush on;
# don't buffer data-sends (disable Nagle algorithm). Good for sending frequent small bursts of data in real time.
# data-sends ( Nagle ), 。
tcp_nodelay on;
# Timeout for keep-alive connections. Server will close connections after this time.
# keep-alive , 。
keepalive_timeout 30;
# Number of requests a client can make over the keep-alive connection. This is set high for testing.
# keep-alive , , 。
keepalive_requests 100000;
# allow the server to close the connection after a client stops responding. Frees up socket-associated memory.
# , socket 。
reset_timedout_connection on;
# send the client a "request timed out" if the body is not loaded by this time. Default 60.
# , 60 。
client_body_timeout 10;
# If the client stops reading data, free up the stale client connection after this much time. Default 60.
# , , , 60 。
send_timeout 2;
# Compression. Reduces the amount of data that needs to be transferred over the network
# , 。
gzip on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6].";
Nginx 를 시작 하고 자동 로드 를 설정 합 니 다.
service nginx start
chkconfig nginx on
Tsung 을 설정 하고 테스트 를 시작 합 니 다. 테스트 가 10 분 정도 차이 나 지 않 으 면 서버 의 피크 능력 을 테스트 할 수 있 습 니 다. 구체 적 인 시간 은 Tsung 설정 과 관련 이 있 습 니 다.
[root@loadnode1 ~] vim ~/.tsung/tsung.xml
tsung start
테스트 결과 가 충분 하 다 고 생각 되 는 경우 ctrl + c 를 통 해 종료 한 후, 우리 가 설정 한 별명 명령 treport 를 사용 하여 테스트 보고 서 를 봅 니 다.WEB 서버 조정, 두 번 째 부분: TCP 프로 토 콜 창고 조정
이 부분 은 Ngiinx 에 만 적용 되 는 것 이 아니 라 모든 WEB 서버 에서 도 사용 할 수 있다.커 널 TCP 설정 에 대한 최적화 로 서버 네트워크 대역 폭 을 높 일 수 있 습 니 다.
아래 설정 은 제 10 - Gbase - T 서버 에서 완벽 하 게 작 동 되 었 습 니 다. 서버 는 기본 설정 의 8Gbps 대역 폭 에서 9.3Gbps 로 향상 되 었 습 니 다.
물론 서버 의 결론 은 다 를 수 있 습 니 다.
다음 설정 항목 은 매번 한 가지 만 수정 한 다음 네트워크 성능 테스트 도구 netperf, iperf 또는 유사 한 테스트 스 크 립 트 cluster - netbench. pl 로 서버 를 여러 번 테스트 하 는 것 을 권장 합 니 다.
yum -y install netperf iperf
vim /etc/sysctl.conf
# Increase system IP port limits to allow for more connections# IP , net.ipv4.ip_local_port_range = 2000 65000
net.ipv4.tcp_window_scaling = 1# number of packets to keep in backlog before the kernel starts dropping them# , net.ipv4.tcp_max_syn_backlog = 3240000# increase socket listen backlog# socket net.core.somaxconn = 3240000
net.ipv4.tcp_max_tw_buckets = 1440000# Increase TCP buffer sizes# TCP net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_congestion_control = cubic
설정 을 수정 할 때마다 다음 명령 을 실행 해 야 합 니 다.
sysctl -p /etc/sysctl.conf
설정 수정 후 반드시 네트워크 벤 치 마크 테스트 를 해 야 한 다 는 것 을 잊 지 마 세 요. 그러면 구체 적 으로 어떤 설정 수정의 최적화 효과 가 가장 뚜렷 한 지 관찰 할 수 있 습 니 다.이런 효과 적 인 테스트 방법 을 통 해 너 를 위해 많은 시간 을 절약 할 수 있다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Java 맵 스트리밍 방법 및 성능 테스트HashMap-2, 크기는 100만이고 키와 value는 모두 String이며 키의 값은 50, 100, 150, 200,..., 50000000: 2.1.2 TreeMap 테스트 데이터 keySet 범주 key+v...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.