{"id":170426,"date":"2020-02-03T10:44:20","date_gmt":"2020-02-03T02:44:20","guid":{"rendered":"https:\/\/gulass.cn\/?p=170426"},"modified":"2020-01-23T09:45:39","modified_gmt":"2020-01-23T01:45:39","slug":"nginx","status":"publish","type":"post","link":"https:\/\/gulass.cn\/nginx.html","title":{"rendered":"Nginx\u5982\u6b64\u4e4b\u5feb"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nnignx\u7684\u5e76\u53d1\u8fde\u63a5\u6570\uff0c\u4e00\u822c\u4f18\u5316\u540e\uff0c\u5cf0\u503c\u80fd\u4fdd\u6301\u5728 1~3w \u5de6\u53f3\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

Nginx \u7684\u8fdb\u7a0b\u6a21\u578b<\/strong><\/div>\n

\"\"<\/p>\n

Nginx \u670d\u52a1\u5668\uff0c\u6b63\u5e38\u8fd0\u884c\u8fc7\u7a0b\u4e2d<\/strong><\/div>\n

1.\u591a\u8fdb\u7a0b\uff1a\u4e00\u4e2a Master \u8fdb\u7a0b\u3001\u591a\u4e2a Worker \u8fdb\u7a0b
\n2.Master \u8fdb\u7a0b\uff1a\u7ba1\u7406 Worker \u8fdb\u7a0b
\n3.\u5bf9\u5916\u63a5\u53e3\uff1a\u63a5\u6536\u5916\u90e8\u7684\u64cd\u4f5c\uff08\u4fe1\u53f7\uff09
\n4.\u5bf9\u5185\u8f6c\u53d1\uff1a\u6839\u636e\u5916\u90e8\u7684\u64cd\u4f5c\u7684\u4e0d\u540c\uff0c\u901a\u8fc7\u4fe1\u53f7\u7ba1\u7406 Worker
\n5.\u76d1\u63a7\uff1a\u76d1\u63a7 worker \u8fdb\u7a0b\u7684\u8fd0\u884c\u72b6\u6001\uff0cworker \u8fdb\u7a0b\u5f02\u5e38\u7ec8\u6b62\u540e\uff0c\u81ea\u52a8\u91cd\u542f worker \u8fdb\u7a0b
\n6.Worker \u8fdb\u7a0b\uff1a\u6240\u6709 Worker \u8fdb\u7a0b\u90fd\u662f\u5e73\u7b49\u7684
\n7.\u5b9e\u9645\u5904\u7406\uff1a\u7f51\u7edc\u8bf7\u6c42\uff0c\u7531 Worker \u8fdb\u7a0b\u5904\u7406\uff1b
\n8.Worker \u8fdb\u7a0b\u6570\u91cf\uff1a\u5728 nginx.conf \u4e2d\u914d\u7f6e\uff0c\u4e00\u822c\u8bbe\u7f6e\u4e3a\u6838\u5fc3\u6570\uff0c\u5145\u5206\u5229\u7528 CPU \u8d44\u6e90\uff0c\u540c\u65f6\uff0c\u907f\u514d\u8fdb\u7a0b\u6570\u91cf\u8fc7\u591a\uff0c\u907f\u514d\u8fdb\u7a0b\u7ade\u4e89 CPU \u8d44\u6e90\uff0c\u589e\u52a0\u4e0a\u4e0b\u6587\u5207\u6362\u7684\u635f\u8017\u3002<\/p>\n

\u601d\u8003\uff1a<\/strong><\/div>\n

1.\u8bf7\u6c42\u662f\u8fde\u63a5\u5230 Nginx\uff0cMaster \u8fdb\u7a0b\u8d1f\u8d23\u5904\u7406\u548c\u8f6c\u53d1\uff1f
\n2.\u5982\u4f55\u9009\u5b9a\u54ea\u4e2a Worker \u8fdb\u7a0b\u5904\u7406\u8bf7\u6c42\uff1f\u8bf7\u6c42\u7684\u5904\u7406\u7ed3\u679c\uff0c\u662f\u5426\u8fd8\u8981\u7ecf\u8fc7 Master \u8fdb\u7a0b\uff1f
\n\"\"<\/p>\n

HTTP \u8fde\u63a5\u5efa\u7acb\u548c\u8bf7\u6c42\u5904\u7406\u8fc7\u7a0b<\/strong><\/div>\n

1.Nginx \u542f\u52a8\u65f6\uff0cMaster \u8fdb\u7a0b\uff0c\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6
\n2.Master \u8fdb\u7a0b\uff0c\u521d\u59cb\u5316\u76d1\u542c\u7684 socket
\n3.Master \u8fdb\u7a0b\uff0cfork \u51fa\u591a\u4e2a Worker \u8fdb\u7a0b
\n4.Worker \u8fdb\u7a0b\uff0c\u7ade\u4e89\u65b0\u7684\u8fde\u63a5\uff0c\u83b7\u80dc\u65b9\u901a\u8fc7\u4e09\u6b21\u63e1\u624b\uff0c\u5efa\u7acb Socket \u8fde\u63a5\uff0c\u5e76\u5904\u7406\u8bf7\u6c42<\/p>\n

Nginx \u9ad8\u6027\u80fd\u3001\u9ad8\u5e76\u53d1<\/strong><\/div>\n

1.Nginx \u91c7\u7528\uff1a\u591a\u8fdb\u7a0b + \u5f02\u6b65\u975e\u963b\u585e\u65b9\u5f0f\uff08IO \u591a\u8def\u590d\u7528 epoll\uff09
\n2.\u8bf7\u6c42\u7684\u5b8c\u6574\u8fc7\u7a0b\uff1a
\n3.\u5efa\u7acb\u8fde\u63a5
\n4.\u8bfb\u53d6\u8bf7\u6c42\uff1a\u89e3\u6790\u8bf7\u6c42
\n5.\u5904\u7406\u8bf7\u6c42
\n6.\u54cd\u5e94\u8bf7\u6c42
\n7.\u8bf7\u6c42\u7684\u5b8c\u6574\u8fc7\u7a0b\uff0c\u5bf9\u5e94\u5230\u5e95\u5c42\uff0c\u5c31\u662f\uff1a\u8bfb\u5199 socket \u4e8b\u4ef6<\/p>\n

Nginx \u7684\u4e8b\u4ef6\u5904\u7406\u6a21\u578b<\/strong><\/div>\n

request\uff1aNginx \u4e2d http \u8bf7\u6c42\u3002<\/p>\n

\u57fa\u672c\u7684 HTTP Web Server \u5de5\u4f5c\u6a21\u5f0f\uff1a<\/p>\n

1.\u63a5\u6536\u8bf7\u6c42\uff1a\u9010\u884c\u8bfb\u53d6\u8bf7\u6c42\u884c\u548c\u8bf7\u6c42\u5934\uff0c\u5224\u65ad\u6bb5\u6709\u8bf7\u6c42\u4f53\u540e\uff0c\u8bfb\u53d6\u8bf7\u6c42\u4f53
\n2.\u5904\u7406\u8bf7\u6c42
\n3.\u8fd4\u56de\u54cd\u5e94\uff1a\u6839\u636e\u5904\u7406\u7ed3\u679c\uff0c\u751f\u6210\u76f8\u5e94\u7684 HTTP \u8bf7\u6c42\uff08\u54cd\u5e94\u884c\u3001\u54cd\u5e94\u5934\u3001\u54cd\u5e94\u4f53\uff09
\nNginx \u4e5f\u662f\u8fd9\u4e2a\u5957\u8def\uff0c\u6574\u4f53\u6d41\u7a0b\u4e00\u81f4\u3002<\/p>\n

\"\"<\/p>\n

\u6a21\u5757\u5316\u4f53\u7cfb\u7ed3\u6784<\/strong><\/div>\n

\"\"<\/p>\n

nginx\u7684\u6a21\u5757\u6839\u636e\u5176\u529f\u80fd\u57fa\u672c\u4e0a\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u51e0\u79cd\u7c7b\u578b\uff1a<\/strong><\/div>\n

1.event module: \u642d\u5efa\u4e86\u72ec\u7acb\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u7684\u4e8b\u4ef6\u5904\u7406\u673a\u5236\u7684\u6846\u67b6\uff0c\u53ca\u63d0\u4f9b\u4e86\u5404\u5177\u4f53\u4e8b\u4ef6\u7684\u5904\u7406\u3002\u5305\u62ecngx_events_module\uff0c ngx_event_core_module\u548cngx_epoll_module\u7b49\u3002nginx\u5177\u4f53\u4f7f\u7528\u4f55\u79cd\u4e8b\u4ef6\u5904\u7406\u6a21\u5757\uff0c\u8fd9\u4f9d\u8d56\u4e8e\u5177\u4f53\u7684\u64cd\u4f5c\u7cfb\u7edf\u548c\u7f16\u8bd1\u9009\u9879\u3002
\n2.phase handler: \u6b64\u7c7b\u578b\u7684\u6a21\u5757\u4e5f\u88ab\u76f4\u63a5\u79f0\u4e3ahandler\u6a21\u5757\u3002\u4e3b\u8981\u8d1f\u8d23\u5904\u7406\u5ba2\u6237\u7aef\u8bf7\u6c42\u5e76\u4ea7\u751f\u5f85\u54cd\u5e94\u5185\u5bb9\uff0c\u6bd4\u5982ngx_http_static_module\u6a21\u5757\uff0c\u8d1f\u8d23\u5ba2\u6237\u7aef\u7684\u9759\u6001\u9875\u9762\u8bf7\u6c42\u5904\u7406\u5e76\u5c06\u5bf9\u5e94\u7684\u78c1\u76d8\u6587\u4ef6\u51c6\u5907\u4e3a\u54cd\u5e94\u5185\u5bb9\u8f93\u51fa\u3002
\n3.output filter: \u4e5f\u79f0\u4e3afilter\u6a21\u5757\uff0c\u4e3b\u8981\u662f\u8d1f\u8d23\u5bf9\u8f93\u51fa\u7684\u5185\u5bb9\u8fdb\u884c\u5904\u7406\uff0c\u53ef\u4ee5\u5bf9\u8f93\u51fa\u8fdb\u884c\u4fee\u6539\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5bf9\u8f93\u51fa\u7684\u6240\u6709html\u9875\u9762\u589e\u52a0\u9884\u5b9a\u4e49\u7684footbar\u4e00\u7c7b\u7684\u5de5\u4f5c\uff0c\u6216\u8005\u5bf9\u8f93\u51fa\u7684\u56fe\u7247\u7684URL\u8fdb\u884c\u66ff\u6362\u4e4b\u7c7b\u7684\u5de5\u4f5c\u3002
\n4.upstream: upstream\u6a21\u5757\u5b9e\u73b0\u53cd\u5411\u4ee3\u7406\u7684\u529f\u80fd\uff0c\u5c06\u771f\u6b63\u7684\u8bf7\u6c42\u8f6c\u53d1\u5230\u540e\u7aef\u670d\u52a1\u5668\u4e0a\uff0c\u5e76\u4ece\u540e\u7aef\u670d\u52a1\u5668\u4e0a\u8bfb\u53d6\u54cd\u5e94\uff0c\u53d1\u56de\u5ba2\u6237\u7aef\u3002upstream\u6a21\u5757\u662f\u4e00\u79cd\u7279\u6b8a\u7684handler\uff0c\u53ea\u4e0d\u8fc7\u54cd\u5e94\u5185\u5bb9\u4e0d\u662f\u771f\u6b63\u7531\u81ea\u5df1\u4ea7\u751f\u7684\uff0c\u800c\u662f\u4ece\u540e\u7aef\u670d\u52a1\u5668\u4e0a\u8bfb\u53d6\u7684\u3002
\n5.load-balancer: \u8d1f\u8f7d\u5747\u8861\u6a21\u5757\uff0c\u5b9e\u73b0\u7279\u5b9a\u7684\u7b97\u6cd5\uff0c\u5728\u4f17\u591a\u7684\u540e\u7aef\u670d\u52a1\u5668\u4e2d\uff0c\u9009\u62e9\u4e00\u4e2a\u670d\u52a1\u5668\u51fa\u6765\u4f5c\u4e3a\u67d0\u4e2a\u8bf7\u6c42\u7684\u8f6c\u53d1\u670d\u52a1\u5668\u3002<\/p>\n

\u5e38\u89c1\u95ee\u9898\u5256\u6790
\nNginx vs. Apache
\n<\/strong><\/div>\n

\u7f51\u7edc IO \u6a21\u578b\uff1a<\/p>\n

1.nginx\uff1aIO \u591a\u8def\u590d\u7528\uff0cepoll(freebsd \u4e0a\u662f kqueue )
\n2.\u9ad8\u6027\u80fd
\n3.\u9ad8\u5e76\u53d1
\n4.\u5360\u7528\u7cfb\u7edf\u8d44\u6e90\u5c11
\n5.apache\uff1a\u963b\u585e + \u591a\u8fdb\u7a0b\/\u591a\u7ebf\u7a0b
\n6.\u66f4\u7a33\u5b9a\uff0cbug \u5c11
\n7.\u6a21\u5757\u66f4\u4e30\u5bcc<\/p>\n

\u573a\u666f\uff1a<\/strong><\/div>\n

\u5904\u7406\u591a\u4e2a\u8bf7\u6c42\u65f6\uff0c\u53ef\u4ee5\u91c7\u7528\uff1aIO \u591a\u8def\u590d\u7528 \u6216\u8005 \u963b\u585e IO +\u591a\u7ebf\u7a0b<\/p>\n

IO \u591a\u8def\u670d\u7528\uff1a\u4e00\u4e2a \u7ebf\u7a0b\uff0c\u8ddf\u8e2a\u591a\u4e2a socket \u72b6\u6001\uff0c\u54ea\u4e2a\u5c31\u7eea\uff0c\u5c31\u8bfb\u5199\u54ea\u4e2a\uff1b
\n\u963b\u585e IO + \u591a\u7ebf\u7a0b\uff1a\u6bcf\u4e00\u4e2a\u8bf7\u6c42\uff0c\u65b0\u5efa\u4e00\u4e2a\u670d\u52a1\u7ebf\u7a0b<\/p>\n

\u601d\u8003\uff1aIO \u591a\u8def\u590d\u7528 \u548c \u591a\u7ebf\u7a0b \u7684\u9002\u7528\u573a\u666f\uff1f<\/strong><\/div>\n

IO \u591a\u8def\u590d\u7528\uff1a\u5355\u4e2a\u8fde\u63a5\u7684\u8bf7\u6c42\u5904\u7406\u901f\u5ea6\u6ca1\u6709\u4f18\u52bf\uff0c\u9002\u5408 IO \u5bc6\u96c6\u578b \u573a\u666f\uff0c\u4e8b\u4ef6\u9a71\u52a8
\n\u5927\u5e76\u53d1\u91cf\uff1a\u53ea\u4f7f\u7528\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u5904\u7406\u5927\u91cf\u7684\u5e76\u53d1\u8bf7\u6c42\uff0c\u964d\u4f4e\u4e0a\u4e0b\u6587\u73af\u5883\u5207\u6362\u635f\u8017\uff0c\u4e5f\u4e0d\u9700\u8981\u8003\u8651\u5e76\u53d1\u95ee\u9898\uff0c\u76f8\u5bf9\u53ef\u4ee5\u5904\u7406\u66f4\u591a\u7684\u8bf7\u6c42\uff1b
\n\u6d88\u8017\u66f4\u5c11\u7684\u7cfb\u7edf\u8d44\u6e90\uff08\u4e0d\u9700\u8981\u7ebf\u7a0b\u8c03\u5ea6\u5f00\u9500\uff09
\n\u9002\u7528\u4e8e\u957f\u8fde\u63a5\u7684\u60c5\u51b5\uff08\u591a\u7ebf\u7a0b\u6a21\u5f0f\u957f\u8fde\u63a5\u5bb9\u6613\u9020\u6210\u7ebf\u7a0b\u8fc7\u591a\uff0c\u9020\u6210\u9891\u7e41\u8c03\u5ea6\uff09
\n\u963b\u585eIO + \u591a\u7ebf\u7a0b\uff1a\u5b9e\u73b0\u7b80\u5355\uff0c\u53ef\u4ee5\u4e0d\u4f9d\u8d56\u7cfb\u7edf\u8c03\u7528\uff0c\u9002\u5408 CPU \u5bc6\u96c6\u578b \u573a\u666f
\n\u6bcf\u4e2a\u7ebf\u7a0b\uff0c\u90fd\u9700\u8981\u65f6\u95f4\u548c\u7a7a\u95f4\uff1b
\n\u7ebf\u7a0b\u6570\u91cf\u589e\u957f\u65f6\uff0c\u7ebf\u7a0b\u8c03\u5ea6\u5f00\u9500\u6307\u6570\u589e\u957f<\/p>\n

Nginx \u6700\u5927\u8fde\u63a5\u6570<\/strong><\/div>\n
\u57fa\u7840\u80cc\u666f\uff1a<\/strong><\/span><\/div>\n

1.Nginx \u662f\u591a\u8fdb\u7a0b\u6a21\u578b\uff0cWorker \u8fdb\u7a0b\u7528\u4e8e\u5904\u7406\u8bf7\u6c42\uff1b
\n2.\u5355\u4e2a\u8fdb\u7a0b\u7684\u8fde\u63a5\u6570\uff08\u6587\u4ef6\u63cf\u8ff0\u7b26 fd\uff09\uff0c\u6709\u4e0a\u9650\uff08nofile\uff09\uff1aulimit -n
\n3.Nginx \u4e0a\u914d\u7f6e\u5355\u4e2a worker \u8fdb\u7a0b\u7684\u6700\u5927\u8fde\u63a5\u6570\uff1aworker_connections \u4e0a\u9650\u4e3a nofile
\n4.Nginx \u4e0a\u914d\u7f6e worker \u8fdb\u7a0b\u7684\u6570\u91cf\uff1aworker_processes<\/p>\n

\u56e0\u6b64\uff0cNginx \u7684\u6700\u5927\u8fde\u63a5\u6570\uff1a<\/strong><\/span><\/div>\n

1.Nginx \u7684\u6700\u5927\u8fde\u63a5\u6570\uff1aWorker \u8fdb\u7a0b\u6570\u91cf x \u5355\u4e2a Worker \u8fdb\u7a0b\u7684\u6700\u5927\u8fde\u63a5\u6570
\n2.\u4e0a\u9762\u662f Nginx \u4f5c\u4e3a\u901a\u7528\u670d\u52a1\u5668\u65f6\uff0c\u6700\u5927\u7684\u8fde\u63a5\u6570
\n3.Nginx \u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u65f6\uff0c\u80fd\u591f\u670d\u52a1\u7684\u6700\u5927\u8fde\u63a5\u6570\uff1a\uff08Worker \u8fdb\u7a0b\u6570\u91cf x \u5355\u4e2a Worker \u8fdb\u7a0b\u7684\u6700\u5927\u8fde\u63a5\u6570\uff09\/ 2\u3002
\n4.Nginx \u53cd\u5411\u4ee3\u7406\u65f6\uff0c\u4f1a\u5efa\u7acb Client \u7684\u8fde\u63a5\u548c\u540e\u7aef Web Server \u7684\u8fde\u63a5\uff0c\u5360\u7528 2 \u4e2a\u8fde\u63a5<\/p>\n

\u601d\u8003\uff1a<\/strong><\/div>\n

\u6bcf\u6253\u5f00\u4e00\u4e2a socket \u5360\u7528\u4e00\u4e2a fd<\/p>\n

\u4e3a\u4ec0\u4e48\uff0c\u4e00\u4e2a\u8fdb\u7a0b\u80fd\u591f\u6253\u5f00\u7684 fd \u6570\u91cf\u6709\u9650\u5236\uff1f<\/p>\n

IO \u6a21\u578b<\/strong><\/div>\n
\u573a\u666f\uff1a<\/strong><\/span><\/div>\n

\u5904\u7406\u591a\u4e2a\u8bf7\u6c42\u65f6\uff0c\u53ef\u4ee5\u91c7\u7528\uff1aIO \u591a\u8def\u590d\u7528 \u6216\u8005 \u963b\u585e IO +\u591a\u7ebf\u7a0b<\/p>\n

IO \u591a\u8def\u590d\u7528\uff1a\u4e00\u4e2a \u7ebf\u7a0b\uff0c\u8ddf\u8e2a\u591a\u4e2a socket \u72b6\u6001\uff0c\u54ea\u4e2a\u5c31\u7eea\uff0c\u5c31\u8bfb\u5199\u54ea\u4e2a\uff1b
\n\u963b\u585e IO + \u591a\u7ebf\u7a0b\uff1a\u6bcf\u4e00\u4e2a\u8bf7\u6c42\uff0c\u65b0\u5efa\u4e00\u4e2a\u670d\u52a1\u7ebf\u7a0b<\/p>\n

\u601d\u8003\uff1a
\nIO \u591a\u8def\u590d\u7528 \u548c \u591a\u7ebf\u7a0b \u7684\u9002\u7528\u573a\u666f\uff1f
\n<\/strong><\/span><\/div>\n

IO \u591a\u8def\u590d\u7528\uff1a\u5355\u4e2a\u8fde\u63a5\u7684\u8bf7\u6c42\u5904\u7406\u901f\u5ea6\u6ca1\u6709\u4f18\u52bf
\n\u5927\u5e76\u53d1\u91cf\uff1a\u53ea\u4f7f\u7528\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u5904\u7406\u5927\u91cf\u7684\u5e76\u53d1\u8bf7\u6c42\uff0c\u964d\u4f4e\u4e0a\u4e0b\u6587\u73af\u5883\u5207\u6362\u635f\u8017\uff0c\u4e5f\u4e0d\u9700\u8981\u8003\u8651\u5e76\u53d1\u95ee\u9898\uff0c\u76f8\u5bf9\u53ef\u4ee5\u5904\u7406\u66f4\u591a\u7684\u8bf7\u6c42\uff1b
\n\u6d88\u8017\u66f4\u5c11\u7684\u7cfb\u7edf\u8d44\u6e90\uff08\u4e0d\u9700\u8981\u7ebf\u7a0b\u8c03\u5ea6\u5f00\u9500\uff09
\n\u9002\u7528\u4e8e\u957f\u8fde\u63a5\u7684\u60c5\u51b5\uff08\u591a\u7ebf\u7a0b\u6a21\u5f0f\u957f\u8fde\u63a5\u5bb9\u6613\u9020\u6210\u7ebf\u7a0b\u8fc7\u591a\uff0c\u9020\u6210\u9891\u7e41\u8c03\u5ea6\uff09
\n\u963b\u585eIO + \u591a\u7ebf\u7a0b\uff1a\u5b9e\u73b0\u7b80\u5355\uff0c\u53ef\u4ee5\u4e0d\u4f9d\u8d56\u7cfb\u7edf\u8c03\u7528\u3002
\n\u6bcf\u4e2a\u7ebf\u7a0b\uff0c\u90fd\u9700\u8981\u65f6\u95f4\u548c\u7a7a\u95f4\uff1b
\n\u7ebf\u7a0b\u6570\u91cf\u589e\u957f\u65f6\uff0c\u7ebf\u7a0b\u8c03\u5ea6\u5f00\u9500\u6307\u6570\u589e\u957f<\/p>\n

select\/poll \u548c epoll \u6bd4\u8f83<\/strong><\/div>\n

\u8be6\u7ec6\u5185\u5bb9\uff0c\u53c2\u8003\uff1a<\/p>\n

select poll epoll\u4e09\u8005\u4e4b\u95f4\u7684\u6bd4\u8f83<\/strong><\/span><\/div>\n

select\/poll \u7cfb\u7edf\u8c03\u7528\uff1a<\/p>\n

\/\/ select \u7cfb\u7edf\u8c03\u7528 \r\n \r\nint select(int maxfdp,fd_set *readfds,fd_set *writefds,fd_set *errorfds,struct timeval *timeout); \r\n \r\n\/\/ poll \u7cfb\u7edf\u8c03\u7528 \r\n \r\nint poll(struct pollfd fds[], nfds_t nfds, int timeout)\uff1b<\/pre>\n
select\uff1a<\/strong><\/span><\/div>\n

\u67e5\u8be2 fd_set \u4e2d\uff0c\u662f\u5426\u6709\u5c31\u7eea\u7684 fd\uff0c\u53ef\u4ee5\u8bbe\u5b9a\u4e00\u4e2a\u8d85\u65f6\u65f6\u95f4\uff0c\u5f53\u6709 fd (File descripter) \u5c31\u7eea\u6216\u8d85\u65f6\u8fd4\u56de\uff1b
\nfd_set \u662f\u4e00\u4e2a\u4f4d\u96c6\u5408\uff0c\u5927\u5c0f\u662f\u5728\u7f16\u8bd1\u5185\u6838\u65f6\u7684\u5e38\u91cf\uff0c\u9ed8\u8ba4\u5927\u5c0f\u4e3a 1024
\n\u7279\u70b9\uff1a
\n\u8fde\u63a5\u6570\u9650\u5236\uff0cfd_set \u53ef\u8868\u793a\u7684 fd \u6570\u91cf\u592a\u5c0f\u4e86\uff1b
\n\u7ebf\u6027\u626b\u63cf\uff1a\u5224\u65ad fd \u662f\u5426\u5c31\u7eea\uff0c\u9700\u8981\u904d\u5386\u4e00\u8fb9 fd_set\uff1b
\n\u6570\u636e\u590d\u5236\uff1a\u7528\u6237\u7a7a\u95f4\u548c\u5185\u6838\u7a7a\u95f4\uff0c\u590d\u5236\u8fde\u63a5\u5c31\u7eea\u72b6\u6001\u4fe1\u606f<\/p>\n

poll\uff1a<\/strong><\/span><\/div>\n

\u89e3\u51b3\u4e86\u8fde\u63a5\u6570\u9650\u5236\uff1a
\npoll \u4e2d\u5c06 select \u4e2d\u7684 fd_set \u66ff\u6362\u6210\u4e86\u4e00\u4e2a pollfd \u6570\u7ec4
\n\u89e3\u51b3 fd \u6570\u91cf\u8fc7\u5c0f\u7684\u95ee\u9898
\n\u6570\u636e\u590d\u5236\uff1a\u7528\u6237\u7a7a\u95f4\u548c\u5185\u6838\u7a7a\u95f4\uff0c\u590d\u5236\u8fde\u63a5\u5c31\u7eea\u72b6\u6001\u4fe1\u606f
\nepoll\uff1aevent \u4e8b\u4ef6\u9a71\u52a8<\/p>\n

epoll\uff1aevent \u4e8b\u4ef6\u9a71\u52a8<\/strong><\/span><\/div>\n

\u4e8b\u4ef6\u673a\u5236\uff1a\u907f\u514d\u7ebf\u6027\u626b\u63cf
\n\u4e3a\u6bcf\u4e2a fd\uff0c\u6ce8\u518c\u4e00\u4e2a\u76d1\u542c\u4e8b\u4ef6
\nfd \u53d8\u66f4\u4e3a\u5c31\u7eea\u65f6\uff0c\u5c06 fd \u6dfb\u52a0\u5230\u5c31\u7eea\u94fe\u8868
\nfd \u6570\u91cf\uff1a\u65e0\u9650\u5236\uff08OS \u7ea7\u522b\u7684\u9650\u5236\uff0c\u5355\u4e2a\u8fdb\u7a0b\u80fd\u6253\u5f00\u591a\u5c11\u4e2a fd\uff09<\/p>\n

select\uff0cpoll\uff0cepoll\uff1a<\/strong><\/span><\/div>\n

1.I\/O\u591a\u8def\u590d\u7528\u7684\u673a\u5236\uff1b
\n2.I\/O\u591a\u8def\u590d\u7528\u5c31\u901a\u8fc7\u4e00\u79cd\u673a\u5236\uff0c\u53ef\u4ee5\u76d1\u89c6\u591a\u4e2a\u63cf\u8ff0\u7b26\uff0c\u4e00\u65e6\u67d0\u4e2a\u63cf\u8ff0\u7b26\u5c31\u7eea\uff08\u4e00\u822c\u662f\u8bfb\u5c31\u7eea\u6216\u8005\u5199\u5c31\u7eea\uff09\uff0c\u80fd\u591f\u901a\u77e5\u7a0b\u5e8f\u8fdb\u884c\u76f8\u5e94\u7684\u8bfb\u5199\u64cd\u4f5c\u3002
\n3.\u76d1\u89c6\u591a\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26
\n4.\u4f46select\uff0cpoll\uff0cepoll\u672c\u8d28\u4e0a\u90fd\u662f\u540c\u6b65I\/O\uff1a
\n5.\u7528\u6237\u8fdb\u7a0b\u8d1f\u8d23\u8bfb\u5199\uff08\u4ece\u5185\u6838\u7a7a\u95f4\u62f7\u8d1d\u5230\u7528\u6237\u7a7a\u95f4\uff09\uff0c\u8bfb\u5199\u8fc7\u7a0b\u4e2d\uff0c\u7528\u6237\u8fdb\u7a0b\u662f\u963b\u585e\u7684\uff1b
\n6.\u5f02\u6b65 IO\uff0c\u65e0\u9700\u7528\u6237\u8fdb\u7a0b\u8d1f\u8d23\u8bfb\u5199\uff0c\u5f02\u6b65IO\uff0c\u4f1a\u8d1f\u8d23\u4ece\u5185\u6838\u7a7a\u95f4\u62f7\u8d1d\u5230\u7528\u6237\u7a7a\u95f4\uff1b<\/p>\n

Nginx \u7684\u5e76\u53d1\u5904\u7406\u80fd\u529b<\/strong><\/div>\n

\u5173\u4e8e Nginx \u7684\u5e76\u53d1\u5904\u7406\u80fd\u529b<\/p>\n

\u5e76\u53d1\u8fde\u63a5\u6570\uff0c\u4e00\u822c\u4f18\u5316\u540e\uff0c\u5cf0\u503c\u80fd\u4fdd\u6301\u5728 1~3w \u5de6\u53f3\u3002\uff08\u5185\u5b58\u548c CPU \u6838\u5fc3\u6570\u4e0d\u540c\uff0c\u4f1a\u6709\u8fdb\u4e00\u6b65\u4f18\u5316\u7a7a\u95f4\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"

1.\u591a\u8fdb\u7a0b\uff1a\u4e00\u4e2a Master \u8fdb\u7a0b\u3001\u591a\u4e2a Worker \u8fdb\u7a0b 2.Master \u8fdb\u7a0b\uff1a\u7ba1\u7406 Worker \u8fdb […]<\/p>\n","protected":false},"author":1469,"featured_media":170427,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-170426","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/170426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1469"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=170426"}],"version-history":[{"count":5,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/170426\/revisions"}],"predecessor-version":[{"id":171528,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/170426\/revisions\/171528"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/170427"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=170426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=170426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=170426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}