nginx를 하나의 동시 최적화 1w

디렉토리

AB 도구
전체 최적화 아이디어
특정 최적화 아이디어는
스크립트가 완료 작성하고 할당 최적화
성능 통계 도구

요약

AB 도구

AB -c 10000 -n 200000 HTTP : //localhost/index.html

[root@study02 ~]# ab -c 10000 -n 100000 http://192.168.0.217/index.html
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.0.217 (be patient)
socket: Too many open files (24)

전체 최적화 아이디어

  • 더 소켓 연결을 허용하는 것은 설립
  • 더 열려있는 파일을 모두 허용

특정 최적화 아이디어

1, 소켓 수준

  • 시스템 수준
  • 하지 홍수에 대한
  • 연결 SOMAXCONN의 최대 수
  • TCP 연결 복구 recyle 속도를
  • 빈 TCP 연결 재활용 재사용 할 수있다
  • nginx를
  • 각각의 자식 프로세스는 열려있는 연결 (work_connections)를 할 수 있습니다
  • HTTP 연결, 빠른 마감, keepalive_timeout 0 가속화

2, 파일 수준

  • 의 nginx 수준
  • Worker_rlimit_nofile 자식 프로세스는 파일을 열 수 있습니다
  • 시스템 수준
  • ulimit를은 (상대적으로 큰 값이 열려있는 파일을 수 있도록 제공) 10000 -n

특정 구성

(1) 시스템 구성

열려있는 연결의 최대 수를 할 수 있도록 시스템을보기

more /proc/sys/net/core/somaxconn
echo 50000 > /proc/sys/net/core/somaxconn

퀵 연결 시스템 복구를 엽니 다

cat /proc/sys/net/ipv4/tcp_tw_recycle
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle

빈 열린 TCP 연결은 재활용이 가능

cat /proc/sys/net/ipv4/tcp_tw_reuse
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse

하지 홍수에 대한

cat /proc/sys/net/ipv4/tcp_syncookies
echo 0 > /proc/sys/net/ipv4/tcp_syncookies

2 Nginx의 구성

  • HTTP 1.0 클라이언트 서버 요청 - 응답 - OFF
  • 요청이 완료된 후 HTTP 1.1 것은 자주 악수를 방지하기 위해, nginx를 keepalive_timeout 설정 인수는 또한 높은 동시성 웹 사이트에서 TCP 연결의 수를 줄이기 위해 긴 연결하는 옵션을 유지하고, 심각한주의가 필요 0으로 설정 될 필요는 없다, keepalived입니다 동시성을 개선하기 위해 연결 상태를 유지 않는다
worker_rlimit_nofile 10000;
events {
    worker_connections 10000;
}
keepalive_timeout 0;

스크립팅 완전 동시 최적의 할당

echo 50000 > /proc/sys/net/core/somaxconn
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
echo 0 > /proc/sys/net/ipv4/tcp_syncookies

문제를 제거 :

  • dmesg를 관찰 시스템
  • 의 nginx는하는 error.log를 관찰

dmesg를 | 꼬리

성능 통계 도구

설치 통계 모듈 http_stub_status_module은, 쉬운의 nginx의 상태를 관찰

  • 1. 모듈이 설치 될 수 통계가 있는지 찾기 위해 nginx를 설치 패키지 디렉토리를 입력하기 전에

