{"id":1749,"date":"2008-06-02T05:03:00","date_gmt":"2008-06-01T21:03:00","guid":{"rendered":"http:\/\/ihower.idv.tw\/blog\/?p=1749"},"modified":"2011-04-09T02:05:17","modified_gmt":"2011-04-08T18:05:17","slug":"httperf","status":"publish","type":"post","link":"https:\/\/ihower.tw\/blog\/1749-httperf","title":{"rendered":"\u4f7f\u7528 httperf \u505a\u7db2\u7ad9\u6548\u80fd\u5206\u6790"},"content":{"rendered":"<p>Update(2008\/7\/8): \u63a8\u85a6<a href=\"http:\/\/github.com\/topfunky\/bong\/\">Topfunky&#8217;s bong<\/a>\u642d\u914d\u4f7f\u7528\uff0c\u975e\u5e38\u7c21\u55ae\u3002<\/p>\n<p>\u505a\u7db2\u7ad9\u6548\u80fd\u8abf\u6821\uff0c\u4e00\u4ef6\u91cd\u8981\u7684\u4e8b\u60c5\u5c31\u662f\u91cf\u6e2c(measure)\u3002\u8abf\u4e4b\u524d\u6e2c\u4e00\u6b21\uff0c\u8abf\u4e4b\u5f8c\u518d\u6e2c\u4e00\u6b21\u624d\u77e5\u6709\u6c92\u6709\u85e5\u6548\u3002<\/p>\n<p><strong>&#8220;Server \u56de\u61c9 requests \u7684\u901f\u5ea6\u6709\u591a\u5feb\uff1f&#8221; <\/strong>\u5c31\u662f\u4e00\u500b\u6700\u57fa\u672c\u7684\u554f\u984c\u3002\u9019\u6280\u5de7\u4e5f\u53eb\u505a\u9ed1\u7bb1\u5206\u6790(Block-box analytic)\u3002Advanced Rails \u4e00\u66f8\u4e2d\u7d66\u4e86\u5e7e\u9ede\u7279\u5225\u8981\u6ce8\u610f\u7684\u4e8b\u9805\uff1a<\/p>\n<ol>\n<li>\u6709\u53f0 front end server (Apache,Nginx\u7b49)\u5148\u6e2c\u8a66 static files\uff0c\u9019\u500b\u6578\u64da\u662f\u4e00\u500b\u4e0a\u9650\u3002Rails \u4e0d\u6703\u6bd4\u9019\u66f4\u5feb\u4e86\u3002<\/li>\n<li>\u627e\u8fd1\u4e00\u9ede\u7684\u5730\u65b9\u6e2c\uff0c\u6e1b\u5c11\u7db2\u8def latency \u7684\u8b8a\u7570\u6027<\/li>\n<li>\u4e0d\u8981\u7528 server \u540c\u4e00\u53f0\u6e2c\u8a66\uff0c\u96d6\u7136 CPU \u4e0d\u592a\u6703\u662f\u554f\u984c\uff0c\u4f46\u662f I\/O \u53ef\u80fd\u6703\u6709\u5f71\u97ff\u3002<\/li>\n<\/ol>\n<p>\u89c0\u6e2c\u7684\u6578\u64da\u9664\u4e86\u5e73\u5747\uff0c\u66f4\u8981\u770b\u6a19\u6e96\u5dee\u8ddf\u8a08\u7b97\u4fe1\u8cf4\u5340\u9593\uff0c\u56e0\u70ba\u9664\u4e86\u5e73\u5747\u4e4b\u5916\uff0c\u4f4e\u8b8a\u7570\u4e5f\u5f88\u91cd\u8981\u3002\u57fa\u672c\u7684\u7d71\u8a08\u5b78\u544a\u8a34\u6211\u5011\uff0c\u76f8\u5dee\u5e73\u5747\u4e00\u500b\u6a19\u6e96\u5dee\u53ef\u4ee5\u6db5\u84cb 68% \u7684\u8cc7\u6599\uff0c\u76f8\u5dee\u5169\u500b\u6a19\u6e96\u5dee\u5c31\u53ef\u4ee5\u6db5\u84cb 95% \u7684\u8cc7\u6599\u3002\u56e0\u6b64\u6211\u5011\u53ef\u4ee5\u7b97\u51fa 95% \u7684\u4fe1\u8cf4\u5340\u9593\uff0c\u4e5f\u5c31\u662f 95% \u767c\u51fa\u7684 requests \u4e2d\uff0c\u53ef\u4ee5\u5728\u5e7e\u79d2\u5230\u5e7e\u79d2\u5167\u56de\u61c9\u3002\u57fa\u672c\u7684\u7d71\u8a08\u77e5\u8b58\u662f\u505a analytic \u5fc5\u5099\uff0cZed Shaw \u70ba\u6b64\u9084\u5beb\u4e86\u7bc7<a href=\"http:\/\/www.zedshaw.com\/rants\/programmer_stats.html\">Programmers Need To Learn Statistics Or I Will Kill Them All<\/a>\u3002<\/p>\n<p>\u5728 Mac \u4e0a\u900f\u904e MacPorts \u5b89\u88dd <a href=\"http:\/\/www.hpl.hp.com\/research\/linux\/httperf\/\">httperf<\/a> \u5f88\u7c21\u55ae\uff0c\u8f38\u5165 `sudo port install httperf` \u5373\u53ef\u3002<\/p>\n<h3>httperf \u7684\u7528\u6cd5<\/h3>\n<p>\u57fa\u672c\u7528\u6cd5\u662f\u6307\u5b9a Server\u3001Port\u3001URL\u548c\u7e3d\u5171\u8981\u767c\u51fa\u591a\u5c11\u500b requests\uff1a<br \/>\n<code><br \/>\nhttperf --server project1.local --port 3000 --uri \/events --num-conns 1000<br \/>\n<\/code><\/p>\n<p>\u5176\u4e2d\u6700\u91cd\u8981\u7684 output \u8cc7\u8a0a\u5c31\u662f Reply rate \u6709\u5e73\u5747\u548c\u6a19\u6e96\u5dee\u7684\u90a3\u4e00\u884c\u3002\u8981\u6ce8\u610f\u7684\u662f httperf \u662f\u6bcf\u4e94\u79d2\u6293\u4e00\u6b21\u6a23\u672c(sample)\uff0c\u6839\u64da httperf \u7684\u5efa\u8b70\u662f\u5e0c\u671b\u81f3\u5c11\u6709 30 \u500b\u6a23\u672c\u6578\u624d\u80fd\u5f97\u5230\u6e96\u78ba\u7684\u6a19\u6e96\u5dee\uff0c\u56e0\u6b64\u7576 sample \u6578\u592a\u5c11\u7684\u6642\u5019\uff0c\u8981\u8a18\u5f97\u628a &#8211;num-conns \u5f80\u4e0a\u52a0\u3002<\/p>\n<p>\u53e6\u4e00\u7a2e\u7b97\u58d3\u529b\u6e2c\u8a66\uff0c\u4e5f\u5c31\u662f\u53bb\u6e2c\u8a66<strong>&#8220;Server \u6bcf\u79d2\u53ef\u4ee5\u627f\u53d7\u591a\u5c11 requests\uff1f&#8221;<\/strong>\u3002\u8acb\u518d\u52a0\u4e0a &#8211;rate \u8ddf &#8211;hog \u53c3\u6578\uff1a<\/p>\n<p><code><br \/>\nhttperf --server project1.local --port 3000 --uri \/events --num-conns 5000 --rate 500 --hog<br \/>\n<\/code><\/p>\n<p>\u9010\u6b65\u628a rate \u5f80\u4e0a\u8abf\uff0c\u76f4\u5230 server \u8d85\u904e\u6975\u9650\u6642\uff0c\u5c31\u6703\u958b\u59cb\u5c11 replies (\u6709 requests \u88ab drop off \u4e86) \u4e26\u51fa\u73fe Errors\u3002<\/p>\n<h3>Rails \u7684\u76f8\u95dc\u8a2d\u5b9a<\/h3>\n<p>\u6709\u5e7e\u9805\u8a2d\u5b9a\u53ef\u4ee5\u589e\u52a0\u66f4\u591a\u76f8\u5c0d\u6bd4\u8f03\u6578\u64da\uff1a<\/p>\n<ol>\n<li>\u900f\u904e config.action_controller.perform_caching = false \u7684\u8a2d\u5b9a\u53ef\u4ee5\u5728 production mode \u4e5f\u628a\u6240\u6709 caching Page, Action, Fragment \u66ab\u6642\u95dc\u6389<\/li>\n<li>\u66ab\u6642\u8a3b\u89e3\u6389 before_filter \u4e2d\u7684\u6b0a\u9650\u6aa2\u67e5<\/li>\n<li>\u900f\u904e session :off \u95dc\u6389 session<\/li>\n<\/ol>\n<h3>\u672c\u6587\u53c3\u8003\u8cc7\u6599<\/h3>\n<ol>\n<li>Advanced Rails Chap.6 Performance<\/li>\n<li><a href=\"http:\/\/peepcode.com\/products\/benchmarking-with-httperf\">Peepcode httperf screencast<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Update(2008\/7\/8): \u63a8\u85a6Topfunky&#8217;s bong\u642d\u914d\u4f7f\u7528\uff0c\u975e\u5e38\u7c21\u55ae\u3002 \u505a\u7db2\u7ad9 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/ihower.tw\/blog\/1749-httperf\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008\u4f7f\u7528 httperf \u505a\u7db2\u7ad9\u6548\u80fd\u5206\u6790\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[34,50,31],"tags":[],"class_list":["post-1749","post","type-post","status-publish","format-standard","hentry","category-http","category-performance","category-ruby","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/s1q6tG-httperf","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1749","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/comments?post=1749"}],"version-history":[{"count":1,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1749\/revisions"}],"predecessor-version":[{"id":5561,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/1749\/revisions\/5561"}],"wp:attachment":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/media?parent=1749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/categories?post=1749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/tags?post=1749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}