{"id":6896,"date":"2017-08-14T17:18:53","date_gmt":"2017-08-14T09:18:53","guid":{"rendered":"http:\/\/rmohan.com\/?p=6896"},"modified":"2017-08-14T17:18:53","modified_gmt":"2017-08-14T09:18:53","slug":"nginx-server-10000-concurrent-optimization-test-ab-test-tool","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6896","title":{"rendered":"Nginx server 10000 concurrent optimization test (ab test tool)"},"content":{"rendered":"<p><strong>1.nginx monitoring module<\/strong><\/p>\n<p>1) Compile nginx with the parameter &#8211;with-http_stub_status_module<\/p>\n<pre class=\"wp-code-highlight prettyprint prettyprinted\"><span class=\"com\">#\/usr\/local\/nginx\/sbin\/nginx -V<span class=\"pln\">\r\n<span class=\"pun\">.\/configure --user=www --<span class=\"kwd\">group=www --prefix=<span class=\"str\">\/usr\/local\/nginx --with-http_stub_status_module --with-http_ssl_mo\r\n\r\n<\/span><\/span><\/span><\/span><\/span><\/pre>\n<pre class=\"javascript\">.<span class=\"regexp\">\/configure --prefix=\/usr\/local\r\n    --user=nginx \r\n    --group=nginx\r\n    --<span class=\"keyword\">with-http_ssl_module\r\n    --with-http_realip_module\r\n    --http-client-body-temp-path=\/usr\/local\/var\/tmp\/nginx\/client \r\n    --http-proxy-temp-path=\/usr\/local\/var\/tmp\/nginx\/proxy \r\n    --http-fastcgi-temp-path=\/usr\/local\/var\/tmp\/nginx\/fcgi \r\n    --http-scgi-temp-path=\/usr\/local\/var\/tmp\/nginx\/scgi \r\n    --http-uwsgi-temp-path=\/usr\/local\/var\/tmp\/nginx\/uwsgi \r\n    --with-http_geoip_module \r\n    --with-http_stub_status_module<\/span><\/span><\/pre>\n<p>2)\u00a0Modify the nginx configuration file and add the monitoring status configuration<\/p>\n<p>Add the following code to the server block of nginx.conf<\/p>\n<pre class=\"nginx\"><span class=\"title\">location \/nginx_status {\r\n    <span class=\"comment\"># Turn on nginx stats\r\n    stub_status <span class=\"built_in\">on;\r\n    # I do not need logs for stats\r\n    access_log   off;\r\n    # Security: Only allow access from 192.168.1.100 IP #\r\n    #allow 192.168.1.100;\r\n    # Send rest of the world to \/dev\/null #\r\n    #deny all;\r\n}<\/span><\/span><\/span><\/pre>\n<pre class=\"nginx\"><span class=\"title\"><span class=\"comment\"><span class=\"built_in\">xplanation:\r\n   Active connections: The number of active connections initiated by the backend. \r\n  Server accepted handling requests: Nginx handled a total of 655 connections, successfully created 655 times handshake (proved no failure in the middle), handled a total of 1985 requests. \r\n  Reading: Nginx Number of Header messages read to the client. \r\n  Writing: Nginx Number of Header messages returned to the client. \r\n  Waiting: In the case of keep-alive, this value is equal to active - (reading + writing), meaning that Nginx <\/span><\/span><\/span><\/pre>\n<pre class=\"wp-code-highlight prettyprint prettyprinted\"><span class=\"com\"><span class=\"pln\"><span class=\"pun\"><span class=\"kwd\"><span class=\"str\">\u00a0<\/span><\/span><\/span><\/span><\/span><\/pre>\n<pre class=\"wp-code-highlight prettyprint prettyprinted\"><span class=\"str\">\/usr\/<span class=\"kwd\">local<span class=\"pun\">\/<span class=\"pln\">nginx\/sbin\/nginx -t  <span class=\"com\">\r\n\/usr\/local\/nginx\/sbin\/nginx -s reload\r\n<\/span><\/span><\/span><\/span><\/span><\/pre>\n<pre class=\"wp-code-highlight prettyprint prettyprinted\"><strong> 2. Set the maximum number of connections (50000) \/ tcp speed up the recovery of the number of conn<\/strong><\/pre>\n<pre class=\"wp-code-highlight prettyprint prettyprinted\"><span class=\"com\"><span class=\"pln\"><span class=\"pun\"><span class=\"kwd\"><span class=\"str\">\r\n\r\n<\/span><\/span><\/span><\/span><\/span><\/pre>\n<p>echo 50000 &gt; \/proc\/sys\/net\/core\/somaxconn<\/p>\n<p>echo 1 &gt; \/proc\/sys\/net\/ipv4\/tcp_tw\/recycle<br \/>\necho 1 &gt; \/proc\/sys\/net\/ipv4\/tcp_tw_reuse<br \/>\necho 0 &gt; \/proc\/sys\/net\/ipv4\/tcp_syncookies<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"wp-code-highlight prettyprint prettyprinted\"><strong>3. set to open more files<\/strong><\/pre>\n<p>ulimit -n 50000<\/p>\n<p>vim \/etc\/nginx\/nginx.conf<br \/>\nworker_rlimit_nofile 10000;<br \/>\nevents{<\/p>\n<p>worker_connections 10240;<br \/>\n}<\/p>\n<p>\/usr\/sbin\/nginx -t<br \/>\n\/usr\/sbin\/nginx -s reload<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"wp-code-highlight prettyprint prettyprinted\"><strong>4.ab -c 5000 -n 100000 http:\/\/192.168.1.129\/index.html <\/strong><\/pre>\n<p>erver Software: nginx\/1.4.6<br \/>\nServer Hostname: 192.168.63.129<br \/>\nServer Port: 80<\/p>\n<p>Document Path: \/index.html<br \/>\nDocument Length: 65 bytes<\/p>\n<p>Concurrency Level: 5000<br \/>\nTime taken for tests: 46.416 seconds<br \/>\nComplete requests: 100000<br \/>\nFailed requests: 90202<br \/>\n(Connect: 0, Receive: 0, Length: 90202, Exceptions: 0)<br \/>\nWrite errors: 0<br \/>\nNon-2xx responses: 90282<br \/>\nTotal transferred: 36624606 bytes<br \/>\nHTML transferred: 18815922 bytes<br \/>\nRequests per second: 2154.42 [#\/sec] (mean)<br \/>\nTime per request: 2320.813 [ms] (mean)<br \/>\nTime per request: 0.464 [ms] (mean, across all concurrent requests)<br \/>\nTransfer rate: 770.55 [Kbytes\/sec] received<\/p>\n<p>Connection Times (ms)<br \/>\nmin mean[+\/-sd] median max<br \/>\nConnect: 18 1251 2273.8 824 31950<br \/>\nProcessing: 298 839 299.1 855 6307<br \/>\nWaiting: 1 648 298.8 651 6194<br \/>\nTotal: 408 2090 2323.2 1697 36083<\/p>\n<p>Percentage of the requests served within a certain time (ms)<br \/>\n50% 1697<br \/>\n66% 1758<br \/>\n75% 1802<br \/>\n80% 1843<br \/>\n90% 2583<br \/>\n95% 4601<br \/>\n98% 8399<br \/>\n99% 8807<br \/>\n100% 36083 (longest request)<\/p>\n<pre class=\"wp-code-highlight prettyprint prettyprinted\"><span class=\"com\"><span class=\"pln\"><span class=\"pun\"><span class=\"kwd\"><span class=\"str\">\u00a0<\/span><\/span><\/span><\/span><\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1.nginx monitoring module<\/p>\n<p>1) Compile nginx with the parameter &#8211;with-http_stub_status_module<\/p>\n<p> #\/usr\/local\/nginx\/sbin\/nginx -V .\/configure &#8211;user=www &#8211;group=www &#8211;prefix=\/usr\/local\/nginx &#8211;with-http_stub_status_module &#8211;with-http_ssl_mo .\/configure &#8211;prefix=\/usr\/local &#8211;user=nginx &#8211;group=nginx &#8211;with-http_ssl_module &#8211;with-http_realip_module &#8211;http-client-body-temp-path=\/usr\/local\/var\/tmp\/nginx\/client &#8211;http-proxy-temp-path=\/usr\/local\/var\/tmp\/nginx\/proxy &#8211;http-fastcgi-temp-path=\/usr\/local\/var\/tmp\/nginx\/fcgi &#8211;http-scgi-temp-path=\/usr\/local\/var\/tmp\/nginx\/scgi &#8211;http-uwsgi-temp-path=\/usr\/local\/var\/tmp\/nginx\/uwsgi &#8211;with-http_geoip_module &#8211;with-http_stub_status_module <\/p>\n<p>2) Modify the nginx configuration file and add the monitoring status configuration<\/p>\n<p>Add the following code to the server block of nginx.conf<\/p>\n<p> location \/nginx_status [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6896"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6896"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6896\/revisions"}],"predecessor-version":[{"id":6897,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6896\/revisions\/6897"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}