삭제 선택한 모든 패키지가 설치 될 수있다

    root@STUDY3 nginx-1.14.2]# cat auto/options |grep YES
    HTTP=YES
    HTTP_CACHE=YES
    HTTP_CHARSET=YES
    HTTP_GZIP=YES
    HTTP_SSI=YES
    HTTP_ACCESS=YES
    HTTP_AUTH_BASIC=YES
    HTTP_MIRROR=YES
    HTTP_USERID=YES
    HTTP_AUTOINDEX=YES
    HTTP_GEO=YES
    HTTP_MAP=YES
    HTTP_SPLIT_CLIENTS=YES
    HTTP_REFERER=YES
    HTTP_REWRITE=YES
    HTTP_PROXY=YES
    HTTP_FASTCGI=YES
    HTTP_UWSGI=YES
    HTTP_SCGI=YES
    HTTP_GRPC=YES
    HTTP_MEMCACHED=YES
    HTTP_LIMIT_CONN=YES
    HTTP_LIMIT_REQ=YES
    HTTP_EMPTY_GIF=YES
    HTTP_BROWSER=YES
    HTTP_UPSTREAM_HASH=YES
    HTTP_UPSTREAM_IP_HASH=YES
    HTTP_UPSTREAM_LEAST_CONN=YES
    HTTP_UPSTREAM_KEEPALIVE=YES
    HTTP_UPSTREAM_ZONE=YES
    MAIL_POP3=YES
    MAIL_IMAP=YES
    MAIL_SMTP=YES
    STREAM_LIMIT_CONN=YES
    STREAM_ACCESS=YES
    STREAM_GEO=YES
    STREAM_MAP=YES
    STREAM_SPLIT_CLIENTS=YES
    STREAM_RETURN=YES
    STREAM_UPSTREAM_HASH=YES
    STREAM_UPSTREAM_LEAST_CONN=YES
    STREAM_UPSTREAM_ZONE=YES
            --with-select_module)            EVENT_SELECT=YES           ;;
            --with-poll_module)              EVENT_POLL=YES             ;;
            --with-threads)                  USE_THREADS=YES            ;;
            --with-file-aio)                 NGX_FILE_AIO=YES           ;;
            --with-http_ssl_module)          HTTP_SSL=YES               ;;
            --with-http_v2_module)           HTTP_V2=YES                ;;
            --with-http_realip_module)       HTTP_REALIP=YES            ;;
            --with-http_addition_module)     HTTP_ADDITION=YES          ;;
            --with-http_xslt_module)         HTTP_XSLT=YES              ;;
            --with-http_image_filter_module) HTTP_IMAGE_FILTER=YES      ;;
            --with-http_geoip_module)        HTTP_GEOIP=YES             ;;
            --with-http_sub_module)          HTTP_SUB=YES               ;;
            --with-http_dav_module)          HTTP_DAV=YES               ;;
            --with-http_flv_module)          HTTP_FLV=YES               ;;
            --with-http_mp4_module)          HTTP_MP4=YES               ;;
            --with-http_gunzip_module)       HTTP_GUNZIP=YES            ;;
            --with-http_gzip_static_module)  HTTP_GZIP_STATIC=YES       ;;
            --with-http_auth_request_module) HTTP_AUTH_REQUEST=YES      ;;
            --with-http_random_index_module) HTTP_RANDOM_INDEX=YES      ;;
            --with-http_secure_link_module)  HTTP_SECURE_LINK=YES       ;;
            --with-http_degradation_module)  HTTP_DEGRADATION=YES       ;;
            --with-http_slice_module)        HTTP_SLICE=YES             ;;
            --with-http_perl_module)         HTTP_PERL=YES              ;;
            --with-http_stub_status_module)  HTTP_STUB_STATUS=YES       ;;
            --with-mail)                     MAIL=YES                   ;;
            --with-mail_ssl_module)          MAIL_SSL=YES               ;;
                MAIL=YES
                MAIL_SSL=YES
            --with-stream)                   STREAM=YES                 ;;
            --with-stream_ssl_module)        STREAM_SSL=YES             ;;
            --with-stream_realip_module)     STREAM_REALIP=YES          ;;
            --with-stream_geoip_module)      STREAM_GEOIP=YES           ;;
                                             STREAM_SSL_PREREAD=YES     ;;
            --with-google_perftools_module)  NGX_GOOGLE_PERFTOOLS=YES   ;;
            --with-cpp_test_module)          NGX_CPP_TEST=YES           ;;
            --with-compat)                   NGX_COMPAT=YES             ;;
            --with-debug)                    NGX_DEBUG=YES              ;;
            --with-pcre)                     USE_PCRE=YES               ;;
            --with-pcre-jit)                 PCRE_JIT=YES               ;;
            --with-libatomic)                NGX_LIBATOMIC=YES          ;;
            --test-build-devpoll)            NGX_TEST_BUILD_DEVPOLL=YES ;;
            --test-build-eventport)          NGX_TEST_BUILD_EVENTPORT=YES ;;
            --test-build-epoll)              NGX_TEST_BUILD_EPOLL=YES   ;;
            --test-build-solaris-sendfilev)  NGX_TEST_BUILD_SOLARIS_SENDFILEV=YES ;;

