{"id":50,"date":"2017-05-02T23:09:24","date_gmt":"2017-05-02T15:09:24","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=50"},"modified":"2018-11-27T15:53:36","modified_gmt":"2018-11-27T07:53:36","slug":"%e4%bd%bf%e7%94%a8locust%e8%bf%9b%e8%a1%8c%e5%8e%8b%e5%8a%9b%e6%b5%8b%e8%af%95","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=50","title":{"rendered":"\u4f7f\u7528locust\u8fdb\u884c\u538b\u529b\u6d4b\u8bd5"},"content":{"rendered":"<ul>\n<li>\n<h1><strong><a href=\"https:\/\/locust.io\/\" target=\"_blank\" rel=\"noopener\">locust\u5b98\u65b9\u94fe\u63a5<\/a><\/strong><\/h1>\n<h2>\u4ec0\u4e48\u662flocust\uff1f<\/h2>\n<p>Locust\u662f\u4e00\u6b3e\u6613\u4e8e\u4f7f\u7528\u7684\u5206\u5e03\u5f0f\u7528\u6237\u8d1f\u8f7d\u6d4b\u8bd5\u5de5\u5177\u3002\u5b83\u7528\u4e8e\u5bf9\u7f51\u7ad9\uff08\u6216\u5176\u4ed6\u7cfb\u7edf\uff09\u8fdb\u884c\u8d1f\u8f7d\u6d4b\u8bd5\uff0c\u5e76\u786e\u5b9a\u7cfb\u7edf\u53ef\u4ee5\u5904\u7406\u591a\u5c11\u5e76\u53d1\u7528\u6237\u3002<br \/>\n\u8fd9\u4e2a\u60f3\u6cd5\u662f\uff0c\u5728\u6d4b\u8bd5\u671f\u95f4\uff0c\u4e00\u7fa4\u8757\u866b \u4f1a\u653b\u51fb\u4f60\u7684\u7f51\u7ad9\u3002\u60a8\u5b9a\u4e49\u4e86\u6bcf\u4e2a\u8757\u866b\uff08\u6216\u6d4b\u8bd5\u7528\u6237\uff0c\u5982\u679c\u60a8\u613f\u610f\uff09\u7684\u884c\u4e3a\uff0c\u5e76\u4e14\u5b9e\u65f6\u5730\u4eceWeb UI\u76d1\u89c6\u7fa4\u96c6\u8fc7\u7a0b\u3002\u8fd9\u5c06\u6709\u52a9\u4e8e\u60a8\u5728\u8ba9\u771f\u6b63\u7684\u7528\u6237\u8fdb\u5165\u4e4b\u524d\u8fdb\u884c\u6d4b\u8bd5\u5e76\u8bc6\u522b\u4ee3\u7801\u4e2d\u7684\u74f6\u9888\u3002<br \/>\nLocust\u5b8c\u5168\u57fa\u4e8e\u4e8b\u4ef6\uff0c\u56e0\u6b64\u53ef\u4ee5\u5728\u4e00\u53f0\u8ba1\u7b97\u673a\u4e0a\u652f\u6301\u6570\u5343\u4e2a\u5e76\u53d1\u7528\u6237\u3002\u4e0e\u8bb8\u591a\u5176\u4ed6\u57fa\u4e8e\u4e8b\u4ef6\u7684\u5e94\u7528\u7a0b\u5e8f\u76f8\u6bd4\uff0c\u5b83\u4e0d\u4f7f\u7528\u56de\u8c03\u3002\u76f8\u53cd\uff0c\u5b83\u901a\u8fc7gevent\u4f7f\u7528\u8f7b\u91cf\u7ea7\u8fc7\u7a0b\u3002\u6bcf\u4e2a\u8757\u866b\u8702\u62e5\u5230\u4f60\u7684\u7f51\u7ad9\u5b9e\u9645\u4e0a\u662f\u5728\u81ea\u5df1\u7684\u8fdb\u7a0b\u5185\u8fd0\u884c\uff08\u6216\u8005\u662fgreenlet\uff0c\u8fd9\u662f\u6b63\u786e\u7684\uff09\u3002\u8fd9\u5141\u8bb8\u60a8\u5728Py\u200b\u200bthon\u4e2d\u7f16\u5199\u975e\u5e38\u5bcc\u6709\u8868\u73b0\u529b\u7684\u573a\u666f\uff0c\u800c\u4e0d\u4f1a\u4f7f\u4ee3\u7801\u590d\u6742\u5316\u3002<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<p>&nbsp;<\/p>\n<h2>\u793a\u4f8b:<\/h2>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom locust import HttpLocust, TaskSet, task\r\n\r\nclass MyTaskSet(TaskSet):\r\n    @task(2)\r\n    def index(self):\r\n        self.client.get(&quot;\/&quot;)\r\n\r\n    @task(1)\r\n    def about(self):\r\n        self.client.get(&quot;\/about\/&quot;)\r\n\r\nclass MyLocust(HttpLocust):\r\n    task_set = MyTaskSet\r\n    min_wait = 5000\r\n    max_wait = 15000\r\n<\/pre>\n<p>@task\u91c7\u7528\u53ef\u9009\u7684\u6743\u91cd\u53c2\u6570\uff0c\u53ef\u7528\u4e8e\u6307\u5b9a\u4efb\u52a1\u7684\u6267\u884c\u7387\u3002\u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\uff0ctask2\u7684\u6267\u884c\u6b21\u6570\u662ftask1\u7684\u4e24\u500d\uff1a<br \/>\n\u901a\u5e38\u8fd8\u9700\u8981\u58f0\u660emin_wait\u548cmax_wait \u5c5e\u6027\u3002\u8fd9\u4e9b\u662f\u6a21\u62df\u7528\u6237\u5728\u6267\u884c\u6bcf\u4e2a\u4efb\u52a1\u4e4b\u95f4\u7b49\u5f85\u7684\u6700\u5c0f\u548c\u6700\u5927\u65f6\u95f4\uff08\u4ee5\u6beb\u79d2\u4e3a\u5355\u4f4d\uff09\u3002min_wait\u548cmax_wait\u9ed8\u8ba4\u4e3a1000\uff0c\u56e0\u6b64\u5982\u679c\u672a\u58f0\u660emin_wait\u548cmax_wait\uff0c\u5219\u6bcf\u4e2a\u4efb\u52a1\u4e4b\u95f4\u7684\u8757\u866b\u5c06\u59cb\u7ec8\u7b49\u5f851\u79d2\u3002<\/p>\n<ul>\n<li>\n<h1>\u96c6\u7fa4\u5206\u5e03\u5f0f\u8fd0\u884clocust<\/h1>\n<\/li>\n<\/ul>\n<p>\u4e00\u65e6\u5355\u4e2a\u673a\u5668\u4e0d\u8db3\u4ee5\u6a21\u62df\u60a8\u9700\u8981\u7684\u7528\u6237\u6570\u91cf\uff0cLocust\u5c31\u652f\u6301\u8fd0\u884c\u5206\u5e03\u5728\u591a\u53f0\u673a\u5668\u4e0a\u7684\u8d1f\u8f7d\u6d4b\u8bd5\u3002\u4e3a\u6b64\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528&#8211;master\u6807\u5fd7\u4ee5\u4e3b\u6a21\u5f0f\u542f\u52a8\u4e00\u4e2aLocust\u5b9e\u4f8b\u3002\u8fd9\u662f\u5c06\u8fd0\u884cLocust\u7684Web\u754c\u9762\u7684\u5b9e\u4f8b\uff0c\u60a8\u53ef\u4ee5\u5728\u5176\u4e2d\u542f\u52a8\u6d4b\u8bd5\u5e76\u67e5\u770b\u5b9e\u65f6\u7edf\u8ba1\u4fe1\u606f\u3002\u4e3b\u8282\u70b9\u4e0d\u4f1a\u6a21\u62df\u4efb\u4f55\u7528\u6237\u672c\u8eab\u3002\u76f8\u53cd\uff0c\u60a8\u5fc5\u987b\u4f7f\u7528\u8be5&#8211;slave\u6807\u5fd7\u4ee5\u53ca &#8211;master-host\uff08\u6307\u5b9a\u4e3b\u8282\u70b9\u7684IP \/\u4e3b\u673a\u540d\uff09\u542f\u52a8\u4e00\u4e2a\u6216\u591a\u4e2a\u53ef\u80fd\u7684\u591a\u4e2a\u4ece\u5c5eLocust\u8282\u70b9\u3002\u5e38\u89c1\u7684\u8bbe\u7f6e\u662f\u5728\u4e00\u53f0\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u5355\u4e2a\u4e3b\u670d\u52a1\u5668\uff0c\u7136\u540e\u5728\u4ece\u5c5e\u8ba1\u7b97\u673a\u4e0a\u4e3a\u6bcf\u4e2a\u5904\u7406\u5668\u6838\u5fc3\u8fd0\u884c\u4e00\u4e2a\u4ece\u5c5e\u5b9e\u4f8b\u3002<\/p>\n<p><strong>\u6ce8\u610f<\/strong><\/p>\n<p>\u5728\u8fd0\u884cLocust\u5206\u5e03\u5f0f\u65f6\uff0c\u4e3b\u673a\u548c\u6bcf\u53f0\u4ece\u673a\u90fd\u5fc5\u987b\u6709\u8757\u866b\u6d4b\u8bd5\u811a\u672c\u7684\u526f\u672c\u3002<\/p>\n<h2>\u793a\u4f8b<br \/>\n\u8981\u5728\u4e3b\u6a21\u5f0f\u4e0b\u542f\u52a8\u8757\u866b\uff1a<\/h2>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">locust -f my_locustfile.py --master <\/pre>\n<p>\u7136\u540e\u5728\u6bcf\u4e2a\u4ece\u7ad9\u4e0a\uff08192.168.0.14\u7528\u4e3b\u673a\u7684IP \u66ff\u6362\uff09\uff1a<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">locust -f my_locustfile.py --slave --master-host=192.168.0.14<\/pre>\n<h2>\u53c2\u6570\u89e3\u91ca:<\/h2>\n<p>&#8211;master<br \/>\n\u5728\u4e3b\u6a21\u5f0f\u4e0b\u8bbe\u7f6e\u8757\u866b\u3002Web\u754c\u9762\u5c06\u5728\u6b64\u8282\u70b9\u4e0a\u8fd0\u884c\u3002<\/p>\n<p>&#8211;slave<br \/>\n\u5c06\u8757\u866b\u8bbe\u7f6e\u4e3a\u4ece\u5c5e\u6a21\u5f0f\u3002<\/p>\n<p>&#8211;master-host=X.X.X.X<br \/>\n\u53ef\u9009\u62e9\u4e0e&#8211;slave\u8bbe\u7f6e\u4e3b\u8282\u70b9\u7684\u4e3b\u673a\u540d\/ IP \u4e00\u8d77\u4f7f\u7528\uff08\u9ed8\u8ba4\u4e3a127.0.0.1\uff09<\/p>\n<p>&#8211;master-port=5557<br \/>\n\u53ef\u9009\u62e9\u4e0e&#8211;slave\u8bbe\u7f6e\u4e3b\u8282\u70b9\u7684\u7aef\u53e3\u53f7\u4e00\u8d77\u4f7f\u7528\uff08\u9ed8\u8ba4\u4e3a5557\uff09\u3002\u8bf7\u6ce8\u610f\uff0clocust\u5c06\u4f7f\u7528\u6307\u5b9a\u7684\u7aef\u53e3\u4ee5\u53ca\u7aef\u53e3\u53f7+1\u3002\u56e0\u6b64\uff0c\u5982\u679c\u4f7f\u75285557\uff0c\u8757\u866b\u5c06\u4f7f\u7528\u7aef\u53e35557\u548c5558\u3002<\/p>\n<p>&#8211;master-bind-host=X.X.X.X<br \/>\n\u53ef\u9009\u62e9\u4e0e&#8211;master\u3002\u4e00\u8d77\u4f7f\u7528\u3002\u786e\u5b9a\u4e3b\u8282\u70b9\u5c06\u7ed1\u5b9a\u5230\u7684\u7f51\u7edc\u63a5\u53e3\u3002\u9ed8\u8ba4\u4e3a*\uff08\u6240\u6709\u53ef\u7528\u63a5\u53e3\uff09\u3002<\/p>\n<p>&#8211;master-bind-port=5557<br \/>\n\u53ef\u9009\u62e9\u4e0e&#8211;master\u3002\u4e00\u8d77\u4f7f\u7528\u3002\u786e\u5b9a\u4e3b\u8282\u70b9\u5c06\u4fa6\u542c\u7684\u7f51\u7edc\u7aef\u53e3\u3002\u9ed8\u8ba4\u4e3a5557.\u8bf7\u6ce8\u610f\uff0clocust\u5c06\u4f7f\u7528\u6307\u5b9a\u7684\u7aef\u53e3\u4ee5\u53ca\u7aef\u53e3\u53f7+1\u3002\u56e0\u6b64\uff0c\u5982\u679c\u4f7f\u75285557\uff0c\u8757\u866b\u5c06\u4f7f\u7528\u7aef\u53e35557\u548c5558\u3002<\/p>\n<p>&#8211;expect-slaves=X<br \/>\n\u5728\u4f7f\u7528\u65f6\u542f\u52a8\u4e3b\u8282\u70b9\u65f6\u4f7f\u7528&#8211;no-web\u3002\u7136\u540e\u4e3b\u8282\u70b9\u5c06\u7b49\u5f85\uff0c\u76f4\u5230\u6d4b\u8bd5\u5f00\u59cb\u4e4b\u524dX\u4ece\u8282\u70b9\u5df2\u8fde\u63a5\u3002<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>\n<h2>\u6253\u5f00Locust\u7684Web\u754c\u9762<\/h2>\n<\/li>\n<\/ul>\n<p>\u4f7f\u7528\u4e0a\u8ff0\u547d\u4ee4\u884c\u4e4b\u4e00\u542f\u52a8Locust\u540e\uff0c\u5e94\u6253\u5f00\u6d4f\u89c8\u5668\u5e76\u5c06\u5176\u6307\u5411<a href=\"http:\/\/127.0.0.1:8089\/\" target=\"_blank\">http:\/\/127.0.0.1:8089<\/a>\uff08\u5982\u679c\u60a8\u5728\u672c\u5730\u8fd0\u884cLocust\uff09\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>locust\u5b98\u65b9\u94fe\u63a5 \u4ec0\u4e48\u662flocust\uff1f Locust\u662f\u4e00\u6b3e\u6613\u4e8e\u4f7f\u7528\u7684\u5206\u5e03\u5f0f\u7528\u6237\u8d1f\u8f7d\u6d4b\u8bd5\u5de5\u5177\u3002\u5b83\u7528\u4e8e\u5bf9\u7f51\u7ad9\uff08<a href=\"https:\/\/www.ccagml.com\/?p=50\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">\u4f7f\u7528locust\u8fdb\u884c\u538b\u529b\u6d4b\u8bd5<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[27,26],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/50"}],"collection":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=50"}],"version-history":[{"count":10,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/50\/revisions"}],"predecessor-version":[{"id":66,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/50\/revisions\/66"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}