{"id":476,"date":"2016-02-06T02:35:14","date_gmt":"2016-02-05T18:35:14","guid":{"rendered":"http:\/\/carlos.aboutme.com.hk\/blog\/?p=476"},"modified":"2016-02-07T00:40:05","modified_gmt":"2016-02-06T16:40:05","slug":"web-service-load-balancing","status":"publish","type":"post","link":"https:\/\/carlos.aboutmy.info\/blog\/?p=476","title":{"rendered":"Web Service Load Balancing"},"content":{"rendered":"<p>\u800c\u5bb6 RESTful web service \u53ca AJAX \u6d41\u884c\uff0cserver \u540c client \u591a\u6578\u7528 JSON \/ Protocol buffers \u4ea4\u63db\u8cc7\u6599\u3002Server side \u5c0d Java EE \/ J2EE \u9700\u6c42\u5927\u6e1b\uff0c\u7279\u5225\u662f mobile Apps\uff0c\u66f4\u672c\u7528\u4e0d\u8457 Java EE\uff0c\u504f\u5411\u7528 Node.js \u6216 Python \u6216 Go \u4f86\u505a server API\u3002\u7531\u65bc\u5728 web API \u505a multi-thread \u6703\u5f88\u9ebb\u7169\uff0c\u82b1\u5927\u91cf\u6642\u9593\u505a development \u53ca testing\uff0c\u800c\u57fa\u65bc JavaScript \u7684 Node.js \u66f4\u52a0\u6c92\u6709 multithreading\uff0c\u800c\u662f\u7528 callback\u3002<\/p>\n<p>\u5982\u679c\u60f3\u7528\u76e1 CPU cores\uff0c\u6700\u5bb9\u6613\u7684\u65b9\u6cd5\u662f\u628a\u7528 Node.js \u6216 Python \u6216 Go \u5beb\u6210\u7684 web API start \u591a\u500b\u6b21\uff0c\u4e0d\u540c instances listen \u4e0d\u540c\u7684 ports (e.g. 8080, 8081, 8082, etc)\u3002\u518d\u5728\u524d\u9762\u52a0\u4e00\u5c64 web service (listen 80) \u505a load balancing\u3002<\/p>\n<p><strong>Apache HTTP Server<\/strong><\/p>\n<p>BalancerMember http:\/\/127.0.0.1:8080<br \/>\nBalancerMember http:\/\/127.0.0.1:8081<br \/>\nBalancerMember http:\/\/127.0.0.1:8082<\/p>\n<p>ProxyPass \/hello_world balancer:\/\/app_servers\/hello_world<\/p>\n<p><strong>nginx<\/strong><\/p>\n<p>upstream app_servers {<br \/>\nserver 127.0.0.1:8080;<br \/>\nserver 127.0.0.1:8081;<br \/>\nserver 127.0.0.1:8082;<br \/>\n}<\/p>\n<p>location \/hello_world {<br \/>\nproxy_pass http:\/\/app_servers\/hello_world;<br \/>\n}<\/p>\n<p>\u7576\u7136\uff0cweb API \u53ef\u4ee5\u5728\u5176\u4ed6\u96fb\u8166 run\uff0c\u53ea\u8981\u628a 127.0.0.1 \u6539\u63db\u4fbf\u53ef\u3002\u9054\u5230\u5206\u6563 work load\uff0c\u52a0\u5927\u4e86 server \u8ca0\u8377\u53ca\u901f\u5ea6\u3002\u6b64 load balancing \u7531\u65bc\u53ea\u662f\u9806\u4f4f\u5206\u767c requests\uff0c\u4e26\u6c92\u6709\u8003\u616e\u5404 instances \u7684\u8ca0\u8377\u3002\u5c31\u5982 supervisor \u5206\u767c\u5de5\u4f5c (requests) \u7d66\u54e1\u5de5 (instances)\uff0c\u800c\u6c92\u6709\u7406\u6703\u54e1\u5de5\u6709\u6c92\u6709\u7a7a\u9592\u4e00\u6a23\u3002\u8981\u505a\u5230\u5f97\u9592\u7684\u54e1\u5de5 (instances) \u4e3b\u52d5\u63a5 job (requests)\uff0c\u90a3\u5c31\u8981\u7528\u5230 message queue \u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u800c\u5bb6 RESTful web service \u53ca AJAX \u6d41\u884c\uff0cserver \u540c client \u591a\u6578\u7528 JSON \/ Protocol buffers \u4ea4\u63db\u8cc7\u6599\u3002Server side \u5c0d Java EE \/ J2EE \u9700\u6c42\u5927\u6e1b\uff0c\u7279\u5225\u662f mobile Apps\uff0c\u66f4\u672c\u7528\u4e0d\u8457 Java EE\uff0c\u504f\u5411\u7528 Node.js \u6216 Python \u6216 Go \u4f86\u505a server API\u3002\u7531\u65bc\u5728 web API \u505a multi-thread \u6703\u5f88\u9ebb\u7169\uff0c\u82b1\u5927\u91cf\u6642\u9593\u505a development \u53ca testing\uff0c\u800c\u57fa\u65bc JavaScript \u7684 Node.js \u66f4\u52a0\u6c92\u6709 multithreading\uff0c\u800c\u662f\u7528 callback\u3002 \u5982\u679c\u60f3\u7528\u76e1 CPU cores\uff0c\u6700\u5bb9\u6613\u7684\u65b9\u6cd5\u662f\u628a\u7528 Node.js \u6216 Python \u6216\u2026 <span class=\"read-more\"><a href=\"https:\/\/carlos.aboutmy.info\/blog\/?p=476\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/476"}],"collection":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=476"}],"version-history":[{"count":2,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/476\/revisions"}],"predecessor-version":[{"id":478,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/476\/revisions\/478"}],"wp:attachment":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}