모듈이 http_stub_status_module 있는지 확인

[root@STUDY3 nginx-1.14.2]# cat auto/options |grep YES|grep 'http_stub_status_module'
        --with-http_stub_status_module)  HTTP_STUB_STATUS=YES       ;;

make && make install
  • 2. Nginx의 성능 통계 도구를 설치
    ./configure --prefix=/usr/local/nginx/ --with-http_stub_status_module
  • 모듈이 성공적으로 설치되어 있는지 여부 3.
    [root@STUDY3 nginx-1.14.2]# /usr/local/nginx/sbin/nginx -V
    nginx version: nginx/1.14.2
    built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
    configure arguments: --prefix=/usr/local/nginx/ --with-http_stub_status_module

설명 모듈이 성공적으로 설치되었습니다

  • 4.의 nginx 서버 구성 도구 개방 성능 통계 내부에 다음과 같은 구성 항목을 추가
    location /nginx_status {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
    }
  • 5.보기, 상태 http://192.168.0.217/nginx_status를 보려면 페이지 액세스를 새로 고침
Active connections: 2020 
server accepts handled requests
 897553 897553 442986 
Reading: 0 Writing: 1 Waiting: 2019 
  • 6.ab 테스트
    [root@study02 ~]# ab -c 10000 -n 200000 http://192.168.0.217/index.html
    This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/

    Benchmarking 192.168.0.217 (be patient)
    Completed 20000 requests
    Completed 40000 requests
    Completed 60000 requests
    Completed 80000 requests
    Completed 100000 requests
    Completed 120000 requests
    Completed 140000 requests
    Completed 160000 requests
    Completed 180000 requests
    Completed 200000 requests
    Finished 200000 requests


    Server Software:        nginx/1.14.2
    Server Hostname:        192.168.0.217
    Server Port:            80

    Document Path:          /index.html
    Document Length:        612 bytes

    Concurrency Level:      10000
    Time taken for tests:   13.268 seconds
    Complete requests:      200000
    Failed requests:        345710
       (Connect: 0, Receive: 0, Length: 174517, Exceptions: 171193)
    Write errors:           0
    Non-2xx responses:      21
    Total transferred:      24276700 bytes
    HTML transferred:       17581305 bytes
    Requests per second:    15074.19 [#/sec] (mean)
    Time per request:       663.386 [ms] (mean)
    Time per request:       0.066 [ms] (mean, across all concurrent requests)
    Transfer rate:          1786.87 [Kbytes/sec] received

    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0  322  85.2    324    1238
    Processing:    69  322 108.4    315     692
    Waiting:        0   38 103.0      0     503
    Total:        373  643  97.8    625    1651

    Percentage of the requests served within a certain time (ms)
      50%    625
      66%    640
      75%    643
      80%    646
      90%    739
      95%    883
      98%    976
      99%   1015
     100%   1651 (longest request)

  • 테스트 기계는 또한 대형 디지털되는 ulimit -n을 구성해야
  • 테스트 시스템을 구성 할 필요가 50000> / proc 디렉토리 / sys 인 / 인터넷 / 코어 / SOMAXCONN 에코

개요

서버 배포 시간을함으로써조차 캐시 데이터베이스를 할, 우리는 첫 번째 서버 구성의 한계를 이해해야하고, 첫 번째 테스트 시작의 nginx는 정적 HTML 페이지 테스트가 시작 실행할 수 있습니다 때 서버가 처리 할 수없는 논리 치료는,의 nginx의 최대 용량을 테스트하기 위해 CDN하지 않습니다. 우리 모두는 PHP에 가입하는 경우, 데이터베이스에 연결, 데이터베이스 캐시가 최대 성능을 눌러 서버에 대해 개별적으로 같은 디버그를 수있는 일이 후, CDN 사진 충격 동시성을 수행 할 것을 알고, 대상 최적화는 올바른 것입니다.

추천

출처www.cnblogs.com/lisqiong/p/11403928.html