锘??xml version="1.0" encoding="utf-8" standalone="yes"?>BlogJava-鑱傛案鐨勫崥瀹?/title><link>http://www.8634070.com/yongboy/</link><description>璁板綍宸綔/瀛範鐨勭偣?#20579;?#28142;?#28142;銆?/description><language>zh-cn</language><lastBuildDate>Tue, 26 Mar 2019 20:21:37 GMT</lastBuildDate><pubDate>Tue, 26 Mar 2019 20:21:37 GMT</pubDate><ttl>60</ttl><item><title>HTTP API璁?#29825;?#32471;?#29825;?/title><link>http://www.8634070.com/yongboy/archive/2018/01/02/433000.html</link><dc:creator>nieyong</dc:creator><author>nieyong</author><pubDate>Tue, 02 Jan 2018 12:53:00 GMT</pubDate><guid>http://www.8634070.com/yongboy/archive/2018/01/02/433000.html</guid><wfw:comment>http://www.8634070.com/yongboy/comments/433000.html</wfw:comment><comments>http://www.8634070.com/yongboy/archive/2018/01/02/433000.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.8634070.com/yongboy/comments/commentRss/433000.html</wfw:commentRss><trackback:ping>http://www.8634070.com/yongboy/services/trackbacks/433000.html</trackback:ping><description><![CDATA[<h2 id="toc_0">鍓嶈</h2> <p>鏈杩戜竴娈垫椂闂达紝瑕佷负?#31476;涓墜鏈虹粓绔疉PP绋嬪簭浠庨浂寮濮?#29825;?#29825;竴鏁村?#26735;TTP API?#32029;?#27932;?#36127;?#28528;鍚?#37928;勭敤?#22491;寰堝浐瀹氾紝?#31476;涓柊鐨勭鍔?#32468;疉PP銆傜洰鍓嶈繕鏄?#26916;圭洰?#22453;鏈燂紝鑷劧瑕佹眰?#31476;鍒囧揩閫?#37510;佷粠绠?#32029;瀹?#37922;?#37804;负涓?#37510;?/p> <p>涓嬮潰灏?#38315;愪竴璁?#26473;?#37812;戜滑鏄?#28641;備綍璁?#29825;HTTP API?#32029;?#27367;?#21159;鐩?#28725;瑰閮?#37714;?#27996;鸿岃?#32029;?#30149;鏈?#28000;涔堟柊鎰忥紝浣?#28725;规?#25118;潵璇村?#22559;柊?#30686;鐨?#37510;傞伩鍏嶅繕鍗达紝瓒佺潃绌?#38338;?#28751;藉揩璁板綍涓嬫潵銆?/p> <h2 id="toc_1">鎶鏈爢鏍?#37928;?#38315;夋嫨</h2> <p>PHP鍢?#38171;?#37733;槦鍐?#28052;熸病?#22161;涓?#27996;虹?#29112;倝銆?/p> <p>Java锛熷?#34249;嚑?#21246;?#30149;鏈?#32432;?#26473;?#27996;嗭紝閭?#28052;堝?#23942;潅鐨勮鍐?#37826;规?#22572;紝鍐?#37716;?#28051;?#37733;槦鍐?#28052;熸病浠涔?#27996;?#28028;?……</p> <p>鍥槦浣?#37922;?#26473;嘗ua?#32029;?#29056;浜嶰penResty鏋勫缓杩嘥CP銆丠TTP缃?#37711;?#32475;夛紝瀵筁ua + Nginx缁勫悎闈炲父鐔熸倝?#32029;鑳藉?#29111;揩閫?#37928;勫簲鐢?#37734;嚎涓婄幆澧?#37510;?#37712;嶈?#30873;ua璇硶灏?#23480;?#37510;?#32480;鍗曪紝?#31476;涓柊?#22684;鍗?#28598;?#28751;?#37721;?#28000;熀鏈?#37908;熸倝?#32029;椹?#28051;?#23534;宸?#37510;?/p> <p>鐪嬫潵?#32029;Nginx + Lua鏄洰鍓?#37832;?#36127;閫?#37722;?#37812;戜滑鐨?#27996;?#37510;?/p> <p>HTTP API?#32029;?#28214;瑕?#37711;?#37714;?#37714;?#37922;HTTP鍏?#28003;?#37823;嶄綔璇?#28052;夛紝?#28533;搴?#28725;瑰叿浣?#37928;?#28051;?#37716;?#37823;嶄綔鏂规硶銆傚熀浜庢?#32029;?#30149;鏈?#38338;?#38338;?#38315;犺溅?#32029;鎴戜滑閫夋嫨浜?<a href="http://lor.sumory.com/">http://lor.sumory.com/</a> 杩?#28052;堜竴涓?#28751;?#23480;?#37928;?#22935;?#37835;讹紝鐢?#27996;庤緟鍔HTTP API鐨勫紑鍙?#23534;鍙?#37510;?/p> <p>鍡紝OpenResty + Lua + Lor?#32029;灏?#37835;?#37812;愪簡鎴戜滑绠鍗?#37814;鏈爢鏍?#37510;?/p> <h2 id="toc_2">HTTP API绠瑕?#29825;?#29825;?/h2> <h3 id="toc_3">HTTP API璺?#23536;勫?#23683;涔?/h3> <p>姣忎竴鍏?#28003;?#28051;?#37716;?#38315;昏緫?#32029;鐩?#37818;?#37734;URL Path涓?#28003;?#37916;板?#28888;潵銆傛?#25116;滑瑕?#37928;?#37828;?#32480;鍗曞揩閫燂紝鏁版嵁缁?#37835;?#28052;?#38338;?#37928;?#26473;?#37818;?#37711;?#32495;伙紝灏藉彲?#20824;鐨勫?#32472;贰鍖?#37510;俥g锛?/p> <pre><code>/resource/video/ID </code></pre> <p>姣斿鐢埛鍙嶉杩欎竴妯潡?#32029;灏?#28003;?#37922;?#28051;嬮潰姣旇緝?#27984;瀹?#37928;勮矾寰?#38171;?/p> <pre><code>/user/feedback </code></pre> <ul> <li><code>GET</code>?#32029;浠?#37922;埛?#28142;搴?#37836;?#29831;?#37721;嶉鐨勫?#21975;鍒?#29723;紝鍙?#37714;嗛 <ul> <li><code>curl -X GET http://localhost/user/feedback?page=1</code></li> </ul></li> <li><code>POST</code>?#32029;鎻愪氦?#31476;涓?#37721;嶉 <ul> <li><code>curl -X POST http://localhost/user/feedback -d "content=hello"</code></li> </ul></li> <li><code>DELETE</code>?#32029;鍒?#38340;竴涓?#37812;?#28598;?#28051;?#37721;嶉?#22572;紝鍙傛?#20276;?#21227;?#29362;湪URL璺?#23536;?#28051;?#37510;? <ul> <li><code>curl -X DELETE http://localhost/user/feedback?id=1001</code></li> </ul></li> <li><code>PUT</code>?#32029;?#27967;?#26570;璇?#29825;?#37712;?#28729;? <ul> <li><code>curl -X PUT http://localhost/user/feedback/1234 -d "content=hello2"</code></li> </ul></li> </ul> <p>鐢埛灞炴?#23536;堝?#27710;紝鐢埛鏄电?#26495;彧鏄?#37711;?#28051;竴涓?#38318;?#37714;嗭紝?#27932;姝洿?#26570;鏄电杩欎竴琛屼负?#32029;HTTP鐨?<code>PATCH</code> 鏂规硶鍙洿绮?#37713;?#37928;勬弿杩?#38318;?#37714;?#37825;版嵁?#27967;?#26570;鐨?#28051;?#37716;渶?#30512;锛?/p> <pre><code>/user/nickname </code></pre> <ul> <li><code>PATCH</code>?#32029;?#27967;?#26570;鐢埛鏄电?#24110;紝鏄电鏄?#37922;埛灞炴?#28052;嬩竴?#32029;鍙?#28000;?#28003;?#37922;洿杞婚噺绾?#37928;?<code>PATCH</code> 璇?#28052;? <ul> <li><code>curl -X PATCH http://localhost/user/nickname -d "nickname=hello2"</code></li> </ul></li> </ul> <p>鍡紝鍚屼竴绫?#37928;勮?#21228;簮URL?#27367;?#21159;?#27984;瀹?#27996;嗭紝浣咹TTP Method鍛堢幇浜?#28051;?#37722;?#37928;?#28051;?#37716;?#38315;昏緫?#28214;?#30512;銆?/p> <h3 id="toc_4">HTTP API鐨?#29825;?#38338;?#37818;堟潈</h3> <p>瀹?#38340;?#28051;?#37716;HTTP API鐨?#29825;?#38338;?#37828;渶瑕佹?#22559;潈鐨?#37510;?/p> <p>浼?#32513;?#37928;凙ccess Token瑙?#37712;?#37826;规?#22572;紝鏈session鍥?#29831;?#37832;?#37714;讹紝?#31476;鑸渶瑕佺粨鍚圵eb娴?#29785;堝櫒?#32029;?#28214;瑕?#37712;?#37711;?#37714;Cookie涓紝鎴?#37922;?#27996;竴涓狫SessionID鐢?#27996;?#37837;?#29831;?#32475;?#37510;?#26473;?#38333;堝?#29808;崟绾潰鍚戠鍔粓绔?#37928;凥TTP API鍚?#32468;潵璁诧紝?#33503;?#30149;鏈変箟鍔?#37720;诲仛杩欎竴鐨勫吋瀹癸紝鐣?#37828;?#37712;?#28003;?#37510;?/p> <p>鍙?#28598;?#28751;?#37828;?<code>OAUTH</code> 璁?#29831;佷?#21997;紝鏈?#37825;村鐨?#29825;?#29831;佹?#35268;?#22557;苟宸?#23480;?#28051;氬?#26677;紝寰?#37828;?#37812;?#37908;?#27996;嗭紝浣?#28725;规?#25116;滑鑰岃杩?#37828;?#28598;噸?#32029;涓嶅閫?#37722;?#26462;婚噺绾?#37928;凥TTP API?#32029;涓嶅鍙兘?#23027;璐瑰澶?#37928;勭鍔?#37720;诲仛瀹?#37928;?#26473;愮淮宸綔銆?/p> <p>鏈?#31891;閫夋嫨浜?#26462;婚噺绾?#37928;?<a href="https://jwt.io/">Json Web Token</a>?#32029;闈炲父?#25571;鍑戯紝寮绠?#37719;?#37922;?#37510;?/p> <p><img src="https://i.ytimg.com/vi/BzZi_kfnaWc/maxresdefault.jpg" alt=""/></p> <p>鏈浣冲仛?#30838;鏄?#37814;奐WT Token鏀?#37734;HTTP璇锋眰澶?#38318;?#28051;紝涓嶈嚦浜?#37724;屽叾瀹?#37721;傛?#29256;?#38155;穯锛?/p> <pre><code class="language-bash">curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiI2NyIsInV0eXBlIjoxfQ.LjkZYriurTqIpHSMvojNZZ60J0SZHpqN3TNQeEMSPO8" -X GET http://localhost/user/info </code></pre> <p>涓嬮潰鏄竴鍓?#23092;?#29785;堝櫒娈?#37928;勪竴鑸?#29825;?#29831;佹祦绋嬶紝杩?#28051;嶩TTP API璁?#29831;?#28598;?#28003;撲竴鑷达細</p> <p><img src="https://upload-images.jianshu.io/upload_images/1821058-2e28fe6c997a60c9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700" alt=""/></p> <p>JWT鐨凩ua瀹?#37916;帮紝鎺?#38013;? <code>https://github.com/SkyLothar/lua-resty-jwt.git</code>?#32029;绠鍗?#28598;?#37922;?#37510;?/p> <h3 id="toc_5">JWT鍜孡or鐨勭粨鍚?/h3> <p>jwt?#28214;瑕佸拰涓?#37716;?#26473;?#29723;?#32513;?#28729;氾紝缁?#37722;?lor 杩?#28051;狝PI寮鍙戞鏋舵?#24874;緵鐨?#28051;?#38338;?#28000;?#37832;?#37714;讹紝鍙?#37734;?#28051;?#37716;?#28598;勭悊涔?#37715;嶏紝鍦?#37722;?#38315;?#28003;?#32515;?#26473;?#29723;屾潈闄愭嫤鎴?#37510;?/p> <ul> <li>鐢埛?#28214;瑕?#29831;锋眰杩?#29723;屾?#22559;潈鎺?#37721;紝姣斿?#20636;櫥闄?#32475;?/li> <li>鏈?#37716;?#37731;?#32468;?#28028;?#37814;?#37922;埛鏍?#29831;?#32471;紝姣斿鐢埛id绛夛紝瀛?#37711;JWT鐨刾ayload璐?#38013;?#28051;紝?#21159;鍚?#37922;?#37812;怲oken瀛?#32471;?#28051;诧紝鍙戠粰瀹埛绔?/li> <li>瀹埛绔?#37824;?#37714;癑WT鐢?#37812;?#37928;凾oken瀛?#32471;?#28051;诧紝鍦?#37722;?#32513;?#37928;?#29831;锋眰涓渶瑕?#38340;勫?#29362;湪HTTP璇锋眰鐨凥eader涓?/li> <li>瀹?#37812;?#29825;?#29831;?#26473;?#32459;?/li> </ul> <p>涓?#37722;?#27996;嶰AUTH?#32029;JWT鍗?#29825;?#37928;?strong>鑷?#37718;?#37722;?/strong>鐗规紝鍐?#28729;?#27996;?#37722;?#32468;?#37721;?#28000;?#28751;?#23536;堝?#27692;?#28852;俊鎭?#28699;樻斁鍦payload璐?#38013;?#28051;紝鍏秚oken鐢?#37812;愪?#23338;悗鍚?#32468;?#37721;?#28000;?#28051;?#37922;?#28699;樺偍锛?#28051;嬫瀹埛绔?#37721;?#38315;?#29831;?#23033;傛椂浼?#37721;?#38315;佺粰鏈?#37716;?#37731;?#32468;紝鍚?#32468;幏鍙?#28052;嬪悗?#32029;鐩?#37818;?#26976;岃瘉鍗?#37721;紝楠岃瘉閫?#26473;囷紝鍙?#28000;?#37929;?#37818;?#29831;?#37721;?#37720;?#37711;堜繚瀛?#37711;?#28051;?#37928;?#37813;鏈?#28766;炴?#37510;?/p> <p>涓嬮潰姊崇?#21973;竴涓婮wt璁?#29831;佸拰Lor鐨勭粨鍚?#37510;?/p> <ul> <li>鍏?#28766;?#23268;鎴紝閽堝?#35268;墍鏈塒ATH?#32029;鎵鏈塇TTP Method?#32029;杩?#38322;屽?#21229;悊JWT璁?#29831;侊紝?#23266;璁?#29831;佹垚鍔燂紝浼?#37929;?#37818;?#37814;?#37922;埛id娉?#37711;?#37714;板綋鍓?#28051;?#37716;?#28598;勭悊涓?#28051;?#37826;?#28051;紝鍚庨潰鐨?#28051;?#37716;?#37721;?#28000;?#37929;?#37818;?#29831;?#37721;栧綋鍓?#37922;埛鐨id鍊?/li> </ul> <pre><code class="language-lua">app:use(function(req, res, next) local token = ngx.req.get_headers()["Authorization"] -- 鏍?#26976;屽璐紝err?#36127;?#25930;璇?#28000;?#37934;侊紝姣斿 400 local payload, err = verify_jwt(token) if err then res:status(err):send("bad access token reqeust") return end -- 娉?#37711;?#26473;涘綋鍓?#28051;?#28051;?#37826;?#28051;紝?#20265;鍏嶆瘡娆?#28000;巘oken涓幏鍙? req.params.uid = payload.uid next() end) </code></pre> <ul> <li>閽堝?#29808;叿浣?#29882;?#23536;?#26473;?#29723;?#29825;?#28729;?#37833;?#38340;愭嫤鎴紝?#32221;绮?#32494;?#25652;?#38171;?#23011;斿 /user 鍙?#37711;?#29825;?#23480;?#37927;?#38340;嗘?#22559;潈鐢埛璁?#38338;?/li> </ul> <pre><code class="language-lua">app:use("/user", function(req, res, next) if not req.params.uid then -- 娉?#37808;忥紝杩?#38322;屾病鏈夎皟鐢next()鏂规硶?#32029;璇锋眰鍒?#26473;?#38322;屽氨鎴?#23005;?#27996;嗭紝涓嶅湪鍖归厤鍚庨潰鐨勮矾鐢? res:status(403):send("not allowed reqeust") else next() -- 婊?#29906;?#28000;?#28051;?#37833;?#28000;讹紝閭?#28052;堢户缁?#37718;归厤涓嬩竴涓?#29882;?#37922;? end end) </code></pre> <ul> <li>?#31476;绉?#37828;緝缁?#32494;?#25652;紝鍏?#28003;?#37714;?#23011;忎竴涓狝PI鎺?#37721;紝?#27932;?#36127;?#27367;?#21159;URL?#31476;鑷达紝浣?#28051;?#37722;?#37928;凥TTP Method鏈夋椂璇?#23033;傛潈闄?#26473;?#37828;?#37832;?#37718;?#37714;?#37928;?/li> </ul> <pre><code class="language-lua">local function check_token(req, res, next) if not req.params.uid then res:status(403):send("not allowed reqeust") else next() end end local function check_master(req, res, next) if not req.params.uid ~= master_uid then res:status(403):send("not allowed reqeust") else next() end end local lor = require("lor.index") local app = lor() -- 澹?#37828;庝竴涓猤roup router local user_router = lor:Router() -- 鍋?#29825;?#37836;?#37930;?#37828;?#28051;嶉渶瑕?#37922;埛鏉?#38340;?#37928;?user_router:get("/feedback", function(req, res, next) end) user_router:put("/feedback", check_token, function(req, res, next) end) user_router:post("/feedback", check_token, function(req, res, next) end) -- 鍙?#37832;?#32480;?#37918;嗗憳鎵?#37832;夋潈闄?#37714;?#38340;?user_router:delete("/feedback", check_master, function(req, res, next) end) -- 浠middleware鐨勫舰寮?#28751;?#29831;group router鍔犺浇杩涙潵 app:use("/user", user_router()) ...... app:run() </code></pre> <h2 id="toc_6">?#36127;浠涔堟病鏈?#38315;夋嫨GraphQL API 锛?/h2> <p>鎴戜滑鍦?#28051;婁竴涓?#26916;圭洰涓?#28725;瑰鎻愪緵浜咷raphQL API?#32029;鍏?#38171;堝湪娴嬭?#26336;幆澧?#28051;?#38171;?#38007;韩鎻愪緵鏂?#22935;?#26440;?#37713;?#38007;?#37813;?#32480;?#37832;?#37714;讹紝鍐?#32513;?#37722;堟柟渚?#37928;勮皟璇?#28729;埛绔紝纭?#28729;?#29825;?#37722;?#32468;?#23534;鍙戝拰鍓?#32468;疉PP寮鍙?#28598;?#28598;?#38340;?#28003;?#27996;嗛?#25120;?#20343;氦娴?#37928;?#26864;戠?#22263;紝鑺傜?#20343;簡?#23266;骞?#23092;?#38322;忥紝浣?#37715;?#37832;?#26473;?#37828;渶瑕佽緝澶?#37928;勫璁?#37814;?#37711;?#37510;?/p> <p>浣嗗湪?#26570;椤圭洰涓紝?#31476;搴?#37807;虫?#24874;緵GraphQL API?#32029;閬?#37714;?#37928;?#38338;?#26864;樺涓?#38171;?/p> <ul> <li>鍏柊鐨?#26916;圭洰鏁版嵁缁?#37835;勫?#28852;?#37721;?#37716;?#28598;?#26864;戠箒</li> <li>鏅?#38316;嶆眰?#25577;?#32029;涓?#37716;?#22959;?#37736;嬪揩閫?#23534;鍙?#37510;佽皟璇?/li> <li>澶?#28729;舵閬?#28725;笹raphQL API鏈?#27996;?#37814;?#29785;紝浣?#37922;JSON杈?#37713;?#37837;?#23534;?#37928;凥TTP API鏄害瀹氫織鎴?#37928;勪範?#20795;閫夋嫨</li> </ul> <p>姣?#37827;犵闂紝浠?#37832;浣?#37812;?#37832;揩閫熸?#21227;?#40511;緝?#36127;瀹?#37825;?#37928;凙PP鍔熻兘?#32029;HTTP API + JSON鏍?#23534;?#37828;?#37832;?#36127;鑸?#37832;?#37928;?#38315;夋嫨銆?/p> <p>?#27367;?#21159;鏈?#27996;?#37815;呭績鏈?#37716;?#37731;?#32468;?#37928;勮緭鍑猴紝寰堝?#27693;椂鍊?#26473;?#37828;?#28028;?#23092;?#29840;规?#22793;竴浜?#23092;?#38322;忥紝瀹埛绔苟涓嶈?#34249;鏈?#37825;?#37928;勫埄鐢?#26473;?#37733;?#37825;版嵁鐨?#37813;鏈?#28699;?#23048;?#28766;炴?#37510;?#28003;嗗拰杩?#25652;?#28000;?#37721;?#27996;?#28000;?#23480;?#32513;忎範?#20795;鐨凥TTP API?#30367;鐢?#37826;?#23534;?#37929;?#23011;旓紝鍙?#23536;?#28052;?#37711;?#23536;?#27996;?#37510;?/p> <h2 id="toc_7">灏?#32513;?/h2> <p>?#32139;鍓嶈?#27406;竴濂桯TTP API鎶鏈爢鏍?#26473;?#29723;?#37928;?#26473;?#28051;嶉敊?#32029;甯?#37832;涜兘缁?#37832;?#37722;屾?#28925;渶瑕?#37928;勫悓瀛?#37819;愪?#28055;竴?#20579;?#20579;鐨勫弬鑰?#28000;峰? :))</p> <p>?#32139;?#21159;?#30149;鏈変竴鎴?#28051;嶅彉鐨?#37835;?#37835;勬鍨嬶紝闅忕潃涓?#37716;?#37928;?#38315;愭笎鍙戝?#26346;紝鍚庨潰鐩镐俊浼?#37832;?#23536;堝鐨勫彉鍔?#37510;?#28003;?#26473;?#37828;?#28000;?#37722;?#37928;?#27996;嬫儏浜嗭紝璋佺煡閬?#37723;紝鍚庨潰鏈?#32460;?#37712;嶆璁板綍鍚~</p> <img src ="http://www.8634070.com/yongboy/aggbug/433000.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.8634070.com/yongboy/" target="_blank">nieyong</a> 2018-01-02 20:53 <a href="http://www.8634070.com/yongboy/archive/2018/01/02/433000.html#Feedback" target="_blank" style="text-decoration:none;">鍙?#29723;?#29831;?#29825;?/a></div>]]></description></item><item><title>Tsung绗?#29825;?#28052;婭P鍦板潃鍜?#32468;?#37721;?#38340;?#37714;剁?#20346;?#23544;瘒http://www.8634070.com/yongboy/archive/2016/08/16/431601.htmlnieyongnieyongTue, 16 Aug 2016 13:17:00 GMThttp://www.8634070.com/yongboy/archive/2016/08/16/431601.htmlhttp://www.8634070.com/yongboy/comments/431601.htmlhttp://www.8634070.com/yongboy/archive/2016/08/16/431601.html#Feedback2http://www.8634070.com/yongboy/comments/commentRss/431601.htmlhttp://www.8634070.com/yongboy/services/trackbacks/431601.html鍓嶈

鍦?a href="http://www.8634070.com/yongboy/archive/2016/07/26/431322.html">Tsung绗?#29825;?#28052;嬪?#23339;祴绔?#29863;勬簮闄?#37714;剁瘒涓?#29831;村?#26495;崟?#31476;IP鍦板潃鐨?#37832;?#37716;?#37731;?#37832;澶?#38003;藉鍚?#28598;?#37721;?#38315;?4K涓?#26473;?#37818;紝杩?#28051;?#23480;?#32480;?#37828;?#37835;?#38340;愪簡銆?/p>

浣?#37916;板湪鎴?#26473;樻兂缁?#32513;?#23075;?#37711;竴涓嬶紝濡備綍绐佺牬杩?#28051;?#38340;?#37714;?#37723;?锛?/p>

濡備綍绐佺牬闄?#37714;?/h3>

杩?#38318;?#37714;?#28751;?#37828;?#29781;佷粠澶?#28051;?#37826;归潰鍘?#29825;?#29825;哄?#20633;綍濡備綍绐佺牬闄?#37714;?#37719;?#28051;狪P鐨?#38340;?#37714;?#37510;?/p>

0. Tsung鏀寔TCP鎯?#37712;?/h5>

鍦Tsung 1.6.0 涓?#37824;寔鐨凾CP灞炴?#37832;夐檺?#32029;鍏?#38318;?#37911;规?#28641;?#28051;?#38171;?/p>

protocol_options(#proto_opts{tcp_rcv_size = Rcv, tcp_snd_size = Snd,
                             tcp_reuseaddr = Reuseaddr}) ->
    [binary,
     {active, once},
     {reuseaddr, Reuseaddr},
     {recbuf, Rcv},
     {sndbuf, Snd},
     {keepalive, true} %% FIXME: should be an option
    ].

姣斿?#20634;彲浠厤缃?#37734;板潃?#22136;鐢?#38171;?/p>

<option name="tcp_reuseaddr" value="true" />

1. 澧?#37716;營P鍦板潃

杩?#37828;?#37832;?#36127;鐜?#28729;?#37510;?#37832;?#36127;鏂?#28186;?#37928;勫?#28852;硶?#32029;鍚?#26473;愮淮鐨勫悓浜嬪鐢?#29831;疯嫢骞?#28051;狪P鍦板潃灏?#28610;?#37510;?#37734;?#28051;嶈?#38095;?#37711;?#28729;冨洜?#30988;鍓嶆彁涓嬶紝?#31476;涓狪P鍦板潃鍙?#28000;?#28725;瑰?#26663;?#34425;珛64K涓?#26473;?#37818;紝澶?#28051;狪P灏?#37828;?code>N * 64K浜?#37510;?#26473;?#28051;?#37734;Tsung涓?#37824;寔鐨勫?#22557;銆?/p>

<client host="client_99" maxusers="120000" weight="2" cpu="8">
    <ip value="10.10.10.99"></ip>
    <ip value="10.10.10.11"></ip>
</client>

澧?#37716;營P鍙?#28000;?#37832;?#28598;?#32457;?#37826;?#23534;?#38171;?/p>

  • 澧?#37716;犵墿?#24714;缃?#37719;?#37826;?#23534;忥紝?#31476;涓?#32515;?#37719;?#32513;?#28729;氫竴涓狪P鍦板潃
    • 浠?#28000;烽珮
  • ?#31476;涓?#32515;?#37719;?#28051;?#32513;?#28729;?#28598;?#28051;?#37721;?#37922;?#37928;勮?#27693;?#28910;P鍦板潃
    • 姣斿 ifconfig eth0:2 10.10.10.102 netmask 255.255.255.0
    • 铏氭?#28910;P蹇?#26916;?#37828;?#37930;?#28729;炲彲鐢紝鍚?#37714;?#37824;?#28051;?#37714;板?#28850;寘鏁版嵁

瑕?#37828;病鏈?#29906;?#28598;?#37928;勫彲鐢?#38095;氭?#28910;P鍦板潃渚?#28003;?#28003;?#37922;紝鎴?#29825;?#28003;犻渶瑕?#37711;虫敞?#31476;涓嬪?#24232;潰鐨?code>IP_TRANSPARENT鐗规弿杩?:))

2. 鑰?#38095;Linux鍐?#37837;?#37826;板SO_REUSEPORT绔?#37721;噸鐢?#37911;规?/h4>

浠?#29722;?#37720;嬫祴鐨勪竴涓猅CP鏈?#37716;?#37731;负渚嬶紝缁?#32513;?#37815;跨?#25120;粶鍥?#37711;?#32513;?#29831;?#27996;?#37510;?/p>

{SrcIp, SrcPort, TargetIp, TargetPort}
  • ?#22158;涓?#28598;?#38318;?#37714;?#37832;?#37716;?#37731;?#37813;浣?#37922;?#37928;勭郴缁熶负CentOS 6绯?#37714;楋紝鎵浣?#37922;?#32495;?#32513;?#37712;?#37837;?#28003;?#27996;?.9
    • {SrcIp, SrcPort} 纭?#28729;?#27996;?#37832;?#37734;板?#34425;珛?#31476;涓?#26473;?#37818;?#37928;勫敮?#31476;鎬紝鏈?#37734;板?#26495;潃鐨勫敮?#31476;鎬?/li>
    • {TargetIp, TargetPort}鐨勬?#29363;硶纭?#28729;氬敮?#31476;?#32029;浠?#28000;?#37837;?#29831;?#27996;嗙洰鐨勫?#26495;潃
  • Linux Kernel 3.9 鏀寔 SO_REUSEPORT 绔?#37721;噸鐢?#37911;规?- 缃戠粶鍥?#37711;?#32513;?#28051;紝浠讳綍?#31476;涓?#37711;冪?#29362;?#37928;勫彉鍖?#38318;?#28028;?#37812;愪负?#31476;涓?#37711;柊鐨?#26473;?#37818;?
    • 鐪熸璁?#32515;戠粶鍥?#37711;?#32513;勪竴璧?#32513;?#37812;愪簡?#31476;涓?#32515;戠粶杩?#37818;?#37928;勫敮?#31476;鎬?/li>
    • ?#24714;璁?#28051;婂彲浠?#28725;瑰?#26663;?#34425;珛鐨?#26473;?#37818;?#37825;?#28186;?#29863;?#27996;?#37733;?#28051;?#37711;冪?#29362;彲鍙?#37825;板?/li>
    • Totalconnections = NSrcIp * NSrcPort * NTargetIp * NTargetPort

?#22158;涓?#37832;?#38318;?#37714;?#37832;?#37716;?#37731;?#28729;夎鏈塁entOS 7?#32029;鍏?#37712;?#37837;镐负3.10.0?#32029;寰?#38007;劧鏀寔绔?#37721;噸鐢?#37911;规?#37510;?/p>

閽堝?#29808;彧鏈変竴涓狪P鍦板潃鐨勫?#23339;祴绔?#37832;?#37716;?#37731;?#38000;岃?#32029;绔?#37721;寖鍥?#28052;?#28751;?#32429;?#28729;?#27996;嗭紝鍙兘浠庣洰鏍?#37832;?#37716;?#37731;?#26473;?#37818;?#37734;板潃涓婂?#26127;?#38095;?#37510;傛湁涓?#32457;?#37826;?#23534;?#38171;?/p>

  1. ?#27952;鏍?#37832;?#37716;?#37731;?#28583;?#37716;犲涓?#37721;?#37922;IP鍦板潃?#32029;鏈?#37716;?#32459;嬪簭缁?#28729;氭寚瀹?#32468;?#37721;?#37719;?#37721;?
    • N涓狪P鍦板潃?#32029;鍙?#37922;?#28699;?#37734;?64K * N
  2. 鏈?#37716;?#32459;嬪簭缁?#28729;?#28598;?#28051;狿ort?#32029;杩?#28051;?#38333;堝绋嬪簭鑰岃闅?#25652;?#28051;嶅
    • 閽堝?#29808;崟涓狪P?#32029;鐩?#37722;?#27996;M涓?#32468;?#37721;?/li>
    • 鍙?#37922;?#23524;虹珛 64K * M 涓?#26473;?#37818;?/li>
  3. 鍙?#37922;?#26473;?#37837;锋?#23815;悊 , Total1 ip connections = 64K * N * M

鍟板棪浜嗗崐澶紝浣嗙洰鍓峊sung杩樻病鏈夋墦绠?#29781;佹?#24874;緵鏀?#37816;佸憿?#32029;鎬?#28052;堝?#28871;紝鑷?#23480;?#37716;墜涓拌瓒抽鍚?#38171;?/p>

https://github.com/weibomobile/tsung/commit/f81288539f8e6b6546cb9e239c36f05fc3e1b874

3. 閫?#37828;?#28000;?#37918;嗘寮?#37824;寔

Linux Kernel 2.6.28鎻愪緵IP_TRANSPARENT鐗规紝鏀寔鍙?#28000;?#32513;?#28729;?#28051;?#37828;?#37832;?#37832;?#37928;処P鍦板潃銆?#26473;?#32457;岻P鍦板潃鐨勭粦瀹?#28051;嶉渶瑕?#37828;?#32448;?#37928;勯厤缃?#37734;?#37911;悊缃?#37719;?#37510;佽?#27693;嫙缃?#37719;?#28051;婇潰?#32029;?#20265;鍏?#27996;?#23536;堝?#27693;墜鍔?#37823;嶄綔鐨勯?#33636;儲銆?#28003;?#37828;渶瑕佷富鍔?#37816;?#28729;?#26473;?#32457;嶉厤缃紝姣斿涓嬮潰鐨凜璇?#29815;鐗?#37832;?#28000;?#37934;?/p>

int opt =1;
setsockopt(server_socket, SOL_IP, IP_TRANSPARENT, &opt, sizeof(opt));

?#27952;鍓嶅湪鏈鏂板嵆灏?#37813;?#37718;?#37928;?.6.1鐗?#37832;?#28051;?#37819;愪緵浜?#28725;筎CP鐨勬敮鎸侊紝涔熼渶瑕佺炕璇?#37812;?#28725;瑰簲鐨?#38315;夐?#30328;紝浠?#28186;?#37734;?#23524;虹珛缃戠粶杩?#37818;椂浣?#37922;?#38171;?br/> 锟?/p>

璇?#37828;庝竴涓?#38171;?br/> - IP_TRANSPARENT?#30149;鏈?#28725;瑰簲涓?#38338;?#37928;勫?#24531;彉閲忥紝鍏?#37711;?#28003;?#37706;间负19
- SOL_IP瀹?#28052;?#28729;?#28725;瑰?#26047;?#38171;?strong>0
- 娣?#37716;Socket閫夐閫?#37922;?#37837;?#23534;忎负锛{raw, Protocol, OptionNum, ValueSpec}

閭?#28052;堝?#20633;綍璁?#38315;?#37828;?#28000;?#37918;嗘寮?#23480;綔鍛?#38171;?/p>

3.1 鍚?#37922;?code>IP_TRANSPARENT鐗规?/h5>
<options>
    ...
    <option name="ip_transparent" value="true" />
    ...
<options>
3.2 ?#21412;缃?#37721;?#37922;?#37928;?#26864;?#28598;朓P鍦板潃

閭?#28052;?#26473;?#27996;?#26864;?#28598;?#37928;処P鍦板潃濡備綍璁?#32515;?#37723;?#38171;?/p>

  • 鍙?#28000;负client鍏冪?#29363;墜鍔?#23075;?#37716;犲涓?#37721;?#37922;?#37928;処P鍦板潃

    <client host="tsung_client1" maxusers="500000" weight="1">
       <ip value="10.10.10.117"/>
       <ip value="10.10.10.118"/>
       ......
       <ip value="10.10.10.127"/>
    </client>
    
  • 鍙?#28000;?#28003;?#37922;?#37826;板鐨?code>iprange鐗规?/p>

    <client host="tsung_client1" maxusers="500000" weight="1">
        <ip value="10.10.10.117"/>
      <iprange version="v4" value="10.10.10-30.1-254"/>
    </client>
    

浣?#37828;渶瑕佺?#32346;锛?/p>

  1. 杩?#27996;IP鍦板潃?#27952;鍓?#38318;芥病鏈夎宸?#37832;?#37832;?#37716;?#37731;?#37734;?#28003;?#37922;?/li>
  2. ?#33503;涓?#37721;?#28000;?#29722;?#23005;父缁?#28729;?#37714;扮墿?#24714;/铏氭嫙缃?#37719;?#28051;婇潰
  3. 瀹屽叏鍙?#37922;?/li>
3.3 ?#21412;缃?#29882;?#37922;?#29785;勫垯鏀寔

鍋?#29825;?#37812;戜滑鐨?code>tsung_client1杩?#37721;板?#23339;祴绔?#37832;?#37716;?#37731;紝缁?#28729;?#37813;鏈夐澶朓P鍦板潃鍒扮墿?#24714;缃?#37719;?code>eth1涓婏紝閭?#28052;堥渶瑕佹墜鍔?#23075;?#37716;犺矾鐢?#29785;勫垯锛?/p>

ip rule add iif eth1 tab 100
ip route add local 0.0.0.0/0 dev lo tab 100

杩?#28051;?#37824;?#37816;佸?#23339;祴绔?#32513;?#28729;?#37722;屼竴缃?#23048;?#37928;勫彲鐢IP鍦板潃?#32029;姣斿?#20634;?#23339;祴绔疘P?#36127;172.16.247.130?#32029;172.16.247.201鏆傛椂绌?#38338;?#37928;?#29831;濓紝閭?#37812;戜滑灏?#37721;?#28000;?#28003;?#37922;?72.16.89.201杩?#28051;狪P鍦板潃鐢?#27996;?#37720;嬫祴銆傛?#26882;涓嶈?#20345;眰琚?#37720;嬫祴鐨?#37832;?#37716;?#37731;厤缃?#28000;涔?#37510;?/p>

3.4 杩?#38339;讹紝鎴戜滑浣?#37922;竴涓柊鐨勭綉娈?#28051;?#37922;?#27996;庢?#23341;瘯

姣斿 10.10.10.0 杩?#28051;?#23048;?#37928;処P鏈?#37812;?#37830;傛椂?#30149;鏈?#28003;?#37922;紝閭?#37812;戜滑涓?#37922;?#27996;?#37720;嬫祴浣?#37922;紝杩?#37837;蜂竴鍙?#37832;?#37716;?#37731;?#28751;?#37832;?#27996;?50澶?#28051;?#37721;?#37922;?#37928;処P鍦板潃浜?#37510;?/p>

鍘嬫祴绔?#37715;嶉潰宸?#32513;忛厤缃?#28610;?#27996;嗭紝鐜板湪?#28214;瑕佷负琚?#37720;嬫祴鐨?#37832;?#37716;?#37731;?#23075;?#37716;犺矾鐢?#29785;勫?#27417;紝杩?#37837;?#37734;?#37725;嶅簲鏁版嵁鍖?#37928;勬椂鍊?#38003;藉璺?#37922;?#37714;板?#23339;祴绔?#38171;?/p>

route add -net 10.10.10.0 netmask 255.255.255.0 gw 172.16.247.130

璁?#32515;?#28729;?#37812;愶紝鍙?#28000;?#38315;?#26473;?code>route -n鍛?#28000;?#37836;?#37930;嬪綋鍓嶆墍鏈?#29882;?#37922;?#29785;勫垯锛?/p>

锟?/p>

鍦?#28051;嶉渶瑕佹椂?#32029;鍙?#28000;?#37714;?#38340;?#37818;?#38171;?/p>

route del -net 10.10.10.0 netmask 255.255.255.0

灏?#32513;?/h3>

姊崇悊浜?#28000;?#28051;?#37813;鑳藉?#29112;兂鍒?#37928;?#37826;?#23534;忥紝浠?#28751;藉彲?#20824;绐佺?#26449;崟鏈?#37928;?#38340;?#37714;讹紝鏍稿績杩?#37828;?#28751;藉彲?#20824;鎵?#37714;?#29906;?#28598;熷鍙?#37922;?#37928;処P鍦板潃?#32029;鍒?#37922;Linux鍐?#37837;哥?#35268;?#37824;?#37816;侊紝绋嬪簭?#30512;?#28528;缁?#28729;?#28751;藉彲鑳藉鐨処P鍦板潃?#32029;寤虹?#23339;?#26449;鐨勫?#29808;杩?#37818;?#37510;傚綋?#21159;浠?#28051;婃病鏈?#38000;?#38095;戠被浼?#27996;嶤PU銆?#37712;?#28699;?#32475;?#29863;勬簮闄?#37714;讹紝瀹?#38340;?#37823;嶄綔?#26882;?#32029;杩?#37828;渶瑕佽?#38095;?#26473;?#27996;?#29863;勬簮鐨?#38340;?#37714;?#37928;?#37510;?/p>

nieyong 2016-08-16 21:17 鍙?#29723;?#29831;?#29825;?/a>
]]>Tsung绗?#29825;?#28052;?00涓?#37922;埛鍘嬫?#23339;墽琛屾楠瘒http://www.8634070.com/yongboy/archive/2016/08/08/431498.htmlnieyongnieyongMon, 08 Aug 2016 13:31:00 GMThttp://www.8634070.com/yongboy/archive/2016/08/08/431498.htmlhttp://www.8634070.com/yongboy/comments/431498.htmlhttp://www.8634070.com/yongboy/archive/2016/08/08/431498.html#Feedback1http://www.8634070.com/yongboy/comments/commentRss/431498.htmlhttp://www.8634070.com/yongboy/services/trackbacks/431498.html鍓嶈

鎬?#37828;?#29831;?#32513;嗚妭銆佺悊璁猴紝浼?#29825;?#27996;?#28051;嶈鍏剁儲銆傛?#25116;滑浣?#37922;Tsung?#28533;?#31476;娆?00涓?#37922;埛鍘嬫祴鐨勫惂?#32029;鎴?#29825;?#38003;藉寮曡?#23792;?#34249;浜?#37928;勫叴瓒?:))

涓嬮潰?#32029;鎴戞?#35268;嵁鍦?#37711;?#37721;?#37714;?#27996;?#37928;PPT銆?#37714;嗗竷寮忕櫨涓?#37922;埛鍘嬫祴浣?#37928;?#28051;?#37716;?#37510;嬶紝璐村嚭鍏?#28051;?#37928;勫叧閿?#38318;?#37714;嗭紝璇?#37828;?#26473;?#29723;屼竴娆?00W(鍗?M)鐢埛鍘嬫祴鐨?#37813;?#29723;屾楠?#37510;?/p>

濡備綍?#20187;鍒嗗竷寮忕櫨涓?#37922;埛鐨勫?#23339;祴 锛?/h3>

鍋?#28729;氶潰鍚?#28751;忕櫧鐢埛?#32029;?#27932;姝?#37813;?#37832;?#27996;?#28051;嬮潰鍙?#37813;?#29723;?#37928;?0涓?#23005;?#26976;?#37922;?#27996;?#23534;灞?#37714;嗗竷寮忕櫨涓?#37922;埛銆?/p>

锟?/p>

鐪嬬潃姝?#26976;?#23536;堝?#27710;紝?#31476;鏃?#37908;熸倝?#33503;鎺屾彙涔嬪悗?#32029;涓?#38338;村彲浠?#37930;?#37719;磋嫢骞?#37510;?/p>

1. 闃?#29831;Tsung鏂?#22935;?/h4>

锟?/p>

?#32531;璁?#28598;?#28729;?#37734;?#28003;?#37922;Tsung涔?#37715;嶏紝?#23027;璐逛竴?#20579;?#26882;闂?#38339;?#29831;?#28729;?#37825;?#28051;?#37922;埛?#22684;鍐岋紝?#27367;?#21159;鏄?#38011;?#37826;?#37928;勶紝闃?#29831;昏?#38155;潵涔?#28051;嶅?#23942;潅銆?#29831;?#28729;?#28052;嬪悗?#32029;鎴戜滑涔?#28751;?#37933;?#38316;撳?#20633;綍?#20187;娴嬭瘯浜嗭紝閬?#37714;?#37928;勫閮?#37714;?#38338;?#26864;橈紝涔?#38003;藉?#29111;湪閲岄潰鎵?#37714;?#32475;?#22935;?#37510;?/p>

2 纭?#28729;氬?#23339;?#23340;洰鏍?/h4>

锟?/p>

  • 瑕?#28725;圭嚎涓婄郴缁熷?#23339;祴100涓?#37922;埛?#32029;?#36127;浜?#28751;藉彲?#20824;闄?#28003;庣嚎涓?#37832;?#37716;?#37731;?#29840;?#26462;藉?#23338;?#28083;紝杩?#38322;?#29825;?#32515;?#23011;?#32457;?#27996;?#37922;?00涓?#37922;埛?#32029;灏嗗湪60鍒嗛挓鍐?#27996;?#37922;?#28729;屾瘯
  • 瑕佸?#23339;祴鐨?#37832;?#37716;?#37731;?#37813;濉?#37712;?#32515;戠粶璁?#38338;?#37734;板潃鍙?#28000;?#37837;规嵁?#28214;瑕佸鍐?#28598;?#28051;?/li>

3. 璁?#32480;?#37813;?#28214;瑕佷粠鏈?#37825;伴噺

锟?br/> 锟?br/> 锟?br/> 锟?br/> 锟?br/> 锟?/p>

  • Tsung?#36127;涓?#28000;庢鍨嬶紝鎴戜滑鍚?#37716;?#27996;?#28051;昏?#20636;偣涔嬪悗?#32029;涓昏?#20636;偣浼氭?#22800;渶鍚?#37716;?#28000;庤?#20636;偣
  • 璁?#28729;?#37813;鐢?#37832;?#37716;?#37731;?#37721;?#37922;?#37712;?#28699;?#28598;?#27996;?G?#32029;?#33503;涓?#38318;藉彧鏈変竴涓狪P鍦板潃
  • ?#31476;鍙?#28000;?#37832;?#37721;?#37922;?#22959;?#37815;?涓?#37922;埛?#32029;?#28214;瑕?7鍙?#28000;?#37832;?/li>
  • ?#23266;璧勬簮鍏?#29906;筹紝鍙?#28000;?#28751;戠敤?#22161;鍙?#37832;?#37716;?#37731;紝?#21412;缃?#28598;?#28051;狪P鍦板潃
  • 鎵?#37714;?#37813;?#28214;瑕?#37928;勫?#23339;祴鐢?#37832;?#37716;?#37731;紝鍦?#29863;勬簮?#30512;?#28528;婊?#29906;虫?#23341;?#26335;?#23341;瘯闆嗙兢?#28214;瑕侊紝杩?#28051;?#37828;?#37711;?#38335;?/li>

4. 閮?#32515;Tsung

锟?/p>

?#27932;?#36127;Tsung渚?#29863;?#27996;嶦rlang?#32029;?#27932;姝渶瑕?#26851;?#37711;?#28729;夎锛?/p>

wget https://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
sudo yum install erlang

?#21159;鍚?#37712;?#37828;?#28729;夎?#21297;sung?#32029;?#32531;璁?#37929;?#37818;?#28003;?#37922;Tsung 1.6.0淇?#37824;?#37911;堬紝涓?#29781;佹?#24874;緵IP鍙?#26473;炴敮?#23508;锛堝叿浣?#32513;嗚?#20646;紝鍙?#37721;傝?#26473;?#38322;?git clone https://github.com/weibomobile/tsung-1.6.0.git ./configure --prefix=/usr/local make install

5. 涓嬭浇SSH鏇?#28000;?#38000;?#38171;?code>tsung鈥攔sh

锟?/p>

?#36127;浠涔?#29781;佹浛鎹?#37818;塖SH?#32029;涓?#29781;佸?#29111;洜锛?/p>

  • SSH鍦竴鑸?#32515;戠粶鏈?#37812;跨幆澧?#37712;?#37832;?#37716;?#37731;?#28052;?#38338;?#29722;?#32450;佹杩?#37818;?#38315;氫俊?#32029;杩?#28028;?#28725;?#38007;?#28051;昏?#20636;偣鏃犳硶鍚?#37716;?#28000;庤?#20636;偣?#32029;鏃犳硶寤虹?#23338;垎甯?#23534;忓?#23339;?#23342;?#21977;兢
  • 灏?#32480;?#37828;疭SH?#30149;琚?#32450;?#37922;紝涓?#28000;?#28052;?#38338;撮渶瑕?#29825;?#32515;?#37711;?#32457;?#38333;SSH鐧诲綍鏂?#23534;忥紝鍗?#37714;嗛?#33636;儲

鍙?#26473;涗竴姝?#37721;傝?#38171;?a href="http://www.8634070.com/yongboy/archive/2016/07/27/431340.html">Tsung绗?#29825;?#28052;嬪垎甯?#23534;?#28583;?#23534;鸿烦鍑SSH缇佺?#23108;瘒銆?/p>

6. 缂?#37712;?#37720;嬫?#23338;唴瀹?/h4>

锟?br/> 锟?br/> 锟?/p>

瑕佹妸涓?#37716;?#28729;?#28052;?#37928;?#37813;鏈変細璇?#37712;?#28729;?#28729;?#37825;?#37928;?#37825;寸悊鏄?#28751;?#37812;怲sung鐨?#28028;?#29831;?#37712;?#28729;癸紝?#27932;?#36127;鐢埛琛屼负寰堝?#23942;潅?#32029;涔熼渶瑕佹?#25116;滑鎯虫硶璁炬硶鍘绘鎷?#37510;?/p>

鍏?#28729;烇紝婕旂鎵浣?#37922;?#37928;?#37828;?#32457;?#37832;?#37719;?#29825;紝鍙?#28000;?#37721;傝?Tsung绗?#29825;?#28052;嬫彃浠剁紪鍐欑瘒 銆?/p>

?#32139;瀹?#37812;?#37720;嬫祴浼?#29831;?#37712;?#28729;?#28052;嬪悗?#32029;users_100w.xml鏂?#28000;?#23480;?#32513;忓鍐?#28729;屾?#26346;紝鎴戜滑鍙?#28000;?#23534;濮嬪?#23339;祴浜?#37510;?/p>

7. 杩?#29723;孴sung

锟?/p>

  • -F 10.10.10.10 涓昏?#20636;偣IP鍦板潃?#32029;IP鐩?#26473;炵?#35268;?/li>
  • -rsh rsh_client.sh 杩?#32459;嬬粓绔紝SSH閫?#38316;?#29722;?#37831;?#37817;?/li>
  • -s 鍘嬫祴绔?#37722;?#37922;erlang smp鐗规紝鎸夐渶浣?#37922;?#37813;鏈塁PU鏍稿績

鎴戜滑鍚?#37716;?#27996;?#28000;庤?#20636;偣?#32029;?#21159;鍚?#28000;庤?#20636;偣琚?#37722;?#37716;紝寮濮嬫墽琛屽叿浣?#37720;嬫祴浠?#37716;?#27996;?#37510;?/p>

8. 鍘嬫祴杩?#32459;?#28051;紝鎴戜滑璇仛浠涔?/h4>

锟?/p>

?#25571;瀵嗗?#34411;敞鏈?#37716;?#37731;?#37832;?#37716;姸鎬?#37510;佽?#21228;簮鍗?#37922;?#32475;夋儏鍐?#28751;?#28725;?#27996;嗭紝鏈濂?#26473;?#29781;佷綔?#36127;?#31476;涓粓绔?#37922;埛鍙?#28051;?#37714;?#27996;?#37725;佷綋楠?#28051;?#37720;?#37510;?/p>

9. 鍘嬫祴缁?#37833;燂紝鐢?#37812;怲sung鎶?#29723;?/h4>

锟?/p>

Tsung鍘嬫祴缁?#37833;?#28052;嬪悗?#32029;涓?#28028;?#28051;?#37716;?#37922;?#37812;?#37720;嬫祴缁?#37835;?#37814;?#29723;?#37928;勶紝?#28214;瑕佸?#37716;?#27996;?tsung_stats.pl perl鑴?#37832;?#37922;?#37812;愶紝瑕佹煡闃?#37721;?#37706;?#37716;python鐢?#37812;?#28051;碬eb绔欑偣?#32029;娴?#29785;堝櫒鎵?#23534;鍗?#37721;?#37510;?/p>

10. 鍥?#26916;?#37724;屾?#32513;?/h4>

锟?/p>

灏?#32513;?/h3>

鍏?#28729;烇紝?#31476;鏃?#37908;熸倝?#33503;鎺屾彙Tsung涔嬪悗?#32029;姝?#26976;?-6閮藉彲浠?#38010;傜?#20343;?#21997;紝寰幆鎵?#29723;屾楠?-10銆?/p>

浣犺嫢浠负浠?#28000;?#37721;?#37828;?#29835;?#29825;篢sung濡備綍?#20187;1M鐢埛鍘嬫?#23350;紝閭?#28751;遍敊浜嗭紝鍙?#29781;?#37832;哄櫒璧勬簮澶燂紝杩?#28051;洰鏍囧氨寰?#28729;规槗瀹?#37916;?#37510;傛?#25116;滑鏇村?#26055;鍏虫敞?#32029;鎴戜滑鍘嬫祴鐨勭洰鐨?#37828;?#28000;涔堬紝鎴戜滑搴旇鍏虫敞浠涔堬紝杩?#28051;?#25652;旇?#33328;鎴愪竴涓?#28729;?#37825;村彲寰幆杩?#32459;嬶紝椹?#37716;潃绯?#32513;熸灦鏋勫搴?#37711;?#37715;嶅?#25117;睍銆?/p>

nieyong 2016-08-08 21:31 鍙?#29723;?#29831;?#29825;?/a>
]]>Tsung绗?#29825;?#28052;嬫彃浠剁紪鍐欑瘒http://www.8634070.com/yongboy/archive/2016/07/30/431396.htmlnieyongnieyongSat, 30 Jul 2016 11:37:00 GMThttp://www.8634070.com/yongboy/archive/2016/07/30/431396.htmlhttp://www.8634070.com/yongboy/comments/431396.htmlhttp://www.8634070.com/yongboy/archive/2016/07/30/431396.html#Feedback0http://www.8634070.com/yongboy/comments/commentRss/431396.htmlhttp://www.8634070.com/yongboy/services/trackbacks/431396.html鍓嶈

Tsung瀵瑰叿浣?#37719;?#29825;?#37510;?#38315;?#38316;?#37928;勬敮鎸侊紝?#31476;鑸?#28000;?#37819;?#28000;跺舰寮忔?#24874;緵鎺?#37721;紝鎺?#37721;?#28051;?#37828;?#23536;堝?#23942;潅?#32029;鎻?#28000;?#28052;?#23536;?#28729;规?#25782;紪鍐欙紝鏀寔鍗?#29825;?#28598;氾紝涔?#28751;?#28051;嶈冻?#36127;鎬?#27996;?#37510;?/p>

涓嬮潰棣?#37711;堟?#23815;?#21973;竴涓嬪綋鍓峊sung 1.6.0鎵鏈?#37712;?#32515;?#37819;?#28000;讹紝?#21159;鍚庝负?#31476;涓?#37722;?#32457;颁负Qmsg鐨勭鏈?#27996;?#26473;?#37714;?#37719;?#29825;?#32514;?#37712;?#37819;?#28000;? 杩?#29723;Qmsg鏈?#37716;?#37731;?#32468;?#32459;嬪簭?#32029;鎵?#29723;屽?#23338;姏娴嬭?#26346;紝鏈鍚庢煡鐪嬫?#23341;瘯鎶?#37723;?#37510;?/p>

宸?#37824;?#37816;佹彃浠舵?#23815;悊

Tsung 1.6.0鏀寔鐨勫崗璁?#23536;堝?#27710;紝绠鍗曟?#23815;?#21973;竴涓?#38171;?/p>

Tsung Controller  Support Plugins V2-1锟?/p>

  • 鍘嬫祴鐨勫崗璁?#26851;?#37711;堥渶瑕佹敮?#23508;xml?#33328;寮忛厤缃紝?#21412;缃?#37712;?#28729;归渶瑕?tsung_config_protocolname 妯潡瑙?#37835;?
    • 瀛樻斁鍦tsung_controller?#27952;?#32141;涓?/li>
  • 鍏舵鏄痶sung client绔?#28052;?#29781;佹彃浠?ts_protocolname 妯潡鏀寔鏁版嵁鎿嶄綔
    • 瀛樻斁鍦tsung?#27952;?#32141;涓?/li>
  • 鍚屾椂鍦tsung椤圭洰examples?#27952;?#32141;涓?#28052;?#32513;?#37713;?#27996;?#23480;?#37824;寔鍗?#29825;厤缃?#32480;鍗曠?#40511;寖xml鏂?#28000;?/li>

宸?#32513;?#37824;寔鍗?#29825;?#32480;鍗曡鏄?#38171;?/p>

  1. amqp?#32029;Advanced Message Queuing Protocol缂?#37712;欙紝鍙?#29781;佹敮鎸侀珮绾?#23057;堟伅?#27110;鍒?#37719;?#29825;?#37928;勫簲鐢紝閮藉彲浠?#37922;潵鍋氬?#23339;?#23350;紝姣斿?#20417;abbitMQ?#32029;ActiveMQ绛?/li>
  2. http?#32029;?#29056;鏈?#37719;?#29825;紝鏋勫缓浜嶩TTP鍗?#29825;?#28052;?#28051;?#37928;勶紝杩?#37832;?#32491;?#28028;?#27996;嶣OSH?#32029;WebDav绛?#28051;婂眰涓?#37716;?#37719;?#29825;?/li>
  3. jabber?#32029;涔熺涔嬩负XMPP?#32029;鏀寔鐨勭浉?#32139;涓板瘜?#32029;闄?#27996;員CP/SSl?#32029;杩?#37721;?#28000;?#38315;?#26473;Websocekt杩?#29723;?#28028;?#38315;?/li>
  4. raw?#32029;閽堝?#29808;師濮?#32491;诲?#23339;?#22559;伅?#32029;涓嶅仛缂?#29785;?#37934;?#28598;勭?#21997;紝鐩?#37818;?#37734;TCP / UDP / SSL绛変?#29370;?#25779;眰涓?#28028;?#38315;掞紝杩?#28051;?#28725;?#38318;?#37714;?#32457;?#37832;?#37719;?#29825;紝姣旇緝鍙嬪?#26020;紝涓?#37922;?#37712;?#37719;曠嫭鐨勭紪瑙?#37934;?#28598;勭?#21997;紝鐩?#37818;?#38315;?#28028;犲浜?/li>
  5. shell?#32029;閽堝?#31553;Inux/Unix?#31891;绔?#37723;?#28000;皟鐢?#26473;?#29723;屽?#23339;?#23350;紝杩?#32457;嶅?#28888;櫙姣旇緝灏?#28028;?/li>
  6. fs?#32029;filesystem缂?#37712;欙紝閽堝?#35268;枃浠剁郴缁?#37928;?#29831;?#37712;?#37804;兘杩?#29723;屽?#23339;祴
  7. job?#32029;閽堝浠?#37716;皟搴?#32459;嬪簭杩?#29723;?#37928;勫?#23339;?#23350;紝姣斿?#20414;BS/torqueLSF銆丱AR绛?/li>

Tsung鎻?#28000;?#23480;綔鏈?#37714;?/h3>

绮椾竴?#20579;?#28533;鐪婽sung鎻?#28000;?#37928;勫伐?#32148;娴?#32459;?#38171;堢偣鍑?#37721;?#28000;?#37930;嬪鍥?#38171;?#38171;?/p>

tsung_qmsg_flo锟?/a>

鏀?#28598;竴浜?#38171;?#23534;?#37922;?hncscwc ?#23845;瀹?#37733;?#37911;囷紝鐩稿綋璧?#38171;?#38171;?#38171;?/p>

?#36127;浠涔?#29781;佺紪鍐?#37819;?#28000;?/h3>

Tsung閽堝閫?#37922;?#37719;?#29825;?#37832;夋敮鎸侊紝?#23266;鏄?#32457;?#37832;?#37812;?#28051;?#38317;?#28052;?#38315;?#37922;?#37928;勫崗璁紝灏?#28051;?#28028;?#37832;?#28051;?#38338;?#37928;勬彃浠?#37824;?#37816;佷?#21997;紝閭?#28052;堝彲閫?#37928;?#37832;?#28051;?#37833;?#29882;?#28699;?#38171;?/p>

  • 浣?#37922;raw妯?#23534;忓彂閫佸師濮嬫?#22559;伅?#32029;?#28214;瑕?#38007;?#29723;?#32513;勮
  • 鑷?#23480;辩紪鍐?#37819;?#28000;讹紝鐏垫椿澶勭悊缂?#29785;?#37934;?/li>

鏃劧璋堝埌浜嗘彃浠讹紝鎴戜滑涔熺紪鍐欎竴涓?#37819;?#28000;?#28052;?#28003;?#26976;屼竴涓嬬紪鍐?#37819;?#28000;?#37928;?#26473;?#32459;?#37510;?/p>

Qmsg鍗?#29825;?#28729;?#28052;?/h3>

鍋?#29825;句竴涓?#38095;氭?#29111;?#28888;櫙?#32029;鎵?#38315;犱竴涓柊鐨勫崗璁甉msg?#32029;浜?#26473;?#37714;?#37837;?#23534;?#32513;?#37812;?#38171;?/p>

qmsg_protoco锟?/p>

杩?#32457;嶉殢鎰忓?#22250;薄鍑烘潵鐨?#37837;?#23534;忥紝涓嶅绉颁綔?#36127;qmsg锛圦鍙?#37910;卞舰寮?#37928;刴essage锛?#37719;?#29825;紝浠呬綔?#36127;Demo婕旂?#40511;?#28699;?#37734;?#37510;傜畝鍗?#37734;烘櫙锛?/p>

  • 鐢埛鍙戣?#32029;鍖?#37722;?#37922;埛id鍜屽彂瑷鍐?#28729;?
    • User ID?#32029;32浣嶈嚜?#21159;鏁扮?#35826;瀷
    • 鍙戣?#36127;鏂?#28699;?#37712;?#28729;癸紝瀛?#32471;?#28051;插舰寮忥紝闀?#25652;?#28051;嶅浐瀹?/li>
    • 缁勮鍚?#37928;?#29831;锋眰浣撲负浜?#26473;?#37714;?#37719;?#29825;?#37837;?#23534;?/li>
    • PocketLen:**##UserId + UserComment##**
  • 鏈?#37716;?#37731;?#32468;?#26473;?#37733;?#37922;埛ID鍜屼竴涓?#39582;?#26473;?#37825;板瓧(32浣嶈绀?
    • PocketLen:**##UserId + RandomCode##**

?#36127;浜嗗崱?#25648;浼婁竴浜涳紝澶?#27996;嗕竴浜涚偣?#32017;鐨?#37413;?*####**鈥?#32471;?#37721;?#37510;?/p>

缂?#37712;欎竴涓?#28729;?#37825;存彃浠?/h3>

杩?#38322;屽熀浜嶵sung 1.6.0鐗?#37832;?#37835;勫缓?#31476;涓猀msg鎻?#28000;讹紝鍋?#28729;?#28003;犳?#20633;竴浜汦rlang浠?#37934;侊紝浠?#37721;?#37908;熸倝Tsung?#31476;浜涘熀鏈?#20634;銆?/p>

0. 鍒涘缓?#31476;涓?#26916;圭洰

瑕?#37714;涘缓Tsung鐨勪竴涓猀msg鎻?#28000;?#26916;圭洰?#32029;?#27367;?#30149;鏈夊浐瀹?#29785;勮寖?#32029;浣嗘?#22796;収宸?#37832;?#37837;?#23534;?#32513;勭?#22247;浠?#37934;佸?#20636;骇涔?#37828;?#37832;夊繀瑕?#37928;?#37510;?/p>

鈹?#37433;鈹 include
鈹偮犅?鈹?#37433;鈹 ts_qmsg.hrl
鈹?#37433;鈹 src
鈹偮犅?鈹?#37433;鈹 tsung
鈹偮犅?鈹偮犅?鈹?#37433;鈹 ts_qmsg.erl
鈹偮犅?鈹?#37433;鈹 tsung_controller
鈹偮犅?    鈹?#37433;鈹 ts_config_qmsg.erl
鈹?#37433;鈹 tsung-1.0.dtd

1. 鍒涘?#27946;厤缃?#37826;?#28000;?/h4>

Tsung鐨勫?#23339;祴浠xml鏂?#28000;?#26937;?#37716;紝?#27932;姝渶瑕佺晫瀹氫竴涓猀msg鎻?#28000;跺舰寮?#37928;勫畬鏁?#28028;?#29831;?#37928;XML鍛堢?#24110;紝姣斿锛?/p>

<session probability="100" name="qmsg-demo" type="ts_qmsg">
    <request>
      <qmsg uid="1001">Hello Tsung Plugin</qmsg>
    </request>

    <request>
      <qmsg uid="1002">This is a Tsung Plugin</qmsg>
    </request>
</session>
  • ts_qmsg?#32029;浼?#29831;?#32491;诲?#23339;墍渚?#29863;?#37719;?#29825;?#22959;?#37815;?#28729;埛绔?#28729;?#37916;?/li>
  • <qmsg uid="Number">Text</qmsg> 瀹?#28052;?#27996;唓msg浼?#29831;?#37721;厤缃舰寮忥紝鍐呭?#23677;湪request鍏冪礌鍐?/li>
  • uid?#36127;灞炴?/li>

姝椂?#32029;浣犺嫢鐩?#37818;?#37734;xml鏂?#28000;?#28051;?#32514;栬緫?#32029;浼?#38316;?#37714;?#37837;?#26976;岄敊璇?#37510;?/p>

2. ?#27967;?#26570;DTD鏂?#28000;?/h4>

Tsung鐨剎ml鏂?#28000;朵緷璧?code>tsung-1.0.dtd鏂?#28000;?#26473;?#29723;屾牎楠岄厤缃?#37828;?#37722;?#37832;?#29831;紝?#28214;瑕佸仛瀵笵TD鏂?#28000;跺?#27691;慨鏀癸紝浠?#37824;?#37816;佹墍娣?#37716;犳柊鐨勫崗璁?#37510;?/p>

鍦?code>tsung-1.0.dtd椤圭洰涓紝鏈灏?#37824;寔锛?/p>

  1. session鍏冪礌type灞炴?#28051;?#23075;?#37716;?#28051;?ts_qmsg
  2. request鍏冪?#29362;?#21228;坊鍔?qmsg : <!ELEMENT request ( match*, dyn_variable*, ( http | jabber | raw | pgsql | ldap | mysql |fs | shell | job | websocket | amqp | mqtt | qmsg) )>
  3. 娣?#37716;qmsg鍏冪礌瀹?#28052;?#38171;?/li>
<!ELEMENT qmsg (#PCDATA) >
<!ATTLIST qmsg
    uid         CDATA   "0"
    ack         (local | no_ack | parse) #REQUIRED
    >

瀹?#37825;村唴瀹癸紝鍙?#37721;傝?code>tsung_plugin_demo/tsung-1.0.dtd鏂?#28000;?#37510;?/p>

3. 澶?#37826;?#28000;?include/ts_qmsg.hrl

澶?#37826;?#28000;?code>include/ts_qmsg.hrl瀹?#28052;?#37825;版嵁?#32346;瀛?#37928;勭粨鏋?#38171;?#28052;熺涔嬩负璁板綍/record锛?#38171;?/p>

-record(qmsg_request, {
          uid,
          data
         }).

-record(qmsg_dyndata, {
          none
         }
       ).
  1. qmsg_request: 瀛樺偍浠巟ml鏂?#28000;?#29785;?#37835;?#37928;剄msg璇?#23033;傛?#29256;嵁?#32029;鐢?#27996;?#37922;?#37812;?#37720;嬪姏璇锋眰
  2. qmsg_dyndata: 瀛樺偍鍔?#37804;?#37721;傛暟锛堝綋鍓嶆?#20635;湭浣?#37922;?#37714;?#38171;?/li>

4. XML鏂?#28000;?#29785;?#37835;?/h4>

ts_config_qmsg.erl鏂?#28000;讹紝鐢?#27996;庤鏋?#37724;屽崗璁甉msg鍏?#38001;?#37928;勯厤缃?#38171;?br/> - 鍙渶瑕?#28729;?#37916;?code>parse_config/2?#25966;?#31476;鏂规硶
- 瑙?#37835;xml鏂?#28000;?#28051;?#37813;?#21412;缃甉msg鍗?#29825;?#29831;?#23033;傜浉鍏抽厤缃?br/> - 琚?code>ts_config:parse/1鍦?#38316;?#37714;癚msg鍗?#29825;厤缃椂?#30367;鐢?/p>

澶?#23049;?#38171;?/p>

  1. ?#23266;瑕佹敮?#23508;鍔?#37804;佹浛鎹紝?#28214;瑕?#37928;勫瓧娈?#28000;?#28699;?#32471;?#28051;插舰寮?#29831;?#37724;?#28699;樺偍

5. ts_qmsg.erl

ts_qmsg.erl妯潡涓?#29781;佹?#24874;緵Qmsg鍗?#29825;?#37928;勭紪瑙?#37934;?#37928;勫畬鏁村姩?#32148;, 浠?#37721;婂綋鍓嶅崗璁?#37923;?#28729;?#28051;?#37928;勭敤?#22491;浼?#29831;?#28766;炴?#29825;?#28729;?#37510;?/p>

棣?#37711;堥渶瑕?#28729;?#37916;?#37818;?#37721;?code>ts_plugin瑙勮寖瀹?#28052;?#37928;?#37813;鏈夐渶瑕?#37713;?#37825;帮紝瀹?#28052;?#27996;嗗?#20635;?#26495;?#37724;?#26473;?#37733;炲?#37510;?/p>

-behavior(ts_plugin).

...

-export([add_dynparams/4,
         get_message/2,
         session_defaults/0,
         subst/2,
         parse/2,
         parse_bidi/2,
         dump/2,
         parse_config/2,
         decode_buffer/2,
         new_session/0]).

鐩?#28725;规潵璇达紝鏍稿績?#36127;鍗?#29825;?#37928;勭紪瑙?#37934;?#37716;熻兘锛?/p>

  • get_message/2?#32029;鏋?#38315;?#29831;?#23033;傛?#29256;嵁?#32029;缂栫?#20345;?#24874;簩杩?#37714;讹紝涓婂眰ts_client妯潡閫?#26473;Socket杩?#37818;?#37721;?#38315;佺粰?#27952;鏍?#37832;?#37716;?#37731;?/li>
  • parse/2?#32029;(?#32139;瀵瑰?#23941;簲?#32148;鍑?#37837;?#26976;屾椂)浠?#37720;?#28654;婼ocket涓?#26473;?#37733;?#37928;?#37825;版嵁杩?#29723;岃鐮侊紝鍙?#37713;?#37719;?#29825;?#28729;?#28052;?#28051;?#37716;?#37712;?#28729;?/li>

杩?#38318;?#37714;?#28000;?#37934;?#37721;?#28000;?#37721;傝?tsung_plugin_demo/src/tsung/ts_client.erl 鏂?#28000;?#37510;?/p>

6. 濡備綍缂?#29831;?/h4>

?#27367;?#21159;?#24714;璁?#28051;婂彲浠?#37719;曠嫭缂栵紝鐢?#37812;?#37928;beam鏂?#28000;?#37929;?#37818;?#37815;?#29840;?#37714;板凡缁?#28729;夎鐨則sung瀵瑰?#26050;洰?#32141;涓嬮潰?#32029;浣?#28729;?#38340;?#28051;?#37819;?#28000;剁紪鍐?#26473;?#32459;?#28051;?#29781;佷緷璧?#28598;?#28051;猼sung鐨刪rl鏂?#28000;讹紝杩?#38315;?#37812;愪簡渚?#29863;?#29882;?#23536;?#38338;?#26864;?#37510;傞噰鐢?#37929;?#37818;?#37724;宼sung鎵?#37718;呬竴璧?#38318;?#32515;诧紝瀹?#38340;?#37823;嶄綔涓?#37832;?#27996;?#27001;荤儲?#32029;

?#36127;浜嗚?#20636;?#20343;綋鍔涳紝浣?#37922;竴涓猻hell鑴?#37832;?- build_plugin.sh?#32029;鏂?#28186;垮揩閫熺紪璇?#37510;?#38318;?#32515;?#38171;?/p>

# !/bin/bash

cp tsung-1.0.dtd $1/
cp include/ts_qmsg.hrl $1/include/
cp src/tsung_controller/ts_config_qmsg.erl $1/src/tsung_controller/
cp src/tsung/ts_qmsg.erl $1/src/tsung/

cd $1/
make uninstall
./configure --prefix=/usr/local
make install

杩?#38322;屾寚瀹?#28729;夎?#21297;sung鐨勬寚瀹氱洰?#32141;?#36127;/usr/local?#32029;鍙?#28000;?#37837;规嵁?#28214;瑕佷慨鏀?/p>

?#28214;瑕佹彁鍓嶅?#21975;?#22247;tsung-1.6.0?#27952;?#32141;锛?/p>

wget http://tsung.erlang-projects.org/dist/tsung-1.6.0.tar.gz
tar xf tsung-1.6.0.tar.gz

鍦?#32514;?#29831;慟msg鎻?#28000;?#38004;?#37832;椂, 鎸?#28729;氫竴涓媡sung-1.6.0瑙?#37720;嬪悗鐨勮矾寰勫嵆鍙?#38171;?/p>

sh build_plugin.sh /your_path/tsung-1.6.0

鍚庨潰鍢涳紝灏?#32475;夌潃鑷?#37716;?#32514;?#29831;戝拰瀹夎鍛?#37510;?/p>

鍚?#37716;Qmsg鍗?#29825;?#37928;勫?#23339;祴

1. 棣?#37711;?#37722;?#37716;Qmsg鏈?#37716;?#37731;?#32468;?#32459;嬪簭

鏃劧鏈?#37720;嬫祴绔紝灏遍渶瑕佷竴涓猀msg鍗?#29825;?#28598;勭悊鐨勫悗绔?#32459;嬪簭qmsg_server.erl?#32029;鐢?#27996;庢帴鏀?#28729;埛绔?#29831;锋眰?#32029;?#24143;寰?#37922;埛ID鍊?#28052;嬪悗?#32029;鐢?#37812;愪竴涓殢鏈?#37825;板瓧?#32029;缁勮鎴愪簩杩?#37714;?#37719;?#29825;紝?#21159;鍚?#37721;戠粰瀹埛绔紝杩?#28751;?#37828;?#37711;?#38318;?#37716;熻兘銆?/p>

杩?#28051;?#32459;嬪簭?#32029;绠鍗曚竴涓?#37826;?#28000;讹紝鍦?tsung_plugin_demo?#27952;?#32141;涓嬮潰?#32029;缂?#29831;?#26473;?#29723;? 榛?#29825;?#37929;?#37722;?678绔?#37721;?#38171;?/p>

erlc qmsg_server.erl && erl -s qmsg_server start

鍙?#28598;栵紝杩樻?#24874;緵浜嗕竴涓墜鍔皟鐢?#37818;?#37721;紝鏂?#28186;?#37734;Erlang Shell绔皟璇?#38171;?/p>

%% 涓嬮潰?#36127;
qmsg_server:sendmsg(1001, "杩?#38322;?#37828;?#37922;埛鍙戣").

鍚?#37716;?#28052;嬪悗?#32029;鐩?#37722;?#37734;板潃 *: 5678

?#31790;鐮佽锛?code>tsung_plugin_demo/qmsg_server.erl

2. 缂?#37712;Qmsg鍘嬫祴XML?#21412;缃?#37826;?#28000;?/h4>

?#27932;?#36127;鏄?#23125;旂?#34425;?#40511;寖?#32029;?#31476;鍙癓inxu涓?#37832;?#28051;?#28751;?#37721;?#28000;?#26473;?#29723;?#27996;?#38171;?/p>

  • 杩?#37818;?#37832;?#37832;?#37928;?127.0.0.1:5678
  • 鏈澶?#27996;?#37922;?0涓?#37922;埛?#32029;姣?#32457;?#27996;?#37922;?涓紝鍘嬪姏璐?#26462;?#29825;?#32515;?#37928;勫緢浣?/li>
  • 涓?#28051;?#28051;?#37722;岀?#35826;瀷浼?#29831;濓紝姣旈噸10% + 90% = 100%
  • qmsg-subst-example浼?#29831;?#28003;?#37922;?#27996;?#37922;埛ID涓?#37724;?#37922;埛鍙戣鍐?#28729;?#38007;?#37716;?#37922;?#37812;?#37832;?#37714;?/li>
<tsung loglevel="debug" dumptraffic="false" version="1.0">
  <clients>
    <client host="localhost" use_controller_vm="true"/>
  </clients>

  <servers>
    <server host="127.0.0.1" port="5678" type="tcp"/>
  </servers>

  <load>
    <arrivalphase phase="1" duration="1" unit="minute">
      <users maxnumber="10" interarrival="1" unit="second"/>
    </arrivalphase>
  </load>

  <sessions>
    <session probability="10" name="qmsg-example" type="ts_qmsg">
      <request>
        <qmsg uid="1001" ack="parse">Hello Tsung Plugin Qmsg!</qmsg>
      </request>
    </session>
    <session probability="90" name="qmsg-subst-example" type="ts_qmsg">
      <setdynvars sourcetype="random_number" start="3" end="32">
        <var name="random_uid"/>
      </setdynvars>
      <setdynvars sourcetype="random_string" length="13">
        <var name="random_txt"/>
      </setdynvars>
      <request subst="true">
        <qmsg uid="%%_random_uid%%" ack="parse">Haha : %%_random_txt%%</qmsg>
      </request>
      <thinktime value="6"/>
      <request subst="true">
        <qmsg uid="%%_random_uid%%" ack="parse">This is a Tsung Plugin</qmsg>
      </request>
    </session>
  </sessions>
</tsung>

杩?#38318;?#37714;嗗唴瀹癸紝璇?#37721;傝?tsung_plugin_demo/tsung_qmsg.xml 鏂?#28000;?#37510;?/p>

3. 鎵?#29723;屽?#23338;姏娴嬭瘯

?#32139;Qmsg鐨勫?#23338;姏娴嬭瘯?#21412;缃?#37826;?#28000;?#37712;?#28610;?#28052;嬪悗?#32029;鍙?#28000;?#23534;濮嬫墽琛屽?#23338;姏娴嬭瘯浜?#38171;?/p>

tsung -f tsung_qmsg.xml start

鍏?#26440;?#37713;?#38171;?/p>

tarting Tsung
Log directory is: /root/.tsung/log/20160621-1334
[os_mon] memory supervisor port (memsup): Erlang has closed
[os_mon] cpu supervisor port (cpu_sup): Erlang has closed

鍏?#28051;? 鍏舵棩蹇椾负锛?code>/root/.tsung/log/20160621-1334銆?/p>

4. 鏌?#37930;嬪?#23339;?#23339;姤鍛?/h4>

杩?#37711;?#37711;?#37922;?#37812;?#37720;嬫?#23339;棩蹇楃洰?#32141;?#32029;?#21159;鍚?#37922;?#37812;?#37814;?#29723;紝鏌?#37930;嬪?#23339;祴缁?#37835;滃搱锛?/p>

cd /root/.tsung/log/20160621-1334

/usr/local/lib/tsung/bin/tsung_stats.pl

echo "open your browser (URL: http://IP:8000/report.html) and vist the report now :))"
/usr/bin/python -m SimpleHTTPServer

鍡紝鎵?#23534;浣?#37928;勬祻瑙堝櫒?#32029;杈?#37713;?#37813;鍦?#37832;?#37716;?#37731;?#37928;処P鍦板潃?#32029;灏?#37721;?#28000;?#37930;嬪?#26495;?#23339;祴缁?#37835;?#27996;?#37510;?/p>

灏?#32513;?/h3>

浠?#28051;?#28000;?#37934;?#23480;?#32513;?#37824;?#37711;github浠?#25652;?#38171;?a href="https://github.com/weibomobile/tsung_plugin_demo">https://github.com/weibomobile/tsung_plugin_demo銆?/p>

瀹?#38340;?#28051;?#37716;?#37928;勭鏈?#37719;?#29825;?#37712;?#28729;?#29781;佹瘮涓婇潰Demo鍑烘潵鐨凲msg澶嶆潅鐨勫?#27710;紝浣嗗?#21057;鏈?#37719;?#29825;?#37819;?#28000;剁紪鍐欙紝濡?#28051;婇潰鎵杩板嚑涓?#23005;?#26976;紝鎸夌収瑙勮?#20906;紪鍐欙紝鍗?#37832;烘?#23341;?#26346;紝?#21159;鍚庡欢浼?#37714;板垎甯?#23534;忛?#21977;兢?#32029;瀹?#37825;存祦绋嬮兘鏄竴鑷?#37928;?#37510;?/p>

鍡紝鎼?#28729;?#27996;嗘彃浠讹紝灏?#37721;?#28000;?#28725;?#32495;?#32513;?#37808;夊揩鍦?#26473;?#29723;屽?#23339;祴浜?:))



nieyong 2016-07-30 19:37 鍙?#29723;?#29831;?#29825;?/a>
]]>Tsung绗?#29825;?#28052;?#37929;戞帶鏁版嵁鏀?#38342;嗙瘒http://www.8634070.com/yongboy/archive/2016/07/29/431367.htmlnieyongnieyongFri, 29 Jul 2016 00:49:00 GMThttp://www.8634070.com/yongboy/archive/2016/07/29/431367.htmlhttp://www.8634070.com/yongboy/comments/431367.htmlhttp://www.8634070.com/yongboy/archive/2016/07/29/431367.html#Feedback0http://www.8634070.com/yongboy/comments/commentRss/431367.htmlhttp://www.8634070.com/yongboy/services/trackbacks/431367.html鍓嶈

鍘嬪姏娴嬭瘯鍜?#37929;戞帶鍒?#28051;?#23534;?#32029;鐩戞帶鑳藉璁板綍鍘嬫祴杩?#32459;?#28051;姸鎬侊紝鏂?#28186;?#38338;?#26864;?#29882;熻釜銆?#28729;?#28003;?#37510;傛湰?#30226;鎴戜滑灏?#29825;?#29825;?#28725;瑰?#23339;祴瀹埛绔痶sung client鐨勭?#25118;帶?#32029;浠?#37721;?#28725;硅鍘嬫祴鏈?#37716;?#37731;?#37928;勮?#21228;簮鍗?#37922;?#37929;戞帶绛?#37510;?#37722;屾椂?#32029;涔熸秹鍙?#37714;癟sung杩?#29723;屾椂鐨勫疄?#26882;璇?#37826;?#37826;?#23534;忥紝杩?#28052;?#37828;?#28725;筎sung?#31476;浜?#26473;?#29723;屾椂?#23032;鎬?#37928;?#28051;?#37716;?#37929;戞帶銆?/p>

鍘嬫祴瀹埛绔?#37928;勭?#25118;帶

鍘嬫祴绔?#38171;堟寚鐨?#37828;痶sung client锛変細鏀?#38342;嗘?#24526;竴涓?#37711;?#28003;撴鎷熺粓绔?#37922;埛锛堝嵆ts_client妯潡锛?#29723;屼负鏁版嵁?#32029;鍙?#38315;佺粰涓昏?#20636;偣锛tsung_controller锛夛紝渚?#37722;庨潰缁?#29825;?#37714;?#37835;愪娇鐢?#37510;?/p>

tsung_monitor_client锟?/p>

  1. ts_client妯潡?#30367;鐢ts_mon?#32029;鑰宼s_mon鍙?#37929;?#37818;皟鐢ts_mon_cache?#32029;鏈?#27996;?#32513;曪紝涓?#37929;?#29785;?#38171;?#38315;昏?#25117;眰?#28528;鍙?#36423;界暐鎺ts_mon锛?/li>
  2. count?#36127;璁?#37825;板櫒?#32029;sum琛?#32448;?#37722;?#26916;圭疮鍔犲硷紝sample鍜宻ample_counter璁?#32480;椾竴娆?#32513;?#29825;?#26916;?#37928;勫?#20914;?#22247;?amp;鏍囧噯宸?/li>
  3. tsung.dump鏂?#28000;朵竴鑸?#28051;?#28028;?#37714;涘缓&鍐?#37711;紝闄?#38344;?#28003;犲湪tsung.xml鏂?#28000;?#28051;?#37816;?#28729;氶渶瑕乨ump灞炴负true?#32029;鍘嬫祴鏁版嵁?#22138;澶椂杩?#28051;?#28028;氬?#21342;?#23942;兘
  4. match.log浠?#28000;?#38333;堝HTTP璇锋眰?#32029;榛?#29825;?#28051;?#28028;?#37712;?#37711;紝闄?#38344;炲湪HTTP鍘嬫?#23339;寚瀹?/p>

        <http url="/" method="GET" version="1.1"/> 
        <match do=鈥檒og鈥?when=鈥檓atch鈥?name=鈥檋ttp_match_200ok鈥?gt;200OK</match> 
    
  5. 浠庤?#20636;偣tsung client鎵璁板綍鏃織銆侀渶瑕乨ump鐨?#29831;锋眰-鍝嶅簲鏁版嵁?#32029;閮?#28028;?#27996;?#37922;眛sung_controller澶勭悊

  6. ts_mon_cache?#32029;鎺?#37824;?#37714;?#37825;版嵁缁?#29825;?#37712;?#28699;?#29825;?#32480;楋紝姣?00姣?#32457;?#37723;?#37832;?#37714;嗗?#25120;粰鍚?#32513;?#22959;潡?#32029;璧?#37714;扮紦鍐蹭綔鐢?/p>

  7. ts_stats_mon妯潡鎺?#37824;?#37825;版嵁杩?#29723;屽唴瀛?#29825;?#32480;楋紝缁?#37835;?#37712;?#37711;?#37922;眛s_mon瑙?#37721;?/p>

  8. ts_mon璐?#29840;?#32513;?#29825;?#37825;版嵁鏈姣?0绉?#28729;氭椂鍐?#37711;?#37722;?#26916;?#32513;?#29825;?#37825;版嵁鍒皌sung.log鏂?#28000;讹紝闈?#28729;炴椂?#32029;鍙伩鍏嶇鐩IO寮閿杩囧闂?#26864;?/p>

    • tsung/src/tsung_controller/tsung_controller.app.in 瀵瑰簲 {dumpstats_interval, 10000}
    • 鍙?#28000;?#37734;?#26473;?#29723;屾椂淇?#37824;?/li>
  9. tsung.log鏂?#28000;?#23033;?#38342;?#27996;?#28729;埛绔?#26473;?#37818;?#37510;?#29831;锋眰銆?#28729;?#37825;?#28028;?#29831;?#37510;?#26916;甸潰浠?#37721;?#23011;忎竴椤?#37928;剆um鎿嶄綔缁?#29825;?#37928;勫畬鏁?#29825;板綍?#32029;鍚?#32513;perl鑴?#37832;?#37814;?#29723;?#37714;?#37835;愬熀浜庢

  10. ts_mon妯潡澶勭悊tsung.log鐨?#37832;鏍稿績妯潡?#32029;鍏?#28766;?#25966;?#31476;杩?#32459;嬶紝鏍?#29831;嗕负{global, ts_mon}

姣斿?#20635;?#24877;鍗?#37832;?0涓?#37922;埛鍘嬫祴tsung.log鏃?#36423;楃墖娈?#38171;?/p>

# stats: dump at 1467620663
stats: users 7215 7215
stats: {freemem,"os_mon@yhg162"} 1 11212.35546875 0.0 11406.32421875 11212.35546875 11346.37109375 2
stats: {load,"tsung_controller@10.10.10.10"} 1 0.0 0.0 0.01171875 0.0 0.01171875 2                                                                                 17,1          Top
stats: {load,"os_mon@yhg162"} 1 2.3203125 0.0 3.96875 0.9609375 2.7558736313868613 411
stats: {recvpackets,"os_mon@yhg162"} 1 5874.0 0.0 604484 5874 319260.6024390246 410
stats: {sentpackets,"os_mon@yhg162"} 1 8134.0 0.0 593421 8134 293347.0707317074 410
stats: {cpu,"os_mon@yhg162"} 1 7.806645016237821 0.0 76.07377357701476 7.806645016237821 48.0447587419309 411
stats: {recvpackets,"tsung_controller@10.10.10.10"} 1 4164.0 0.0 45938 4164 24914.798543689314 412
stats: {sentpackets,"tsung_controller@10.10.10.10"} 1 4182.0 0.0 39888 4182 22939.191747572815 412
stats: {cpu,"tsung_controller@10.10.10.10"} 1 0.575191730576859 0.0 6.217097016796189 0.575191730576859 2.436491628709831 413
stats: session 137 2435928.551725737 197.4558174045777 2456320.3908691406 2435462.9838867188 2436053.875557659 499863
stats: users_count 0 500000
stats: finish_users_count 137 500000
stats: connect 0 0 0 1004.4912109375 0.278076171875 1.480528250488281 500000
stats: page 139 12.500138756182556 1.1243565417115737 2684.760009765625 0.43115234375 16.094989098940804 30499861
stats: request 139 12.500138756182556 1.1243565417115737 2684.760009765625 0.43115234375 16.094989098940804 30499861
stats: size_rcv 3336 3386044720
stats: size_sent 26132 6544251843
stats: connected -139 0
stats: error_connect_timeout 0 11

tsung.log鏃織鏂?#28000;?#37721;?#37922;?code>tsung_stats.pl鑴?#37832;彁鍙?#37510;?#37714;?#37835;?#37510;?#37825;寸悊鎴?#37814;?#29723;?#28766;曠?#29492;紝鍏?#37814;?#29723;?#37928;勪竴涓憳瑕佹埅鍥?#38171;?/p>

锟?/p>

寮傚父琛屼负鐨勬敹闆?/h4>

?#32139;妯?#37815;熺粓绔?#38316;?#37714;?#32515;戠粶杩?#37818;?#29906;呮椂銆?#37734;板潃涓嶅彲杈?#32475;?#23534;傚父浜?#28000;舵椂?#32029;鏈?#31891;涔?#28028;?#37721;戠粰涓昏?#20636;偣鐨則s_mon妯潡?#32029;?#32346;瀛?#37714;皌sung.log鏂?#28000;?#28051;?#37510;?/p>

杩?#32457;?#23534;傚父璁板綍?#32029;鍏?#38335;?#29831;?#37715;嶇紑?#36127; **error_**锛?/p>

  • 姣斿?#20480;s_client妯潡閬?#37714;?#26473;?#37818;?#29906;呮椂浼?#23033;?#37814;?code>error_connect_timeout?#25930;璇?/li>
  • 绯?#32513;?#37928;勫彲鐢?#32468;?#37721;?#28051;嶅鐢椂锛堝?#28056;缓涓?#37720;嬫祴鏈?#37716;?#37731;?#26473;?#37818;?#37825;?#29906;?#37713;?#37721;?#37922;?#23048;?#38340;?#37714;?#38171;?#28051;?#37814;?code>error_connect_eaddrinuse?#25930;璇?/li>

Errors鎶?#29723;?#28610;?#23011;?#28729;埛绔?#37713;虹幇闂?#26864;樻?#25774;琛紝鍐?#37716;?#28051;tsung杈?#37713;log鏃織鏂?#28000;讹紝寰堟?#21614;鐨勫?#22562;?#26495;?#23339;祴杩?#32459;?#28051;?#37713;虹幇鐨?#38338;?#26864;?#23033;?#38342;嗭紝鏂?#28186;?#38338;?#26864;樺揩閫?#28729;?#28003;?#37510;?/p>

锟?/p>

琚?#37720;嬫祴鏈?#37716;?#37731;?#37928;勭?#25118;帶

?#32139;鍓峵sung鎻愪緵浜?绉?#37826;?#23534;?#26473;?#29723;?#37929;戞帶?#27952;鏍?#37832;?#37716;?#37731;?#29863;勬簮鍗?#37922;?#37807;?#37712;?#38171;?/p>

  • erlang
  • snmp
  • Munin

澶?#38007;?#27996;?#27996;?#37716;熻兘?#32029;绮?#37923;?#28003;?#37922;竴寮?#37733;捐绀?#38171;?/p>

tsung_server_monito锟?/p>

  • tsung_controller涓昏?#20636;偣浼氳寮?#37714;?#37722;?#37922;?#37929;戞帶
  • SNMP鏂?#23534;忥紝瀹埛绔綔?#36127;浠悊涓?#37716;?#23049;?#37712;屽苟杩?#37818;?#23534;鏀維NMP鐨?#37832;?#37716;?#37731;紝SNMP瀹夎閽堝?#35268;柊?#22684;?#28533;璇?#23011;旇緝澶嶆潅
  • Munin閲?#37922;C/S妯?#23534;忥紝鑷韩瑕佷綔?#36127;瀹埛绔?#26473;?#37818;?#29722;?#37720;嬫祴鏈?#37716;?#37731;?#28051;?#38003;藉瀹夎Munin Server
  • erlang鏂?#23534;忥紝鏈韩浠?#37918;嗗舰寮?#37929;戞帶鏈?#37716;?#37731;?#29863;勬簮鍗?#37922;紝婊?#29906;虫潯浠?#23536;?#32480;鍗?#38171;?
    • ?#28214;瑕佽?#34249;鑷?#37716;?#37927;诲綍杩?#37818;?/li>
    • ?#33503;涓?#28729;夎鏈塃rlang杩?#29723;屾椂?#24134;澧冿紝tsung_controller鏂?#28186;?#37722;?#37716;?#37929;戞帶鑺傜偣
    • 閲?#37922;?#26473;?#32459;嬪姞杞?#37826;?#23534;?#28051;?#37716;?#28000;?#37934;侊紝鐪佸?#26127;鐩戞帶绔?#38318;?#32515;?#37928;勯?#33636;儲
    • 鐜?#28729;炴儏鍐?#28051;嬶紝鎴戜竴鑸?#38322;?#37922;竴涓?#38004;?#37832;?#37820;?#28729;?#38007;?#37716;?#38318;?#32515;?#37929;戞帶閮?#32515;?#28729;埛绔紝鑷?#37716;?#37813;?#37718;?#37721;?#32457;绘鐨凟rlang?#32029;绠鍗?#32513;?#38009;诧紝閮?#32515;?#37826;?#28186;?/li>
  • 鎻愪緵鐩戞帶閲?#37837;?#37825;版嵁鍖?#37815;?CPU/Memory/Load/Socket Sent&Recv
  • 鎵鏈?#37929;戞帶鏁版嵁閮?#28028;氳鍙?#38315;佺粰ts_mon妯潡?#32029;?#33503;瀹氭椂鍐?#37711;?#37714;皌sung.log鏂?#28000;?#28051;?/li>

鐪嬩竴涓?#37832;?#31891;鎶?#29723;?#38318;?#37714;嗗?#22562;?#26495;惂锛?/p>

锟?/p>

tsung瀵规湇鍔?#37731;?#37929;戞帶閲?#37837;锋墜鏈?#37825;版嵁涓?#37828;?#23536;?#28051;板瘜?#32029;?#27932;?#36127;瀹冮潰鍚?#37928;勬洿?#36127;閫?#37922;?#37928;勭?#25118;帶?#28214;?#30512;銆?/p>

?#27967;娣?#28766;傛銆佹洿缁?#32494;?#25652;?#29863;勬簮鐩戞帶?#32029;灏遍渶瑕?#38007;?#29723;岄噰闆?#37510;?#38007;?#29723;屽垎鏋愪?#21997;紝?#31476;鑸?#37734;?#37727;?#28051;?#27996;搧鍦?#26473;?#37826;归潰浼?#37832;夋洿鏄庣?#28214;?#30512;銆?/p>

鏃織鏀?#38342;?/h3>

鍜?#37715;嶉潰璁?#37714;?#37928;勭粓绔?#29723;屼负鏁版嵁閲?#38342;嗗拰鏈?#37716;?#37731;?#32468;?#29863;勬簮鐩戞帶琛屼负绫?#28028;硷紝tsung杩?#29723;?#26473;?#32459;?#28051;?#37813;浜?#37922;熸棩?#32340;琚?#28699;樺偍鍒?#28051;昏?#20636;偣銆?/p>

tsung浣?#37922;error_logger璁板綍鏃織?#32029;涓昏?#20636;偣tsung_controller鍚?#37716;?#28052;嬪悗?#32029;浼氬苟鍙?#37722;?#37716;tsung client浠庤?#20636;偣?#32029;鎹?#37721;?#29831;濇潵璇磘sung client浠庤?#20636;偣鏄?#37922;?#28051;昏?#20636;偣tsung_controller鍒涘缓?#32029;杩?#28051;?#37911;规?#37712;?#28729;?#27996;tsung client浠庤?#20636;偣浣?#37922;error_logger璁板綍鐨勬棩?#32340;閮?#28028;氳?#22136;瀹?#37722;?#37714;?#28051;昏?#20636;偣tsung_controller鎵鍦?#37832;?#37716;?#37731;?#28051;婏紝杩?#28051;?#37828;?#37922;Erlang鑷韩?#23277;鐗规満鍒?#37712;?#28729;?#37510;?/p>

?#27932;姝紝浣犲湪涓昏?#20636;偣log?#27952;?#32141;涓嬭?#34249;?#29114;?#23338;?#26495;叿浣?#37928;勬棩?#32340;杈?#37713;?#37826;?#28000;讹紝涔?#28751;辨?#26449;?#29256;笭鎴愪簡銆傚洜?#36127;Erlang澶?#37922;?#37714;嗗竷寮忓熀?#27932;?#32029;浠庤?#20636;偣error_logger鏃織杈?#37713;洪?#37828;庨噸瀹?#37722;?#37714;?#28051;昏?#20636;偣?#32029;涓嶈垂鍚圭伆涔嬪姏銆?#26473;?#37734;?#37711;?#28000;?#29831;?#29815;鐪嬫潵?#32029;纭?#28729;?#28729;屽叏涓嶅彲?#20824;杞?#37828;?#28729;?#37916;?#37928;?#37510;?/p>

?#29056;浜error_logger鍖呰鏃織璁板綍?#32029;?#28214;瑕佷竴涓?#23005;?#26976;?#38171;?/p>

  1. 璁?#32515;?#26440;?#37713;?#37714;?#37826;?#28000;剁郴缁?#28051;?error_logger:tty(false)
  2. 璁?#28729;氳緭鍑?#37928;?#37826;?#28000;剁洰?#32141; error_logger:logfile({open, LogFile})
  3. 鍖呰鏃織杈?#37713;烘帴鍙??DEBUG/?DEBUGF/?LOG/?LOGF/
  4. 鏈?#31891;?#30367;鐢?#37718;呰鐨error_logger鎺?#37721;?/li>
debug(From, Message, Args, Level) ->
    Debug_level = ?config(debug_level),
    if
        Level =< Debug_level ->
            error_logger:info_msg("~20s:(~p:~p) "++ Message,
                                  [From, Level, self()] ++ Args);
        true ->
            nodebug
    end.

鍜屽閮?#37714;嗘棩?#32340;妗?#37835;?#29825;?#28729;?#37928;勬棩?#32340;绛?#32510;竴鑷达紝emergency > critical > error > warning > notice (default) > info > debug?#32029;浠?#23480;?#37714;板?#31609;紝渚?#23046;?#38315;?#37713;?#37510;?/p>

?#28214;瑕佹敞鎰?#27996;嬮?#30328;紝error_logger璇?#28052;変负璁板綍?#25930;璇?#37827;織?#32029;鍙?#38315;?#37922;?#27996;?#37930;熸鐨勫?#20634;父鎯?#37712;碉紝?#33503;涓?#37832;?#37832;?#26473;囧鐨勬?#22559;伅?#22138;鐨勫?#21229;悊銆?

?#23266;?#32139;?#31476;鑸?#28051;?#37716;皟璇?#32491;诲?#23339;棩?#32340;?#22138;杩囧?#27693;椂?#32029;涓?#28003;?#38000;?#29840;?#27996;嗗?#22138;鍐?#28699;橈紝缃戠粶/纾?#37929;?#37712;?#37711;?#38315;熷害璺?#28051;?#28051;?#37922;?#27996;?#38315;熷害?#26882;?#32029;浼?#28725;?#38007;?#26473;?#32459;嬪?#38747;?#28871;紝涓噸浼氭?#26667;疮鏁?#28051;?#25652;?#37922;?#37709;垫?#20249;紝?#27932;姝渶瑕?#37734;tsung.xml鏂?#28000;?#28051;?#29825;?#32515;?#38007;?#28751;慽nfo绾?#37714;紝鑷?#28751;戦粯璁?#37928;刵otice灏?#23536;?#37722;?#38315;?#37510;?/p>

Tsung杩?#29723;屾椂璇?#37826;?鐩戞帶

Tsung鍦?#26473;?#29723;屾椂?#32029;鎴戜滑鍙?#28000;remote shell鏂?#23534;?#26473;?#37818;?#37927;诲綍杩?#37720;?#37510;?/p>

?#36127;浜?#26473;?#37818;?#37826;?#28186;匡紝鎴?#37712;?#27996;嗕竴涓?#38004;?#37832;?connect_tsung.sh?#32029;鍙渶瑕佷紶鍏tsung鑺傜偣鍚?#32457;板嵆鍙?#38171;?/p>

# !/bin/bash
## 璁?#38338;?#26473;?#32459;婽sung鑺傜偣 sh connect\_tsung.sh tsung\_controller@10.10.10.10

HOST=`ifconfig | grep "inet " | grep -v "127.0.0.1" | head -1 | awk '{print $2}' | cut -d / -f 1`
if [ -z $HOST ]; then
    HOST = "127.0.0.1"
fi
erl -name tmp\_$RANDOM@$HOST -setcookie tsung -remsh $1

?#28214;瑕?#28729;夎鏈塃rlang杩?#29723;屾椂?#24134;澧?#37824;寔

?#32139;?#21159;?#32029;瑕?#37722;?#26473;?#29723;岃剼鏈紝浣?#23536;楃煡閬揟sung鎵鏈夎?#20636;偣鍚?#32457;?#37510;?/p>

濡備綍?#24143;寰tsung鑺傜偣鍚?#32457;?/h4>

鍏?#28729;?#37832;?#28051;?#32457;?#37826;?#23534;忚幏寰桾sung鑺傜偣鍚?#32457;?#38171;?/p>

濡備綍璇?#37826;?鐩戞帶Tsung杩?#29723;屾椂

鍏?#28729;烇紝杩?#38322;?#28000;?#28000;?#38333;堝浣?#37922;Erlang?#33503;涓?#28725;筎sung鎰?#37711;?#29906;?#37928;勫悓瀛紝浣?#38318;?#38003;藉杩涙潵浜嗭紝閭?#28052;堝?#20633;綍杩?#29723;屾煡鐪?#37510;佽皟璇?#26473;?#29723;屾椂tsung绯?#32513;?#26473;?#29723;屾儏鍐碉紝閭?#28052;堝氨寰?#32480;鍗?#27996;?#37510;傛帹鑽愪娇鐢?recon 搴擄紝鍖?#37815;?#37712;?#28699;?#37719;?#37922;紝鍑?#37825;?#26473;?#29723;屽爢鏍堬紝CPU璧勬簮鍒嗛厤绛夛紝?#31476;?#27952;浜嗙劧銆?/p>

?#23266;闂紝tsung鍚?#37716;椂濡備綍娣?#37716;爎econ渚?#29863;栵紝涔?#28051;嶅?#23942;潅锛?/p>

  1. 姣忎竴涓?#26473;?#29723;宼sung鐨?#37832;?#37716;?#37731;?#37815;?#29840;?#23480;?#32513;忕紪璇?#28729;?#37812;?#37928;剅econ椤圭洰鍒版寚瀹氱洰?#32141;
  2. tsung_controller涓昏?#20636;偣鍚?#37716;椂?#32029;鎸?#28729;歳econ渚?#29863;?#25652;?#28003;?#32515;?/p>

    tsung -X /Your_Save_Path/recon/ebin/ ...

璇翠竴涓?#37922;?#28186;嬶紝淇?#37824;?#37929;戞帶鏁版嵁姣?0绉?#37712;?#37711;tsung.log鏂?#28000;舵椂闂?#38338;撮?#26047;硷紝10绉?#28103;?#37824;逛负5绉?#38171;?/p>

application:set_env(tsung_controller, dumpstats_interval, 5000).

鎵?#29723;?#28052;嬪悗?#32029;浼?#32468;嬪埢鐢?#37825;?#37510;?/p>

灏?#32513;?/h3>

鎬?#32513;?#27996;員sung涓?#28000;?#37929;戞帶?#32029;浠?#37721;?#37832;?#37716;?#37731;?#32468;?#37929;戞帶閮?#37714;嗭紝浠?#37721;?#26473;?#29723;屾椂鐩戞帶绛?#37510;傛?#24874;緵鐨勮鍘嬫祴鏈?#37716;?#37731;?#37929;戞帶鍔熻兘寰堢?#26955;紝浠?#37824;?#38342;咰PU銆?#37712;?#28699;?#37510;佽礋杞?#37510;佹帴鏀?#37825;版嵁绛?#32491;诲?#23338;?#26495;硷紝鍏?#37832;変竴鑸?#37721;傝?#37808;?#28052;?#37510;?#28003;嗗熀浜嶵sung鏋勫缓鐨?#37510;佹垨绫?#28028;煎晢涓?#27996;?#37725;侊紝?#31476;鑸?#28028;?#37832;夋?#24874;緵涓?#38338;?#37825;版嵁鏀?#38342;?#37832;?#37716;?#37731;紝浣?#28725;?#27996;?#23534;?#31790;鐨勫簲鐢?#38000;岃?#32029;?#28214;瑕?#37711;?#26916;?#38315;?#37922;渶?#30512;?#32029;涔?#37828;?#38003;藉?#29114;悊瑙?#37928;?#37510;?/p>

nieyong 2016-07-29 08:49 鍙?#29723;?#29831;?#29825;?/a>
]]>Tsung绗?#29825;?#28052;婭P鐩?#26473;炴敮鎸佺瘒http://www.8634070.com/yongboy/archive/2016/07/28/431354.htmlnieyongnieyongThu, 28 Jul 2016 00:37:00 GMThttp://www.8634070.com/yongboy/archive/2016/07/28/431354.htmlhttp://www.8634070.com/yongboy/comments/431354.htmlhttp://www.8634070.com/yongboy/archive/2016/07/28/431354.html#Feedback0http://www.8634070.com/yongboy/comments/commentRss/431354.htmlhttp://www.8634070.com/yongboy/services/trackbacks/431354.html鍓嶈

鍓嶉潰璇村埌璁?#29825;竴涓?#28751;忓瀷鐨凜/S绫诲瀷杩?#32459;嬬粓绔?#28610;?#28000;?#28000;?#37831;?#37817;SSH?#32029;?#33503;涓?#23480;?#32513;?#25652;?#37922;?#37714;扮嚎涓?#37510;?#26473;?#28051;?#38338;?#26864;橈紝鍏?#28729;?#28051;?#37828;疶sung鑷韩鐨?#38338;?#26864;橈紝鏄?#28598;?#38318;?#26473;?#37818;?#28186;?#29863;?#38338;?#26864;?#37510;?/p>

Tsung鍦?#37722;?#37716;?#37714;嗗竷寮忓?#23339;?#23339;椂?#32029;涓昏?#20636;偣tsung_controller瑕?#26473;?#37818;?#37928;?#28000;?#37832;哄繀椤?#29781;佸鍐?#28051;?#37832;?#37722;嶏紝涓?#37832;?#37722;嶆病鏈?#37712;?#32515;DNS鏈?#37716;?#37731;?#37824;?#37816;佽鏋?#37928;勬儏鍐?#28051;?鎴戞墍缁忓巻浜?#38001;?#32515;?#37711;?#37721;?#23536;堝皯鏈夋?#24874;緵鏀寔鐨??#32029;鍙?#28610;借垂鍔?#37734;?code>/etc/hosts鏂?#28000;?#28051;?#28617;?#37712;?#28051;?#37832;?#37722;?#32457;板拰IP鍦板潃鐨?#37828;?#28751;勫叧绯伙紝棰囦负楹荤儲?#32029;灏?#37711;?#37828;?#29781;佹坊鍔犱竴鎵规柊鐨勫?#23339;祴浠?#37832;?#37812;?#28000;?#37832;?#37721;?#37716;?#26864;戠?#22250;緝澶椂銆?/p>

閭?#28052;堝?#20633;綍瑙?#37712;?#26473;?#27996;?#38338;?#26864;?#37723;紝璁tsung鍦?#28598;嶆潅鐨?#37832;?#37812;?#37712;?#32515;戠幆澧?#28051;嬶紝瀹屽叏?#29056;浜嶪P杩?#29723;?#37929;?#26473;烇紝杩?#28751;?#37828;?#37832;?#37826;?#37813;璁?#29825;?#37928;勫唴瀹?#37510;?/p>

棰勫?#22249;煡璇?/h3>

瀹屽叏闄?#28729;?#37737;?#37722;?/h4>

瀹屽叏闄?#28729;?#37737;?#37722;嶏紝缂?#37712;欎负FQDN (fully qualified domain name)?#32029;璧?#38338;搧鍏?#32513;?#37713;?#37928;?#28051;?#37826;?#28729;?#28052;?/a>锛?/p>

?#31476;绉?#37922;?#27996;庢寚瀹?#29825;?#32480;?#37832;?#37734;?#37737;熷?#20635;缁?#37835;?#28051;?#32429;?#37714;?#28003;?#32515;?#37928;?#37828;庣鍩?#37722;?#37510;?br/> ?#31476;鍙扮壒瀹?#29825;?#32480;?#37832;?#37812;?#28051;?#37832;?#37928;勫畬鏁?Internet 鍩?#37722;?#37510;侳QDN 鍖?#37815;?#28051;?#38318;?#37714;?#38171;?#28051;?#37832;?#37722;嶅?#23677;煙鍚?#37510;?#28186;嬪 mycomputer.mydomain.com銆?br/> ?#31476;绉嶅寘鍚?#28051;?#37832;?#37722;嶅?#23677;煙鍚?#38171;堝寘鎷?#26916;剁骇鍩?#38171;?#37928;?URL銆?#28186;嬪?#20646;紝www.symantec.com 鏄?#28729;屽叏闄?#28729;?#37737;?#37722;?#37510;?#37711;?#28051;?www 鏄?#28051;?#37832;猴紝symantec 鏄?#27996;岀骇鍩燂紝.com 鏄?#26916;剁骇鍩?#37510;侳QDN 鎬?#37828;?#28000;?#28051;?#37832;?#37722;?#23534;濮?#28051;?#28000;?#26916;剁骇鍩?#37722;?#32513;?#37833;燂紝?#27932;姝?www.sesa.symantec.com 涔?#37828;竴涓?FQDN銆?/p>

?#23266;鏈哄櫒涓?#37832;?#37722;嶄负鍐?#32515;戝煙鍚嶅舰寮忥紝?#33503;涓?#37824;寔DNS瑙?#37835;愶紝鏂?#28186;?#37711;?#28729;?#37832;?#37716;?#37731;?#37721;?#38315;?#26473;?#29831;?#28051;?#37832;?#37722;?#37929;?#37818;?#37813;?#37714;板?#29808;簲IP鍦板潃?#32029;鑳藉 ping -c 3 鏈哄櫒鍩?#37722;?/code> 閫氾紝閭?#28052;?#37832;哄櫒涔?#38338;?#38003;藉瀹规槗鎵?#37714;板?#35268;柟銆?/p>

鏈?#37716;?#37731;hostname鐨勫懡鍚嶏紝?#23266;涓?#37828;?#37737;?#37722;嶅舰寮忥紝绠鐭?#37722;?#32457;板舰寮忥紝姣斿鈥測k_mobile_dianxin_001鈥濓紝?#31476;鑸?#37712;?#32515;?#37928;DNS鏈?#37716;?#37731;?#28051;嶆敮鎸佽鏋愶紝鏈哄櫒涔?#38338;撮渶瑕佷簰鐩?#37734;?etc/hosts鏂?#28000;跺?#34425;?#23338;郊姝IP鍦板潃鏄?#28751;勫叧绯?#37813;嶈?#34249;浜?#37929;?#37808;熺煡瀵规柟銆?/p>

Erlang鑺傜偣鍚?#32457;?#37928;勮?#21227;垯

?#27932;?#36127;Tsung浣?#37922;Erlang缂?#37712;欙紝Erlang鍏?#27996;庤?#20636;偣鍚?#37716;?#37722;?#32457;拌?#21227;?#27710;紝涔?#37828;疶sung?#28214;瑕侀潰瀵?#37928;?#38338;?#26864;?#37510;?/p>

Erlang鑺傜偣鍚?#32457;颁竴鑸渶瑕侀伒寰?#28051;?#32457;?#37837;?#23534;?#38171;?/p>

  1. ?#31476;鑸?#37722;?#32457;?#38171;?#28052;熺涔嬩负鐭?#37722;?#32457;?#38171;夊舰寮忥紝涓嶅寘鍚?#37413;?鈥?#28699;?#32471;紝姣斿 erl -name tsun_node
  2. 瀹屽叏闄?#28729;?#37737;?#37722;嶅舰寮?
    • 鍩?#37722;嶅舰寮忥紝姣斿erl -name tsun_node.youdomain.com
    • IP?#33328;寮忥紝姣斿erl -name 10.10.10.103

Tsung澶勭悊鏂?#23534;?#38171;?/p>

  • ?#23266;闈炵壒鍒?#37816;?#28729;氾紝?#31476;鑸?#27035;?#29825;负鐭?#37722;?#32457;板舰寮?/li>
  • 鍚?#37716;椂鍙?#28000;?#38315;?#26473;?code>-F鍙傛?#29256;寚瀹?#28003;?#37922;?#28729;屽叏闄?#28729;?#37737;?#37722;嶅舰寮?/li>

?#24143;寰IP鍦板潃

涓?#37832;?#37722;?#32457;版棤璁?#37828;?#28729;屽叏闄?#28729;?#37737;?#37722;嶅舰寮忥紝杩?#37828;?#32480;鍗?#37928;勭煭鍚?#32457;板舰寮忥紝?#32139;鍒?#37928;?#28051;?#37832;洪渶瑕?#38315;?#26473;?#28051;?#37832;?#37722;?#29825;?#38338;椂?#32029;绯?#32513;熷眰?#28528;?#28214;瑕?#38315;?#26473;DNS绯?#32513;?#29785;?#37835;?#37812;怚P鍦板潃鎵嶈?#34249;杩?#29723;?#32515;戠粶杩?#37818;?#37510;傚綋鍐?#32515;DNS鑳藉瑙?#37835;?#37713;烘潵IP?#28533;?#32029;?#30149;鏈?#28000;涔堟?#21613;績鐨?#38171;?#38171;堢煭鍚?#32457;?#38171;?#29785;?#37835;?#28051;嶅?#28888;潵?#26882;?#32029;澶?#37719;?#28028;?#38315;?#26473;囧啓鍏?#37714;?#32495;?#32513;?#37928;?/etc/hosts 鏂?#28000;?#28051;紝杩?#37837;?#28052;?#38003;藉瑙?#37835;?#37812;?#37716;?#37510;?/p>

?#31476;鑸?#37832;?#37812;?#37712;?#32515;戠幆澧冿紝涓?#37832;?#37722;?#32457;板閮?#37828;?#37933;?#37722;?#32457;板舰寮忥紝?#23266;?#28214;鍒嗗竷寮忥紝姣忎竴涓?#28051;?#37832;?#28052;?#38338;?#38318;?#29781;佽?#34249;浜?#37929;?#38001;?#38315;氾紝鏈缁?#23092;庡仛?#30838;灏?#37828;?#37929;?#37818;?#28003;?#37922;IP鍦板潃?#32029;鍙伩鍏嶅啓鍏?#28598;噺鏄?#28751;勫埌 hosts 鏂?#28000;?#28051;紝涔?#28028;氶伩鍏嶄竴浜?#38341;愭偅銆?/p>

涓昏?#20636;偣鍚?#37716;?#28583;?#37716;營P鏀寔

榛?#29825;?#37807;?#37712;?#28051;嬶紝Tsung Master涓昏?#20636;偣鍚?#32457;扮被浼?#27996;?code>tsung_controller@涓?#37832;?#37722;?/code>锛?/p>

  • 鑺傜偣鍚?#32457;板墠?#32017;榛?#29825;负锛?code>tsung_controller 锛?#38340;?#38344;炲湪tsung鍚?#37716;椂閫?#26473;?code>-i鎸?#28729;?#37715;嶇紑锛?/li>
  • ?#31476;鑸?#28051;?#37832;?#37722;?#38318;?#37828;?#28699;?#32471;?#28051;插舰寮?#38171;?code>hostname鍛?#28000;?#37721;?#29825;?#32515;?#28051;?#37832;?#37722;?#38171;?/li>
  • 鍙?#28751;?#28051;?#37832;?#37722;?#32457;?#29825;?#32515;负鏈?#37832;篒P?#32029;浣?#28051;?#32471;?#37722;?#27996;虹被璁?#37933;儻鎬?/li>

鏃劧Tsung涓昏?#20636;偣榛?#29825;?#28725;笽P鑺傜偣鍚?#32457;版敮鎸佷?#23941;?#29122;紝鏀?#38315;犱竴涓?code>tsung/tsung.sh.in鑴?#37832;?#37510;?/p>

Tsung鍚?#37716;椂-F鍙傛暟?#36127;鎸?#28729;?#28003;?#37922;?strong>瀹屽叏闄?#28729;?#37737;?#37722;?FQDN)?#33328;寮忥紝涓嶆敮鎸佹?#21700;甫鍙傛暟銆傝嫢瑕?#37929;?#37818;?#28028;?#38315;扞P鍦板潃?#32029;绫?#28028;?#27996;?#38171;?/p>

-F Your_IP

淇?#37824;?code>tsung.sh.in?#32029;鍙?#28000;?#28028;?#38315;扞P鍦板潃?#32029;?#22684;鍔?#32513;勮鑺傜偣鍚?#32457;?#38171;?/p>

F) NAMETYPE="-name"
    SERVER_IP=$OPTARG
    if [ "$SERVER_IP" != "" ]; then
        CONTROLLER_EXTENDS="@$SERVER_IP"
    fi
    ;;

淇?#37824;?#28051;嶅?#23942;潅?#32029;鏇村缁嗚妭璇?#37721;傝?#38171;?a href="https://github.com/weibomobile/tsung/blob/master/tsung.sh.in">https://github.com/weibomobile/tsung/blob/master/tsung.sh.in

鍚?#37716;Tsung?#26882;?#32029;鎸?#28729;?#37832;?#37734;IP锛?/p>

tsung -F 10.10.10.10 -f tsung.xml start

tsung_controller?#27952;鍓嶈?#20636;偣鍚?#32457;板凡缁忓彉?#36127;锛?/p>

-name tsung_controller@10.10.10.10

鍡紝?#27952;鏍囪揪鎴?#37510;?/p>

浠庤?#20636;偣涓?#37832;?#28583;?#37716;營P?#21412;缃?/h3>

缁?#37713;轰竴涓?#38010;傜偣client50?#21412;缃?#38171;?/p>

<client host="client50"  maxusers="100000" cpu="7" weight="4">
    <ip value="10.10.10.50"></ip>
    <ip value="10.10.10.51"></ip>
</client>

Tsung Master?#20802;璁?#38338;甤lient50?#32029;?#28214;瑕佹彁鍓嶅?#34425;珛client50涓嶪P鍦板潃鐨?#37828;?#28751;勫叧绯?#38171;?/p>

echo "10.10.10.50 client50" >> /etc/hosts

host灞炴?#27035;?#29825;?#37807;?#37712;?#28051;嬪彧鑳藉鍐欓?#36328;煭鍚?#32457;帮紝鏃犳硶濉?#37712;橧P鍦板潃?#32029;?#36127;浜嗗吋瀹?#23480;?#37832;?#29785;勫?#27417;紝淇?#37824;?code>tsung-1.0.dtd鏂?#28000;朵负client鍏冪礌鏂板?#28848;竴涓?code>hostip灞炴?#38171;?/p>

<!ATTLIST client
     cpu      NMTOKEN "1"
     type     (machine | batch)  "machine"
     host     NMTOKEN #IMPLIED
     hostip   CDATA ""
     batch    (torque | pbs | lsf | oar) #IMPLIED
     scan_intf NMTOKEN #IMPLIED
     maxusers NMTOKEN "800"
     use_controller_vm (true | false) "false"
     weight   NMTOKEN "1">

淇?#37824;?code>src/tsung_controller/ts_config.erl鏂?#28000;讹紝澧?#37716;犲?#21229;悊閫昏緫?#32029;鍙?#37832;夊綋涓昏?#20636;偣涓?#37832;?#37722;嶄负IP?#26882;鎵?#28028;?#37721;?code>hostip?#32148;?#36127;涓?#37832;?#37722;?#38171;?/p>

{ok, MasterHostname} = ts_utils:node_to_hostname(node()),
case {ts_utils:is_ip(MasterHostname), ts_utils:is_ip(Host), ts_utils:is_ip(HostIP)} of
   %% must be hostname and not ip:
    {false, true, _} ->
        io:format(standard_error,"ERROR: client config: 'host' attribute must be a hostname, "++ "not an IP ! (was ~p)~n",[Host]),
        exit({error, badhostname});
    {true, true, _} ->
        %% add a new client for each CPU
        lists:duplicate(CPU,#client{host     = Host,
                                    weight   = Weight/CPU,
                                    maxusers = MaxUsers});
    {true, _, true} ->
        %% add a new client for each CPU
        lists:duplicate(CPU,#client{host     = HostIP,
                                    weight   = Weight/CPU,
                                    maxusers = MaxUsers});
    {_, _, _} ->
        %% add a new client for each CPU
        lists:duplicate(CPU,#client{host     = Host,
                                    weight   = Weight/CPU,
                                    maxusers = MaxUsers})
end

鍡紝鐜板湪鍙?#28000;?#26473;?#37837;烽厤缃?#28000;庤?#20636;偣浜嗭紝涓?#37922;?#37815;呭績Tsung鍚?#37716;椂鏄?#37722;?#38340;勫姞-F鍙傛暟浜?#38171;?/p>

<client host="client50" hostip="10.10.10.50" maxusers="100000" cpu="7" weight="4">
    <ip value="10.10.10.50"></ip>
    <ip value="10.10.10.51"></ip>
</client>

鍏?#28729;烇紝鍙?#29781;佷?#29365;瀹?#37721;?#28003;?#37922;?#28051;昏?#20636;偣涓?#37832;?#37722;嶄负IP鍦板潃?#32029;鍙?#28000;?#37929;?#37818;?#29825;?#32515;甴ost灞炴?#37706;间负IP鍊硷紝鍙?#36423;界暐hostip灞炴紝浣?#26473;?#28000;?#37911;虹鍏?#28729;规负浠?#28000;?#37928;?#37510;?/p>

<client host="10.10.10.50" maxusers="100000" cpu="7" weight="4">
    <ip value="10.10.10.50"></ip>
    <ip value="10.10.10.51"></ip>
</client>

?#36127;浜嗗噺灏?code>/etc/hosts澶噺鏄?#28751;勫啓鍏紝杩?#37828;?#37818;?#38013;?#37711;?#38318;IP?#33328;寮忥紝杩?#32457;嶅舰寮?#38315;?#37722;圱sung鍒嗗竷寮忛?#21977;兢鎵渚?#29863;?#37832;?#37716;?#37731;?#37928;勫揩閫熺璧佹鍨?#37510;?/p>

?#31790;鐮?#37734;板潃

閽堝?#31566;sung鏈?#26570;浠?#37934;?#28583;?#37716;?#37928;処P鐩?#26473;炵?#35268;?#37813;鏈変慨鏀癸紝宸?#32513;?#37824;?#37734;github涓?#38171;?/p>

https://github.com/weibomobile/tsung 銆?/p>

?#33503;涓?#23480;?#32513;?#38315;?#27996;?code>pull request锛?https://github.com/processone/tsung/pull/189 銆?/p>

姣旇緝鏈?#37808;?#37804;?#37928;?#37828;紝鏈?#26473;?#37837;蜂竴鏉?#29831;?#29825;?#38171;?/p>

锟?/p>

閽堝?#31566;sung 1.6.0淇?#37824;?#37911;?/h4>

鏈杩戜竴娆?#37721;?#29723;岀増鏄痶sung 1.6.0?#32029;杩?#28051;?#37911;?#37832;?#23011;旇緝绋?#28729;氾紝鎴?#28729;?#38340;?#37720;嬫?#23339;墍浣?#37922;?#37928;勫氨鏄?#37734;?#23005;?#37911;?#37832;?#28051;婂鍔營P鐩?#26473;炴敮?#23508;锛堝涓?#37813;杩?#38171;夛紝宸?#32513;忚鍗曠嫭鏀?#37711;?#37714;癵ithub涓?#38171;?/p>

https://github.com/weibomobile/tsung-1.6.0

鑷?#27996;庡?#20633;綍瀹夎?#21635;紝git clone鍒?#37832;?#37734;帮紝鍚庨潰灏?#37828;?#28641;備綍缂?#29831;tsung鐨勬楠?#27996;嗭紝涓嶅啀绱?#26473;?#37510;?/p>

灏?#32513;?/h3>

?#23266;瑕?#29825;IP鐩?#26473;炵?#35268;?#37922;?#37825;堬紝鍐嶆璇?#37828;?#37722;?#37922;?#23005;?#26976;竴涓?#38171;?/p>

  1. tsung.xml鏂?#28000;堕厤缃?#28000;?#37832;hostip灞炴紝鎴杊ost灞炴紝濉?#37712;?#23005;?#32429;IP
  2. tsung鍚?#37716;椂?#32029;鎸?#28729;?#37832;?#37832;?#37721;?#37922;IP鍦板潃锛?code>tsung -F Your_Available_IP -f tsung.xml ... start

IP鐩?#26473;烇紝鍐嶉厤鍚?#37715;嶉潰鎵鍐橲SH鏇?#37817;?#37826;规?#22572;紝鍙?#28000;?#29825;Tsung鍒嗗竷寮忛?#21977;兢鍦?#28598;嶆?#20636;?#25120;粶鏈?#37812;?#37712;?#32515;戠幆澧?#28051;?#38315;?#25652;?#37804;?#37722;?#37715;嶈繄浜嗕竴澶?#23005;?#37510;?/p>

2016-08-06 ?#27967;?#26570;姝?#37826;囷紝澧?#37716;燭sung 1.6.0淇?#37824;?#37911;堟弿杩?/p>



nieyong 2016-07-28 08:37 鍙?#29723;?#29831;?#29825;?/a>
]]>Tsung绗?#29825;?#28052;嬪垎甯?#23534;?#28583;?#23534;鸿烦鍑SSH缇佺?#23108;瘒http://www.8634070.com/yongboy/archive/2016/07/27/431340.htmlnieyongnieyongWed, 27 Jul 2016 01:28:00 GMThttp://www.8634070.com/yongboy/archive/2016/07/27/431340.htmlhttp://www.8634070.com/yongboy/comments/431340.htmlhttp://www.8634070.com/yongboy/archive/2016/07/27/431340.html#Feedback0http://www.8634070.com/yongboy/comments/commentRss/431340.htmlhttp://www.8634070.com/yongboy/services/trackbacks/431340.html鍓嶈

Erlang澶?#37922;熸敮?#23508;鍒嗗竷寮忕幆澧冿紝Tsung妗?#37835;?#37928;勫垎甯?#23534;忓?#23339;?#23338;鐩?#27996;庢?#32029;绠鍗曡交鏉?#37823;嶆帶瀛?#38010;傜偣鐢熸瀛?#27996;?#37510;佹淳鍙戜换鍔?#32475;?#28051;嶈垂鍚圭伆涔嬪姏銆?/p>

Tsung鍚?#37716;?#37714;嗗竷寮忓?#23339;?#23339;椂?#32029;涓昏?#20636;偣tsung_controller榛?#29825;?#37807;?#37712;?#28051;嬮渶瑕?#38315;?#26473;SSH閫?#38316;?#26473;?#37818;?#37714;?#26473;?#32459;?#37832;哄櫒涓?#37722;?#37716;?#28000;庤?#20636;偣?#32029;閭?#28052;?#38338;?#26864;?#28186;挎潵浜嗭紝?#31476;鑸?#27996;?#38001;?#32515;?#37711;?#37721;稿熀浜庤?#34411;澘/?#29262;鍨?#37832;?缃?#37711;虫?#22559;潈鏂?#23534;?#29825;?#38338;?#37832;?#37812;?#37832;?#37716;?#37731;紝閭?#28052;SSH鏈?#37714;?#28598;?#37825;堬紝?#33503;涓旇鏄?#28000;?#32450;佹銆係SH涓?#38315;氾紝Tsung涓?#37832;?#37722;?#37716;?#28051;?#27996;?#28000;?#37832;猴紝鍒嗗竷寮忔洿?#26852;浠庤皥璧?#37510;?/p>

閭?#28052;堝?#20633;綍瑙?#37712;?#26473;?#28051;?#38338;?#26864;?#37723;紝璁tsung鍦?#28598;嶆潅鐨?#37832;?#37812;跨?#25120;粶?#24134;澧?#29825;?#28729;?#28051;嬫?#26449;?#29362;?#20638;寰楁?#36798;紝灏?#37828;?#37832;?#37826;?#37813;璁?#29825;?#37928;勫唴瀹?#37510;?#37413;?/p>

RSH锛歊emote Shell

RSH?#32029;remote shell缂?#37712;欙紝?#28142;鍩虹櫨绉戜笂鑻?#37826;?#29785;?#38322;?#38171;?a href="https://en.wikipedia.org/wiki/Remote_Shell">https://en.wikipedia.org/wiki/Remote_Shell銆備綔?#36127;?#31476;涓粓绔?#23480;?#37711;凤紝Linux鐣岄?#29111;鏇?#32513;?#37712;?#26473;?RSH瀹埛绔?#37724;?#37832;?#37716;?#37731;?#32468;?#37820;缓鏁?#32459;?/a>銆?/p>

鍦CentOS涓?#28729;夎涔?#32480;鍗?#38171;?/p>

yum install rsh

Erlang鍊?#37716;?#27996;巖sh鍛?#28000;?#29723;?#23480;?#37711;?#38315;?#26473;SSH閫?#38316;?#26473;?#37818;?#37714;?#28000;庤?#20636;偣鍚?#37716;Tsung搴?#37922;紝涓嬮潰鍙?#28000;?#37930;嬪埌rsh宸?#37711;?#37832;韩澶?#37720;?#27996;嗗師鏈?#37928;勫惈涔夛紝绫?#28028;?#27996;?code>exec鍛?#28000;?#37716;?#37825;?#37510;?/p>

姣斿?#20402;rlang涓昏?#20636;偣锛堝亣璁捐繖涓?#37832;?#37716;?#37731;?#37722;?#32457;颁负node_master?#32029;?#33503;涓?#23480;?#32513;?#37734;?etc/hosts鏂?#28000;跺?#34425;珛浜咺P鍦板潃鏄?#28751;?#38171;?#37734;?#37722;?#37716;椂鎸?#28729;歳sh鐨勫彲閫?#37826;?#23534;忎负SSH锛?/p>

erl -rsh ssh -sname foo -setcookie mycookie

鍚?#37716;?#28052;嬪悗?#32029;瑕?#37722;?#37716;?#26473;?#32459;?#28051;?#37832;鸿?#20636;偣鍚?#32457;颁负node_slave鐨勫瓙鑺傜偣锛?/p>

slave:start(node_slave, bar, "-setcookie mycookie").

涓婇潰Erlang鍚?#37716;?#28000;庤?#20636;偣鍑?#37825;帮紝鏈?#31891;琚炕璇戜负鍙?#37813;?#29723;?#37928;剆hell鍛?#28000;?#38171;?/p>

ssh node_slave erl -detached -noinput -master foo@node_master -sname bar@node_slave -s slave slave_start foo@node_master slave_waiter_0 -setcookie mycookie

erl鍛?#28000;Erlang鐨勫惎鍔?#37723;?#28000;紝瑕佹眰涓?#37832;?code>node_slave鑷韩涔?#29781;?#28729;夎浜咵rlang鐨?#26473;?#29723;屾椂?#24134;澧?#37813;嶈銆?/p>

浠庤?#20636;偣鐨勫惎鍔?#37723;?#28000;?#37832;?#31891;渚?#29863;?#27996;嶴SH杩?#37818;苟杩?#32459;嬫墽琛岋紝鍏?#38315;?#37922;竴鑸?#37837;?#23534;忎负锛?/p>

ssh HOSTNAME/IP Command

杩?#28751;?#37828;熀浜嶦rlang鏋勫缓鐨凾sung鎿嶆帶浠庤?#20636;偣鍚?#37716;?#37928;?#37832;?#31891;瀹?#37916;?#37832;?#37714;?#37510;?/p>

鍏?#28729;?#29831;?#29815;涓紝Master鍚?#37716;Slave涔?#37828;?#28641;傛鏈?#37714;?/p>

SSH?#36127;閫?#37922;?#37826;规?#22572;紝浣?#28051;?#37828;?#37832;濂?#37928;?#37826;规

涓?#37923;?#38315;?#37922;?a href="https://zh.wikipedia.org/wiki/Secure_Shell">SSH鏈?#37714;?#26473;?#37818;?#26473;?#32459;Unix/Linux鏈?#37716;?#37731;?#28051;?#37832;猴紝鍒嗗竷寮忕幆澧?#28051;?#29781;佽?#34249;鑷?#37922;?#37711;嶉櫎瀵?#37934;佹柟寮?#37722;?#37716;?#26473;?#32459;?#28051;?#37832;?#28051;?#38171;?#26473;?#38322;屾寚鐨?#37828;?#37712;?#38318;Lan?#24134;澧?#38171;?#25652;?#37922;紝?#31476;鑸渶瑕?#29825;?#32515;?#37711;?#38333;紝?#28214;瑕佷紶閫?#37711;?#38333;紝?#28214;瑕佷繚瀛?#37714;板悇鑷?#37832;哄櫒涓婏紝杩?#37832;?#32513;忓父閬?#37714;?#37833;?#38340;?#38338;?#26864;橈紝寰?#37828;?#27001;荤儲?#32029;杩?#37828;?#37711;朵竴銆傝嫢瑕?#37721;?#23057;堟煇鍙?#37832;?#37716;?#37731;?#37927;?#38340;嗘?#22559;潈?#32029;鍒欓渶瑕佽鍔?#28103;?#37824;瑰叕閽紝涔?#37828;?#28051;嶅?#29114;?#22443;椿銆?/p>

鍙?#28598;栦竴鑸?#27996;?#38001;?#32515;?#37711;?#37721;?#28598;?#27996;?#28729;?#37711;?#38000;?#38095;?#38318;?#28028;氱?#20345;鍏?#37721;?#37712;?#38318;?#27996;哄憳鐩?#37818;?#38315;?#26473;SSH鏂?#23534;忕?#35826;綍鍒?#26473;?#32459;?#28051;?#37832;?#26473;?#29723;屾?#23940;綔?#32029;杩?#37837;?#28725;?#38007;SSH閫?#38316;?#28598;?#37825;堬紝Tsung涓?#37832;洪?#26473;SSH杩?#37818;?#37714;?#28000;?#37832;哄苟鎵?#29723;屽懡浠紝涔?#28751;?#28051;嶅彲?#20824;浜?#37510;?/p>

鍏?#28729;烇紝鍦熀浜?#37714;嗗竷寮忓?#23339;?#23340;幆澧?#28051;嬶紝?#25577;閫熺璧?#37510;佸揩閫熷?#37922;?褰?#26473;?#37928;勬鍨嬪氨寰?#38315;?#37722;?#37510;備竴鑸?#37711;?#37721;?#23536;堝?#25116;細瀛?#37734;?#28051;?#38338;?#37922;?#27996;?#37720;嬫祴鐨勫?#22138;绌?#38338;?#37832;哄櫒?#32029;浣?#37828;嚎涓?#28028;?#26473;?#29723;岀潃?#32139;鍓嶈礋杞?#28051;嶉珮鐨?#37832;?#37716;?#37731;紝鍙?#28000;?#37815;挎潵鐢綔鍘嬫祴瀹埛绔?#28003;?#37922;紝鐢?#28729;屽氨褰?#26473;?#37510;傚洜?#36127;鍘嬫祴涓?#28028;?#37828;?#38336;挎椂闂?#26473;?#29723;?#37928;?#37832;?#37716;紝鍏朵负鐭椂闂?#29723;屼负銆?#26473;?#32457;嶆寮?#28051;嬪氨涓?#38315;?#37722;堝?#23942;潅鐨凷SH鍏?#38333;?#23114;?#28598;?#26891;烇紝鍚?#37832;熷繕璁板垹闄?#37928;勬儏鍐碉紝鍦?#37720;嬫祴绔?#29906;?#28598;?#37928;勬儏鍐?#28051;嬶紝鏃犵?#25116;篃灏?#38315;?#37812;?#26473;愮淮鎴?#37832;?#23157;澧烇紝瀹?#37711;?#37804;?#38340;?#28003;?#32475;?#38338;?#26864;?#37510;?/p>

SSH鏇?#37817;?#37826;规锛氫竴绉嶅揩閫熺璧佹寮?#26473;?#32459;嬬粓绔?#37826;规

鐜板湪?#28214;瑕?#28725;?#37813;句竴绉嶆柊鐨?#28000;?#37831;?#37826;规?#22572;紝?#31476;绉?#38315;?#25652;斿揩閫熺璧?#37928;?#26473;?#32459;嬬粓绔?#28729;?#37916;?#37832;?#37714;?#37510;?/p>

鏇?#37817;?#37826;规瑕佹?#20636;偣

  1. 绫?#28028;?#27996;嶴SH Server?#32029;鐩?#37722;?#37836;?#28051;?#32468;?#37721;紝鑳藉?#29112;墽琛?#28028;?#38315;?#26473;囨潵鐨勫懡浠?/li>
  2. 鑳藉鏍规嵁IP鍦板潃鎺堟潈?#32029;杩?#37837;?#37721;?#37832;塗sung Master鎵嶈?#34249;璁?#38338;?#28000;庤?#20636;偣?#32029;浠庤?#20636;偣涔?#38338;存?#29363;硶鐩?#37818;?#28725;?#26473;?/li>
  3. ?#28214;瑕佹帴鍙椾竴浜?#37823;嶆帶鎸?#28000;紝鍙?#28000;?#37714;?#37826;?#37828;?#37722;?#28699;樻椿
  4. ?#31476;鍒?#28051;?#28051;?#38004;?#37832;?绋嬪簭鎼?#28729;氾紝灏介噺?#20265;鍏?#28729;夎?#21635;紝寮绠?#37719;?#37922;?/li>
  5. 鎬?#28052;嬮厤缃?#37510;佹?#23940;綔?#31476;瀹?#29781;?#32480;鍗曪紝瀹?#38340;?#26473;愮淮鎴?#37832;竴瀹?#29781;佷綆

?#30149;鎵?#37714;板緢杞婚噺鐨勫疄鐜帮紝鍙?#28000;?#29825;?#29825;苟瀹?#37916;?#26473;?#37837;蜂竴绉?#37826;规銆?/p>

鏈?#37716;?#37731;?#32468;?#28729;堟姢杩?#32459;?/h4>

杞婚噺绾?#37832;?#37716;?#32468;?#28729;堟姢杩?#32459;?= ?#31476;涓?#37929;戞帶绔?#37721;?#37928;?#26473;?#32459;?#38171;?code>rsh_daemon.sh锛?+ 鎵?#29723;屽懡浠?#26473;?#23114;?#37716;熻兘(rsh_filter)

rsh_daemon.sh 璐?#29840;?#28729;堟姢杩?#32459;?#37928;勭?#24714;锛?/p>

  • ?#29056;浜嶤entOS 6/7榛?#29825;?#28729;夎鐨?code>ncat绋嬪簭
  • 涓?#29781;?#37922;?#27996;?#32480;悊19999绔?#37721;?#37929;?#37722;?/li>
  • start/stop/restart 璐?#29840;?#37929;戞帶杩?#32459;嬪惎鍔?#37510;?#37711;?#38338;?/li>
  • status 鏌?#37930;?#26473;?#32459;嬬姸鎬?/li>
  • kill 鎻愪?#28057;墜鍔?#37826;?#23534;?#37711;?#38338;苟鍒?#38340;?#37818;?#38007;韩
  • rsh_filter鐢?#27996;庢娴?#26473;?#32459;?#28028;?#37711;?#37723;?#28000;苟杩?#29723;屽?#21229;悊
    • 鎺?#37824;ping鎸?#28000;紝杩?#37733;瀙ong
    • 鎵?#29723;孍rlang浠庤?#20636;偣鍛?#28000;紝?#33503;杩?#37733;?done 瀛?#32471;?#28051;?/li>
    • 瀵?#28051;?#37722;堟硶鍛?#28000;紝鐩?#37818;?#37711;?#38338;?/li>

rsh_daemon.sh浠?#37934;?#23536;?#32480;鍗?#38171;?/p>

#!/bin/bash
# the script using for start/stop remote shell daemon server to replace the ssh server
PORT=19999
FILTER=~/tmp/_tmp_rsh_filter.sh
# the tsung master's hostname or ip
tsung_controller=tsung_controller
SPECIAL_PATH=""
PROG=`basename $0`

prepare() {
    cat << EOF > $FILTER
#!/bin/bash

ERL_PREFIX="erl"

while true
do
    read CMD
    case \$CMD in
        ping)
            echo "pong"
            exit 0
            ;;
        *)
            if [[ \$CMD == *"\${ERL_PREFIX}"* ]]; then
                exec $SPECIAL_PATH\${CMD}
            fi
            exit 0
            ;;
    esac
done
EOF
    chmod a+x $FILTER
}

start() {
    NUM=$(ps -ef|grep ncat | grep ${PORT} | grep -v grep | wc -l)

    if [ $NUM -gt 0 ];then
        echo "$PROG already running ..."
        exit 1
    fi

    if [ -x "$(command -v ncat)" ]; then
        echo "$PROG starting now ..."
        ncat -4 -k -l $PORT -e $FILTER --allow $tsung_controller &
    else
        echo "no exists ncat command, please install it ..."
    fi
}

stop() {
    NUM=$(ps -ef|grep ncat | grep rsh | grep -v grep | wc -l)

    if [ $NUM -eq 0 ]; then
        echo "$PROG had already stoped ..."
    else
        echo "$PROG is stopping now ..."
        ps -ef|grep ncat | grep rsh | grep -v grep | awk '{print $2}' | xargs kill
    fi
}

status() {
    NUM=$(ps -ef|grep ncat | grep rsh | grep -v grep | wc -l)

    if [ $NUM -eq 0 ]; then
        echo "$PROG had already stoped ..."
    else
        echo "$PROG is running ..."
    fi
}

usage() {
    echo "Usage: $PROG <options> start|stop|status|restart"
    echo "Options:"
    echo "    -a <hostname/ip>  allow only given hosts to connect to the server (default is tsung_controller)"
    echo "    -p <port>         use the special port for listen (default is 19999)"
    echo "    -s <the_erl_path> use the special erlang's erts bin path for running erlang (default is blank)"
    echo "    -h                display this help and exit"
    exit
}

while getopts "a:p:s:h" Option
do
    case $Option in
        a) tsung_controller=$OPTARG;;
        p) PORT=$OPTARG;;
        s) TMP_ERL=$OPTARG
            if [ "$OPTARG" != "" ]; then
                if [[ "$OPTARG" == *"/" ]]; then
                    SPECIAL_PATH=$OPTARG
                else
                    SPECIAL_PATH=$OPTARG"/"
                fi
            fi
            ;;
        h) usage;;
        *) usage;;
    esac
done
shift $(($OPTIND - 1))

case $1 in
        start)
            prepare
            start
            ;;
        stop)
            stop
            ;;
        status)
            status
            ;;
        restart)
            stop
            start
            ;;
        *)
            usage
            ;;
esac

鎬?#32513;撲竴涓?#38171;?/p>

  • ?#29056;浜?code>ncat鐩?#37722;?9999绔?#37721;?#37819;愪緵bind shell鏈?#37714;讹紝浣嗛檺鍒?#37832;夐檺IP鍙?#29825;?#38338;?/li>
  • 鍔?#37804;?#37922;?#37812;?#37723;?#28000;?#26473;?#23114;?#38004;?#37832;?code>rsh_filter.sh?#32029;鎵?#29723;孍rlang浠庤?#20636;偣鍛?#28000;?/li>

璇?#37721;傝?#38171;?a href="https://github.com/weibomobile/tsung_rsh/blob/master/rsh_daemon.sh">https://github.com/weibomobile/tsung_rsh/blob/master/rsh_daemon.sh

瀹埛绔?#26473;?#37818;?#37826;规

鏈?#37716;?#37731;?#32468;?#23480;?#32513;忔?#24874;緵浜?#32468;?#37721;?#37818;?#37711;苟鍑嗗?#22247;浜嗘帴鏀舵寚浠紝瀹埛绔?#38171;?code>rsh_client.sh锛?#37721;?#28000;?#26473;?#29723;?#26473;?#37818;?#37724;?#27996;?#27996;?#27996;?#38171;?/p>

  • 绫?#28028;SSH瀹埛绔?#37818;?#37824;?#37826;?#23534;?#38171;?code>rsh_client.sh Host/IP Command
  • 瀹屽叏?#29056;浜?code>nc鍛?#28000;紝杩?#37818;?#26473;?#32459;?#28051;?#37832;?/li>
  • 杩?#37818;?#37812;?#37716;燂紝鍙?#38315;佸懡浠?/li>
  • 寰?#37714;?#37929;?#25652;旓紝娴?#32459;?#28729;?#37812;?/li>

?#31476;鏍?#38344;炲父灏?#37928;?#28000;?#37934;佸?#22562;幇銆?/p>

#!/bin/sh

PORT=19999

if [ $# -lt 2  ]; then
    echo "Invalid number of parameters"
    exit 1
fi

REMOTEHOST="$1"
COMMAND="$2"

if [ "${COMMAND}" != "erl"  ]; then
    echo "Invalid command ${COMMAND}"
    exit 1
fi

shift 2

echo "${COMMAND} $*" | /usr/bin/nc ${REMOTEHOST} ${PORT}

Erlang涓昏?#20636;偣濡備綍鍚?#37716;?/h3>

鏈?#27996;SSH鏇?#37817;?#37826;规?#22572;紝閭?#28051;昏?#20636;偣灏?#37721;?#28000;?#26473;?#37837;?#37722;?#37716;?#27996;?#38171;?/p>

erl -rsh ~/.tsung/rsh_client.sh -sname foo -setcookie mycookie

姣斿?#20634;綋Tsung?#28214;瑕?#26473;?#37818;?#37714;板彟澶栦竴鍙?#37832;?#37716;?#37731;?#28051;?#37722;?#37716;?#28000;庤?#20636;偣?#26882;?#32029;瀹?#37832;?#31891;浼氱炕璇?#37812;?#28051;嬮潰鍛?#28000;?#38171;?/p>

/bin/sh /root/.tsung/rsh_client.sh node_slave erl -detached -noinput -master foo@node_master -sname bar@node_slave -s slave slave_start foo@node_master slave_waiter_0 -setcookie mycookie

瀹埛绔?#38004;?#37832;?code>rsh_client.sh鍒?#37832;?#31891;?#28214;瑕佹墽琛?#26473;?#37818;?#37714;?#37832;?#37716;?#37731;?#37510;佸苟鍙?#38315;佸懡鐨勫懡浠?#38171;?/p>

echo "erl -detached -noinput -master foo@node_master -sname bar@node_slave -s slave slave_start foo@node_master slave_waiter_0 -setcookie mycookie" | /usr/bin/nc node_slave 19999

杩?#37837;?#28751;?#28729;?#37916;?#27996;嗗拰SSH?#31476;鏍?#37928;勫?#29115;兘浜嗭紝寰?#32480;鍗?#37722;?#37510;?/p>

Tsung濡備綍鍒?#37817;?#37714;?#37817;?#38171;?/h3>

?#36127;tsung鍚?#37716;?#23075;?#37716;?code>-r鍙傛?#29256;寚瀹?#37719;?#37721;?#38171;?/p>

tsung -r ~/.tsung/rsh_client.sh -f tsung.xml start

杩?#38339;?#38171;?#37721;?#37816;?#28729;?#26473;?#29723;屽懡浠?#29882;?#23536;?/h3>

rsh_client.sh鑴?#37832;?#37832;鍚庝竴琛屼慨鏀逛竴涓嬶紝鎸?#28729;氱洰鏍?#37832;?#37716;?#37731;erl杩?#29723;屽懡浠?#38171;?/p>

#!/bin/sh

PORT=19999

if [ $# -lt 2  ]; then
    echo "Invalid number of parameters"
    exit 1
fi

REMOTEHOST="$1"
COMMAND="$2"

if [ "${COMMAND}" != "erl"  ]; then
    echo "Invalid command ${COMMAND}"
    exit 1
fi

shift 2
exec echo "/root/.tsung/otp_18/bin/erl $*" | /usr/bin/nc ${REMOTEHOST} 19999

涓婇潰鑴?#37832;?#37813;渚?#29863;?#37928;?#28051;?#28051;?#37826;囩幆澧?#37721;?#28000;?#37828;?#26473;?#37837;?#37928;勶紝鏈?#37812;?#37832;?#37716;?#37731;?#37823;嶄綔绯?#32513;熷?#23680;増鏈竴鑷达紝鎴戜滑鎶奅rlang 18.1鏁?#28051;?#26473;?#29723;屾椂?#24134;澧?#37734;竴鍙?#37832;哄櫒涓?#23480;?#32513;?#28729;夎鐨勭洰?#32141;锛堟?#26047;?#20636;洰?#32141;鍚嶄负otp_18锛夛紝鎷?#29840;?#37714;?#26473;?#32459;?#28051;?#37832;?code>/root/.tsung/?#27952;?#32141;?#32029;鐩?#23011;?#27996;?#28729;夎鑰岃?#32029;鍙?#28000;?#29825;Tsung杩?#29723;屼緷璧?#37928;凟ralng?#24134;澧?#28729;屽叏鍙?#28000;?#32457;绘?#23941;寲锛Portable锛夛紝?#31476;娆?#28729;夎?#21635;紝澶氭澶?#37714;?#37510;?/p>

浠?#37934;佹墭绠?#37734;板潃

鏈?#37826;?#37813;璋堝強浠?#37934;侊紝閮?#23480;?#32513;?#37813;?#32480;?#37734;github锛?br/> https://github.com/weibomobile/tsung_rsh

鍚?#32513;?#28000;?#37934;佹洿?#26570;銆丅UG淇?#28598;?#32475;夛紝璇?#37929;?#37818;?#37721;傝?#29831;?#28000;?#25652;?#37510;?/p>

灏?#32513;?/h3>

绠鍗曚竴濂楁柊鐨勬浛鎹SSH閫?#38316;撴棤瀵嗛挜鐧?#38340;?#26473;?#32459;?#28051;?#37832;篊/S妯?#37736;嬶紝?#27367;?#21159;瀹?#37825;存?#28051;?#37827;犳硶涓嶴SH鐩?#23011;旓紝浣?#38003;?#37734;?#32480;鍗?#28598;?#37922;紝瀹屽叏婊?#29906;?#27996;嗗綋鍓?#28051;?#37716;渶瑕侊紝?#33503;涓?#37711;?#26473;愮淮鎴?#37832;?#28003;庯紝鏃犵璁Tsung鍦?#28598;嶆?#20635;湇鍔?#37731;?#37712;?#32515;戠幆澧?#28051;?#38315;?#25652;?#37804;?#37721;?#37832;?#37715;嶅璧?#27996;嗗崐閲岃矾銆?/p>

涓嬩竴绡囧皢浠?#32513;嶄负Tsung澧?#37716;營P鐩?#26473;炵?#35268;?#37824;?#37816;侊紝浣?#37711;?#37714;嗗竷寮?#32515;戠粶?#24134;澧?#28051;?#38315;?#25652;?#37804;?#37831;村娉涗竴浜?#37510;?/p>

nieyong 2016-07-27 09:28 鍙?#29723;?#29831;?#29825;?/a>
]]>Tsung绗?#29825;?#28052;嬪?#23339;祴绔?#29863;勬簮闄?#37714;剁瘒http://www.8634070.com/yongboy/archive/2016/07/26/431322.htmlnieyongnieyongTue, 26 Jul 2016 00:47:00 GMThttp://www.8634070.com/yongboy/archive/2016/07/26/431322.htmlhttp://www.8634070.com/yongboy/comments/431322.htmlhttp://www.8634070.com/yongboy/archive/2016/07/26/431322.html#Feedback0http://www.8634070.com/yongboy/comments/commentRss/431322.htmlhttp://www.8634070.com/yongboy/services/trackbacks/431322.html鍓嶈

杩?#38322;屾眹闆嗕竴涓嬪?#21342;搷tsung client鍒涘?#34425;敤?#22491;鏁?#37928;勫悇椤瑰洜?#30988;銆傚洜?#36127;Tsung鏄疘O瀵嗛?#21975;瀷鐨勫簲鐢紝CPU鍗?#37922;竴鑸?#28051;嶅?#32029;?#36127;浜?#28751;藉彲?#20824;鐨勭敓鎴?#37831;村鐨勭敤?#22491;?#32029;?#28214;瑕佽?#38095;?#37712;?#28699;?#37929;?#37711;?#27996;?#28729;?#37510;?/p>

IP & 绔?#37721;?#37928;勫?#21342;搷

1. 绯?#32513;?#32468;?#37721;?#38340;?#37714;?/h4>

Linux绯?#32513;?#32468;?#37721;负short绫诲?#23341;绀猴紝鏁板?#28051;?#38340;愪负65535銆傚亣璁?#37714;嗛?#23941;?#23339;祴涓?#37716;?#37721;?#37922;?#32468;?#37721;寖鍥翠负1024 - 65535?#32029;涓嶈?#38095;戝彲?#20824;杩?#26473;?#29723;岀潃鍏?#28729;?#28725;瑰杩?#37818;?#37928;?#37832;?#37716;紝鐪熸鍙?#37922;?#32468;?#37721;?#28052;?#28751;?#37828;?4000宸?#37721;?#38171;?#28729;?#38340;?#28051;婏紝?#31476;鑸负浜?#37826;?#28186;?#29825;?#32480;楋紝?#31476;鑸?#37929;?#37818;?#29825;?#28729;氫负50000锛?#37510;傛崲瑷涔嬶紝鍗?#37734;竴鍙?#37832;哄櫒涓婁竴涓狪P?#32029;鍙?#37922;?#37722;屾椂瀵瑰?#26663;?#34425;珛64000缃戠粶杩?#37818;?#37510;?/p>

?#23266;鏄N涓?#37721;?#37922;IP?#32029;?#24714;璁?#28051;?64000*N?#32029;瀹?#38340;?#28051;?#26473;橀渶瑕?#23114;?#29906;?#38171;?/p>

  • 鍏?#29906;?#37712;?#28699;樻敮?#23508;
    • tcp鎺?#37824;?鍙?#38315;佺紦鍐?#37718;?#28051;嶈璁?#32515;?#28598;?#28598;紝tsung榛?#29825;?#37714;嗛厤32K锛堝彲浠?#28103;?#37824;规垚16K?#32029;?#31476;鑸?#28598;?#37922;?#27996;?#38171;?/li>
    • ?#31476;涓?#32494;?#37923;?#28028;?#32480;椾竴涓?#26473;?#37818;?#37719;?#37922;?0K鍐?#28699;橈紝閭?#28052;?0涓?#37922;埛?#32029;灏嗗崰鐢害8G鍐?#28699;?/li>
  • ?#36127;澶欼P鐨勫?#23339;祴绔?#37714;嗛厤閫?#37722;?#37928;勬潈?#22136;?#32029;浠?#28186;?#37813;?#37815;?#37831;村鐨勭粓绔?#26473;?#37818;?/li>

鍙?#28598;?#26473;橀渶瑕佽?#38095;?#32468;?#37721;?#37928;勫揩閫?#37733;炴?#21057;?#22811;紝鍙?#28000;?#26473;?#37837;峰仛锛?/p>

sysctl -w net.ipv4.tcp_syncookies=1
sysctl -w net.ipv4.tcp_tw_reuse=1
sysctl -w net.ipv4.tcp_tw_recycle=1
sysctl -w net.ipv4.tcp_fin_timeout=30
sysctl -w net.ipv4.ip_local_port_range="1024 65535"

sysctl -p

?#23266;宸?#32513;?#37734;?/etc/sysctl.conf 鏂?#28000;?#28051;?#37832;?#29825;板綍?#32029;鍒欓渶瑕佹墜鍔?#28103;?#37824;?/p>

?#32148;?#36127;闄勫姞?#32029;鍙?#29825;?#32515;?#32468;?#37721;噸鐢?#38171;?/p>

<option name="tcp_reuseaddr" value="true"/>

娉?#37808;忥紝涓嶈璁?#32515;?#28051;嬮潰鐨勫彲鐢?#32468;?#37721;寖鍥达細

<option name="ports_range" min="1025" max="65535"/>

?#27932;?#36127;鎿嶄綔绯?#32513;?#28028;?#38007;?#37716;?#29882;?#26473;?#23480;?#32513;忚鍗?#37922;?#37832;?#37734;?#32468;?#37721;紝鑰孴sung鍙?#38003;藉?#29115;鍔?#38315;?#26473;囬敊璇?#26473;?#29723;屽彲鐢?#32468;?#37721;?1缁?#32513;?#28051;嬩竴涓?#26473;?#37818;紝鏈?#27996;?#28598;?#28003;?#37510;?/p>

2. IP鍜?#32468;?#37721;?#32513;勫悎

姣忎竴涓猚lient鏀寔澶?#28051;?#37721;?#37922;IP鍦板潃鍒?#29723;?/p>

<client host="client_99" maxusers="120000" weight="2" cpu="8">
    <ip value="10.10.10.99"></ip>
    <ip value="10.10.10.11"></ip>
</client>

tsung client浠庤?#20636;偣寮濮嬪?#21975;?#22247;?#34425;珛缃戠粶杩?#37818;?#28028;?#29831;濇椂?#32029;?#28214;瑕佷粠tsung_controller涓昏?#20636;偣?#24143;鍙?#37711;?#28003;?#37928;?#28028;?#29831;濅俊鎭紝鍏?#28051;?#28751;?#37718;?#37722;?#27996;?#28729;埛绔?#26473;?#37818;渶瑕佷娇鐢?#37714;版潵?#31790;{LocalIP?#32029; LocalPort}浜屽厓缁?#37510;?#37922;眛sung_controller涓昏?#20636;偣瀹?#37812;?#37510;?/p>

get_user_param(Client,Config)->
    {ok, IP} = choose_client_ip(Client),
    {ok, Server} = choose_server(Config#config.servers, Config#config.total_server_weights),
    CPort = choose_port(IP, Config#config.ports_range),
    {{IP, CPort}, Server}.

choose_client_ip(#client{ip = IPList, host=Host}) ->
    choose_rr(IPList, Host, {0,0,0,0}).

......

choose_client_ip(#client{ip = IPList, host=Host}) ->
    choose_rr(IPList, Host, {0,0,0,0}).

choose_rr(List, Key, _) ->
    I = case get({rr,Key}) of
          undefined -> 1 ; % first use of this key, init index to 1
          Val when is_integer(Val) ->
            (Val rem length(List))+1 % round robin
    end,
    put({rr, Key},I),
    {ok, lists:nth(I, List)}.

%% 榛?#29825;?#28051;?#29825;?#32515;?ports_range 浼?#37929;?#37818;?#26473;?#37733;?
%% 涓嶅缓璁?#29825;?#32515;?<option name="ports_range" min="1025" max="65535"/>
%% ?#27932;?#36127;杩?#37837;?#28699;?#37734;?#32468;?#37721;?#37712;茬獊闂?#26864;橈紝闄?#38344;炵瀹?#28051;?#28699;?#29722;?#37719;?#37922;?#37807;?#37712;?choose_port(_,_, undefined) ->
    {[],0};
choose_port(Client,undefined, Range) ->
    choose_port(Client,dict:new(), Range);
choose_port(ClientIp,Ports, {Min, Max}) ->
    case dict:find(ClientIp,Ports) of
        {ok, Val} when Val =< Max ->
            NewPorts=dict:update_counter(ClientIp,1,Ports),
            {NewPorts,Val};
        _ -> % Max Reached or new entry
            NewPorts=dict:store(ClientIp,Min+1,Ports),
            {NewPorts,Min}
    end.

浠庤?#20636;偣寤虹?#23338;?#26495;?#23339;祴鏈?#37716;?#37731;?#26473;?#37818;椂?#32029;灏遍渶瑕佹寚瀹?#28000;?#28051;昏?#20636;偣?#24143;鍙?#37714;?#37928;?#37832;?#37832;篒P鍦板潃鍜?#32468;?#37721;?#28051;?#37711;?#32513;?#38171;?/p>

Opts = protocol_options(Protocol, Proto_opts)  ++ [{ip, IP},{port,CPort}],
......
gen_tcp:connect(Server, Port, Opts, ConnectTimeout).

3. IP鑷?#37716;?#37813;弿鐗规?/h4>

?#23266;浠?#37832;?#37719;?#28051;?#32515;?#37719;?#32513;?#28729;?#27996;嗗涓狪P?#32029;鍙堟浜庤緭鍏紝鍙?#28000;厤缃?#37813;弿鐗规?

<ip scan="true" value="eth0"/>

鏈?#29840;?#28051;?#28003;?#37922;shell鏂?#23534;忚幏鍙朓P鍦板潃?#32029;?#33503;涓?#37824;寔CentOS 6/7銆?/p>

    /sbin/ip -o -f inet addr show dev eth0

?#27932;?#36127;鎵弿姣旇緝鎱紝Tsung 1.6.1鎺?#37713;?#27996;?code>ip_range鐗规?#37824;寔銆?/p>

Linux绯?#32513;熸墦寮鏂?#28000;?#37721;?#37836;?#38340;?#37714;?/h3>

绯?#32513;熸墦寮鏂?#28000;?#37721;?#37836;勶紝鐩?#37818;?#37712;?#28729;?#27996;嗗彲浠?#37722;屾椂鎵?#23534;鐨勭?#25120;粶杩?#37818;?#37825;伴?#24549;紝杩?#28051;渶瑕?#29825;?#32515;?#28598;竴浜涳紝鍚?#37714;欙紝浣犲彲?#20824;浼?#37734;?a href="mailto:tsung_controller@IP.log">tsung_controller@IP.log鏂?#28000;?#28051;?#37930;嬪埌error_connect_emfile绫?#28028;?#37826;?#28000;?#37721;?#37836;?#28051;嶅浣?#37922;?#37928;勮鍛婏紝?#32531;璁?#23005;?#37706;?#29781;?#28598;?#27996;?> N * 64000銆?/p>

echo "* soft nofile 300000" >> /etc/security/limits.conf
echo "* hard nofile 300000" >> /etc/security/limits.conf

鎴?#38000;咃紝鍦Tsung浼?#29831;?#37722;?#37716;?#38004;?#37832;?#37826;?#28000;?#28051;?#37828;庣娣?#37716;?#28051;?code>ulimit -n 300000銆?/p>

鍐?#28699;?#37928;勫?#21342;搷

?#31476;涓?#32515;戠粶Socket杩?#37818;?#37719;?#37922;?#28051;嶅?#27710;紝浣?#28051;?#28051;?#28051;?#37812;?#37825;板?#20343;竾绛?#28751;?#28051;?#28729;?#28751;?#29785;戜?#21997;紝璁?#32515;?#28051;嶅綋浼?#28725;?#38007;村唴瀛?#37929;?#37818;?#37812;愪负灞?#38341;?#37510;?/p>

1. TCP鎺?#37824;?#37510;?#37721;?#38315;佺紦瀛?/h4>

Tsung榛?#29825;?#29825;?#32515;?#37928;勭?#25120;粶Socket鍙?#38315;佹帴鏀剁紦鍐?#37718;轰负16KB?#32029;?#31476;鑸?#28598;?#37922;?#27996;?#37510;?/p>

浠TCP?#36127;渚嬶紝鏌愭鎴戞墜璇负Tcp鎺?#37824;剁紦瀛?#29863;嬪?#26473;囧(599967瀛?#38010;??#32029;杩?#37837;?#23011;忎竴涓?#32515;戠粶浜?#29785;?#38007;?#28751;?#37719;?#37922;?#27996;?.6M鍐?#28699;橈紝鐩?#37818;?#28725;?#38007;村湪16G鍐?#28699;?#37832;?#37716;?#28051;?#32515;戠粶杩?#37818;?#37825;板埌2涓囧?#27693;椂?#32029;鍐?#28699;?#37723;?#37804;?#37510;?/p>

<option name="tcp_snd_buffer" value="16384"></option>
<option name="tcp_rcv_buffer" value="16384"></option>

姝?#37706;?#28028;?#29781;?#37929;Linux绯?#32513;?#29825;?#32515;?#37818;?#37824;?#37510;?#37721;?#38315;佺紦鍐?#28598;?#28751;?#37510;?/p>

绮?#37923;?#37928;勯粯璁?#37706;?#29825;?#32480;楋紝?#31476;涓?#32515;戠粶杩?#37818;?#37721;?#38315;佺紦鍐?#37718;?+ 鎺?#37824;剁紦鍐?#37718;猴紝鍐?#37716;?#28051;?#26473;?#32459;嬪?#21229;悊杩?#37818;爢鏍堝崰鐢紝?#23475;40澶欿鍐?#28699;橈紝?#36127;鍗?#29825;?#32480;?#37826;?#28186;匡紝璁?#28729;氬?#34425;珛?#31476;涓?#32515;戠粶杩?#37818;秷璐?0K鍐?#28699;?#37510;?/p>

鍏?#28051;嶈?#38095;?#37711;?#28729;冨洜?#30988;?#32029;?#23266;鎴戜滑?#20802;瑕佷粠鏈烘鎷?0W涓?#37922;埛?#32029;閭?#28052;堝綋鍓嶅彲鐢?#37712;?#28699;?#38007;?#28751;?#29781;?#37715;?#28003;?#38171;?0K * 100000 / 1000K = 5000M = 5G鍐?#28699;?#37510;傞?#22557;?#36891;竴鑸?#37832;?#37716;?#37731;潵璁诧紝瀹屽叏鍙?#23114;?#29906;?#29781;佹眰锛?#37715;?#28051;?#27996;嬫儏灏?#37828;?#29781;?#37832;?#28051;?#28051;?#37721;?#37922;IP浜?#38171;?#37510;?/p>

2. Erlang鍑?#37825;板爢鏍堝唴瀛?#37719;?#37922;?/h4>

浣?#37922;Erlang绋嬪簭鍐?#37928;勫簲鐢?#37832;?#37716;?#37731;紝杩?#32459;?#29781;?#28699;樺偍?#29218;鏍堣皟鐢俊鎭紝杩?#32459;嬩竴澶?#28052;呬細鍗?#37922;?#28598;噺鍐?#28699;橈紝?#20802;瑕?#37832;?#37716;?#37831;村缃戠粶杩?#37818;?浠?#37716;紝?#28214;瑕?#28751;?#28051;嶆椿鍔?#37928;?#26473;?#32459;?#29825;?#32515;负浼戠?#29365;姸鎬侊紝浠?#28186;?#38010;傜渷鍐?#28699;橈紝Tsung鐨勫?#23339;祴浼?#29831;濅俊鎭嫢鍖?#37722;thinktime?#26882;闂达紝涔?#29781;佽?#38095;?#37722;?#37922;hibernate浼戠湢鏈?#37714;?#37510;?/p>

<option name="hibernate" value="5"></option>

鍊?#37719;?#28003;?#32457;掞紝榛?#29825;thinktime瓒?#26473;?0绉?#37722;?#38007;?#37716;?#37722;?#37716;紝杩?#38322;屼慨鏀逛负5绉?#37510;?/p>

XML鏂?#28000;?#29825;?#32515;渶瑕佹敞鎰?#38318;?#37714;?/h3>

1. 鏃織绛?#32510;?#29781;佽?#20910;?#27193;竴浜?/h4>

tsung浣?#37922;error_logger璁板綍鏃織?#32029;鍏?#37721;?#38315;?#37922;?#27996;?#37930;熸鐨勫?#20634;父鎯?#37712;碉紝?#23266;?#32139;?#31476;鑸?#28051;?#37716;皟璇?#32491;诲?#23339;棩?#32340;?#22138;杩囧?#27693;椂?#32029;涓?#28003;?#38000;?#29840;?#27996;嗗?#22138;鍐?#28699;橈紝缃戠粶/纾?#37929;?#37712;?#37711;?#38315;熷害璺?#28051;?#28051;?#37922;?#27996;?#38315;熷害?#26882;?#32029;浼?#28725;?#38007;?#26473;?#32459;嬪?#38747;?#28871;紝涓噸浼氭?#26667;疮鏁?#28051;?#25652;?#37922;?#37709;垫?#20249;紝?#27932;姝渶瑕?#37734;tsung.xml鏂?#28000;?#28051;?#29825;?#32515;?#37827;織绛?#32510;?#29781;侀?#27193;竴浜涳紝鑷?#28751;戦粯璁?#37928;刵otice灏?#23536;?#37722;?#38315;?#37510;?/p>

2. 涓嶈鍚?#37922;dump

dump鏄竴涓?#38000;楁椂鐨勮?#23676;负?#32029;?#27932;姝?#27035;?#29825;负false?#32029;闄?#38344;?#23536;堝皯鐨勫?#23339;祴鐢埛鐢?#27996;庤皟璇?#37510;?/p>

3. 鍔?#37804;佸?#28852;?#28598;?#28598;氾紝浼?#28725;?#38007;?#29831;锋眰瓒呮椂

<option name="file_server" id="userdb" value="/your_path/100w_users.csv"/>

...

<setdynvars sourcetype="file" fileid="userdb" delimiter=";" order="iter">
    <var name="userid" />
    <var name="nickname" />
</setdynvars>

...

<request subst="true">
    <yourprotocol type="hello" uid="%%_userid%%" ack="local">
        Hello, I'm %%_nickname%%
    </yourprotocol>
</request>

璁?#28729;氫竴涓?#37832;夌姸鎬?#37928;勫?#28888;櫙?#32029;鐢埛ID?#20557;瀛?#37734;?#37826;?#28000;?#28051;紝姣忎竴娆?#28028;?#29831;?#29831;锋眰閮?#29781;佷粠?#24143;鍙?#37714;?#37922;埛ID?#32029;鍘嬫祴鐢埛?#31476;鏃?#26440;?#37714;扮櫨涓?#32510;?#37714;苟涓?#37922;埛姣?#32457;?#27996;?#37922;?#38315;熺巼杩囧锛堟?#26047;?#20635;瘡绉?000涓?#37922;埛锛夛紝浼?#32513;忓父閬?#37714;?#29906;呮椂?#25930;璇?#38171;?/p>

=ERROR REPORT==== 25-Jul-2016::15:14:11 ===
** Reason for termination =
** {timeout,{gen_server,call,
                        [{global,ts_file_server},{get_next_line,userdb}]}}

杩?#37828;洜?#36127;?#32029;?#32139;tsung client閬?#37714;?code>setdynvars鎸?#28000;椂?#32029;浼?#37929;?#37818;?#29831;锋眰涓?#37832;簍s_file_server妯潡?#32029;?#32139;?#31476;?#26882;闂?#29831;锋眰?#22138;宸?#28598;紝鍙兘浼?#38315;?#37812;?#37719;曚竴妯潡澶勭悊缂撴參?#32029;鍑虹幇瓒呮椂闂?#26864;?#37510;?/p>

鎬?#28052;堝姙锛?/p>

  1. 闄?#28003;?#37922;埛姣?#32457;?#27996;?#37922;?#38315;熺?#22263;紝姣斿300绉?#37922;埛鐢?#37812;?/li>
  2. 涓?#37922;?#28000;?#37826;?#28000;?#28051;?#28699;樺偍鐢埛id绛変俊鎭紝閲?#37922;?#37714;?#37928;?#37826;?#23534;?/li>

濡備綍闄?#23092;?闄?#38315;?/h3>

鏌愪?#28057;椂鍊欙紝瑕侀伩鍏峵sung client鍘嬫祴绔?#35120;卞?#23942;墍鍦?#37832;?#37716;?#37731;?#32515;戠粶甯?#28729;IO澶?#37815;?#37816;紝?#28214;瑕?#38340;?#37714;?#23092;?#38322;忥紝鍏?#38322;?#37922;?#28000;?#37911;屾绠楁硶銆?/p>

<option name="rate_limit" value="1024"></option>
  • 鍊间负KB鍗?#28003;嶆瘡绉?/li>
  • ?#27952;鍓?#28000;?#28725;?#28028;?#37711;?#23092;侀噺鐢?#37825;?/li>

闃鍊?#29825;?#32480;?#37826;?#23534;?#38171;?/p>

{RateConf,SizeThresh} = case RateLimit of
                            Token=#token_bucket{} ->
                                Thresh=lists:min([?size_mon_thresh,Token#token_bucket.burst]),
                                {Token#token_bucket{last_packet_date=StartTime}, Thresh};
                            undefined ->
                                {undefined, ?size_mon_thresh}
           end,

鎺?#37824;?#28028;?#37711;?#23092;侀噺鏁版嵁?#32029;?#28214;瑕?#29825;?#32480;?#38171;?/p>

handle_info2({gen_ts_transport, _Socket, Data}, wait_ack, State=#state_rcv{rate_limit=TokenParam}) when is_binary(Data)->
    ?DebugF("data received: size=~p ~n",[size(Data)]),
    NewTokenParam = case TokenParam of
                        undefined ->
                            undefined;
                        #token_bucket{rate=R,burst=Burst,current_size=S0, last_packet_date=T0} ->
                            {S1,_Wait}=token_bucket(R,Burst,S0,T0,size(Data),?NOW,true),
                            TokenParam#token_bucket{current_size=S1, last_packet_date=?NOW}
                    end,
    {NewState, Opts} = handle_data_msg(Data, State),
    NewSocket = (NewState#state_rcv.protocol):set_opts(NewState#state_rcv.socket,
                                                       [{active, once} | Opts]),
    case NewState#state_rcv.ack_done of
        true ->
            handle_next_action(NewState#state_rcv{socket=NewSocket,rate_limit=NewTokenParam,
                                                  ack_done=false});
        false ->
            TimeOut = case (NewState#state_rcv.request)#ts_request.ack of
                global ->
                    (NewState#state_rcv.proto_opts)#proto_opts.global_ack_timeout;
                _ ->
                    (NewState#state_rcv.proto_opts)#proto_opts.idle_timeout
            end,
            {next_state, wait_ack, NewState#state_rcv{socket=NewSocket,rate_limit=NewTokenParam}, TimeOut}
    end;

涓嬮潰鍒?#37828;?#37711;?#28003;?#37928;?#28000;?#37911;屾绠楁硶锛?/p>

%% @spec token_bucket(R::integer(),Burst::integer(),S0::integer(),T0::tuple(),P1::integer(),
%%                    Now::tuple(),Sleep::boolean()) -> {S1::integer(),Wait::integer()}

%% @doc Implement a token bucket to rate limit the traffic: If the
%%      bucket is full, we wait (if asked) until we can fill the
%%      bucket with the incoming data
%%      R = limit rate in Bytes/millisec, Burst = max burst size in Bytes
%%      T0 arrival date of last packet,
%%      P1 size in bytes of the packet just received
%%      S1: new size of the bucket
%%      Wait: Time to wait
%% @end
token_bucket(R,Burst,S0,T0,P1,Now,Sleep) ->
    S1 = lists:min([S0+R*round(ts_utils:elapsed(T0, Now)),Burst]),
    case P1 < S1 of
        true -> % no need to wait
            {S1-P1,0};
        false -> % the bucket is full, must wait
            Wait=(P1-S1) div R,
            case Sleep of
                true ->
                    timer:sleep(Wait),
                    {0,Wait};
                false->
                    {0,Wait}
            end
    end.

灏?#32513;?/h3>

浠?#28051;?#32480;鍗曟?#23815;?#21973;竴涓嬪?#21342;搷tsung浠?#37832;?#37714;涘?#34425;敤?#22491;鐨勫悇椤瑰洜?#30988;?#32029;瀹?#38340;呯幆澧?#37711;?#28729;?#37929;稿綋澶嶆潅?#32029;?#28214;瑕佷竴?#31476;瀵圭棁涓嬭嵂鎵嶈銆?/p>

nieyong 2016-07-26 08:47 鍙?#29723;?#29831;?#29825;?/a>
]]>Tsung绗?#29825;?#28052;?#28051;?#28000;庤?#21228;簮鍗忚?#20906;瘒http://www.8634070.com/yongboy/archive/2016/07/25/431310.htmlnieyongnieyongMon, 25 Jul 2016 06:02:00 GMThttp://www.8634070.com/yongboy/archive/2016/07/25/431310.htmlhttp://www.8634070.com/yongboy/comments/431310.htmlhttp://www.8634070.com/yongboy/archive/2016/07/25/431310.html#Feedback1http://www.8634070.com/yongboy/comments/commentRss/431310.htmlhttp://www.8634070.com/yongboy/services/trackbacks/431310.html鍓嶈

鎺潃涓?#37826;囷紝tsung?#31476;鏃?#37722;?#37716;紝涓?#28000;庤?#20636;偣涔?#38338;撮渶瑕?#37719;忚皟鍒嗛?#23944;?#21228;簮?#32029;瀹?#37812;?#37714;嗗竷寮忓?#23339;祴浠?#37716;?#37510;?/p>

濡備綍鍚?#37716;Tsung鍘嬫祴浠?#37832;?/h3>

Erlang SDK鎻愪緵浜?#28000;?#37832;?#37722;?#37716;?#37826;?#23534;?#38171;?/p>

slave:start(Host, Node, Opts)

鍚?#37716;?#28000;?#37832;洪渶瑕佸?#37716;?#27996;?#37711;?#37927;?#38340;嗗舰寮?#26473;?#32459;嬬粓绔紝姣斿?#20418;SH锛?#37722;?#32513;?#28028;?#29825;?#29825;SSH瀛?#37734;?#28051;嶈冻?#32029;浠?#37721;?#37711;柊鐨勬浛浠搧锛夛紝?#28214;瑕?#38007;?#29723;岄厤缃?#37510;?/p>

<client host="client_100" maxusers="60000" weight="1">
    <ip value="10.10.10.100"/>
</client>
  • host灞炴?#28725;瑰簲value?#36127;浠?#37832;?#28051;?#37832;?#37722;?#32457;?#38171;?strong>client_100
  • Node鑺傜偣鍚?#32457;?#37922;眛sung_controller缁勮?#21635;紝绫?#28028;?#27996;?tsung10@client_100
  • Opts琛?#32448;虹浉鍏?#37721;傛暟
  • ?#31476;涓?#37911;悊鏈哄櫒?#32029;鍙?#28000;?#28699;?#37734;?#28598;?#28051;猼sung浠?#37832;?#28729;?#28186;?/li>
  • ?#31476;涓猼sung浠?#37832;?#28729;?#28186;嬪?#29808;簲?#31476;涓猼sung client

绠鍗曠炕璇戜竴涓?#38171;?code>slave:start(client_100, 'tsung10@client_100', Opts)

浠?#37832;洪渶瑕?#37711;?#38338;椂?#32029;灏?#23536;?#32480;鍗?#27996;?#38171;?/p>

slave:stop(Node)

?#32139;?#21159;?#23266;涓?#37832;?#28051;?#38315;?#37816;傛?#22811;紝浠?#37832;?#28052;?#28028;?#38007;?#37716;?#38007;潃鎺?#38007;韩銆?/p>

鍚?#37716;tsung client鏂?#23534;?/h4>

Tsung涓?#37832;?#37722;?#37716;?#28000;?#37832;?#37812;?#37716;燂紝浠?#37832;?#37724;?#28051;?#37832;?#28751;?#37721;?#28000;Erlang鑺傜偣杩?#32459;?#28052;?#38338;?#26473;?#29723;屾?#35268;?#26337;皟鐢?#37724;屾?#22559;伅浼?#38315;?#37510;傛綔鍦?#29781;佹?#20635;槸?#32029;tsung缂?#29831;?#37722;巄eam鏂?#28000;?#38003;藉?#29111;湪Erlang杩?#29723;屾椂?#24134;澧?#28051;?#38003;藉璁?#38338;?#37714;帮紝杩?#28051;?#37724;孞ava Classpath?#31476;鑷村?#29114;悊銆?/p>

rpc:multicall(RemoteNodes,tsung,start,[],?RPC_TIMEOUT)

鍒版?#36127;姝紝?#31476;涓猼sung client瀹?#28186;?#37812;?#37716;?#26473;?#29723;?#37510;?/p>

  • tsung client瀹?#28186;?#37922;熷?#34249;懆鏈?#32513;?#37833;燂紝涓?#28028;?#28725;?#38007;?#28000;?#37832;?#28729;?#28186;?#28051;?#37716;?#37711;?#38338;?/li>
  • tsung slave鎻愪緵浜?#26473;?#29723;屾椂?#24134;澧冿紝tsung client鏄?#28051;?#37716;?/li>
  • tsung slave鍜宼sung client鍏?#32495;?#37828;? : 1鍏?#32495;伙紝寰堝?#27693;椂鍊欎负浜嗙悊瑙?#37826;?#28186;匡紝涓?#28028;?#26473;?#29723;?#28051;?#37837;?#37718;?#37714;?/li>

鍘嬫?#23340;洰鏍?/h3>

鏄庣櫧浜?#28051;?#28000;?#37722;?#37716;?#37826;?#23534;忥紝涓嬮潰璁?#29825;?#37720;嬫?#23340;洰鏍囷紝姣斿50涓?#37922;埛鐨?#38322;忥紝鏍规嵁缁?#37713;?#37928;勫?#23339;祴浠?#37832;?#37714;?#29723;紝杩?#29723;?#28000;?#37716;?#37714;嗛厤銆?/p>

鍘嬫?#23340;洰鏍囬厤缃?/h4>

tsung鍘嬫祴xml?#21412;缃?#37826;?#28000;讹紝load鍏冪?#29362;彲浠厤缃?#37804;?#28003;?#28000;?#37716;?#37922;?#37812;?#37928;勪俊鎭?#37510;?/p>

<load>
    <arrivalphase phase="1" duration="60" unit="minute">
        <!--users maxnumber="500000" interarrival="0.004" unit="second"></users-->
        <users maxnumber="500000" arrivalrate="250" unit="second"></users>
    </arrivalphase>
</load>
  • 瀹?#28052;変竴涓?#37832;?#31891;鍘嬪姏浜?#37922;熷彲浠?#37816;佺画60鍒嗛?#29111;?#23339;?#23338;?#28888;櫙?#32029; 涓?#38340;?#37922;埛閲忎负50涓?/li>
  • arrivalphase duration灞炴?#37816;佺画?#26882;闀?#29723;?#32448;虹敓鎴?#37720;嬫祴鐢埛鍙秷璐规?#28003;撴椂闂?0鍒嗛?#29122;紝鍗充负T1
  • users鍏冪礌鍏?#28766;炴?#29723;?#32448;?#37719;?#28003;嶆椂闂村唴锛?#26473;?#38322;屽崟浣嶆椂闂翠负绉?#38171;?#27996;?#37922;?#37922;埛鏁颁负250涓?/li>
  • 50涓?#37922;埛?#32029;灏嗗湪2000绉??#23475;34鍒嗛挓)鍐?#37922;?#37812;愶紝鑰楁椂?#26882;闀?#37719;充负T2
  • T2灏?#27996;arrivalphase瀹?#28052;?#37928;勭敤?#22491;鐢?#37812;?#38339;?#23048;垫?#20346;画?#26882;闂碩1
  • ?#23266;T2?#26882;闂村悗锛?4鍒嗛挓)鍚庡洜?#36127;浜?#37922;?#37922;埛鏁板凡缁忚揪鍒?#27996;?#28051;?#38340;愶紝灏?#28051;嶅啀浜?#37922;熸柊鐨勭敤?#22491;?#32029;鐭?#38316;?#37825;?#28051;?#37720;嬫祴缁?#37833;?/li>
  • ?#23266; T1 灏?#27996;?T2?#32029;鍒?0涓?#37922;埛寰堥?#25424;揪鍒帮紝?#27932;姝T1?#26882;闂?#29781;?#29825;?#32515;?#38336;夸竴浜?/li>

浠庤?#20636;偣?#20426;鎭厤缃?/h4>

鎵璇?#28000;庤?#20636;偣涔?#37828;?#37720;嬫祴瀹埛绔紝?#28214;瑕侀厤缃甤lients鍏冪礌锛?/p>

<clients>
    <client host="client_100" maxusers="60000" weight="1">
        <ip value="10.10.10.100"/>
    </client>

    ......

    <client host="client_109" maxusers="120000" weight="2">
        <ip value="10.10.10.109"></ip>
        <ip value="10.10.10.119"></ip>
    </client>
</clients>
  1. 鍗?#28051;猚lient鏀寔澶?#28051;狪P?#32029;鐢?#27996;庣?#20346;?#26449;崟涓狪P瀵瑰?#26663;?#34425;珛杩?#37818;?#37825;?#37928;?#38340;?#37714;?鍚?#32513;?#28028;?#29825;?#37714;?#38171;?/li>
  2. xml鎵瀹?#28052;?#37928;勪竴涓猚liet鍏冪礌?#32029;鍙兘琚?#37714;嗚鍑鸿嫢骞?#28000;?#37832;?#28729;?#28186;?鍗硉sung client)?#32029;1 : N

鏍规嵁CPU鏁伴噺鍒嗚?#20480;sung client瀹?#28186;嬫儏鍐?/h4>

鍦?#37510;奣sung Documentation銆?#32513;?#37713;?#27996;嗗缓璁紝?#31476;涓狢PU?#31476;涓猼sung client瀹?#28186;?#38171;?/p>

Note: Even if an Erlang VM is now able to handle several CPUs (erlang SMP), benchmarks shows that it鈥檚 more efficient to use one VM per CPU (with SMP disabled) for tsung clients. Only the controller node is using SMP erlang.
Therefore, cpu should be equal to the number of cores of your nodes. If you prefer to use erlang SMP, add the -s option when starting tsung (and don鈥檛 set cpu in the config file).

  • 榛?#29825;?#32475;栫暐, ?#31476;涓猼sung client瀵瑰簲?#31476;涓狢PU?#32029;?#23266;涓?#29825;?#32515;瓹PU灞炴紝榛?#29825;?#37706;?#28751;?#37828;?
  • ?#31476;涓猚pu瀵瑰簲?#31476;涓猼sung client?#32029;N涓狢PU?#32029;N涓猼sung client
  • 鍏?#37722;屽垎鎷?#37833;冮噸?#32029;姣忎竴涓?#37714;嗚鐨則sung client鏉冮噸 Weight/N
  • ?#31476;鏃?#29825;?#32515;甤pu灞炴紝?#26852;璁篢sung鍚?#37716;椂鏄?#37722;?#37820;哄甫-s鍙傛暟璁?#32515;?#37711;?#27996;CPU?#32029;閮?#28028;?
    • 鑷?#37716;?#37714;嗚CPU涓猼sung client瀹?#28186;?/li>
    • 姣忎竴涓?#28729;?#28186;嬫潈閲嶄负Weight/CPU
%% add a new client for each CPU
lists:duplicate(CPU,#client{host     = Host,
                            weight   = Weight/CPU,
                            maxusers = MaxUsers})

?#23266;瑕?#29825;?#32515;?#37719;?#28051;猼sung client瀹?#28186;嬪叡浜?#28598;?#28051;狢PU锛堟?#26882;涓嶈璁?#32515;甤pu灞炴?#37727;?#38171;夛紝?#28214;瑕?#37734;tsung鍚?#37716;椂娣?#37716;?code>-s鍙傛暟?#32029;tsung client琚?#37722;?#37716;椂?#32029;smp灞炴?#29722;?#29825;?#32515;?#37812;恆uto锛?/p>

-smp auto +A 8

杩?#37837;?#28000;?#37832;?#28751;?#37721;?#37832;変竴涓猼sung client瀹?#28186;?#27996;嗭紝涓?#28028;?#29825;?#27996;?#27996;?#37922;?#37733;?#37813;?#37510;傝嫢鏄?#28051;存椂绉熷?#28000;?#37832;猴紝?#32531;璁?#37722;?#37716;椂浣?#37922;?s鍙傛暟?#32029;?#33503;涓旇?#20344;幓闄cpu灞炴?#29825;?#32515;紝杩?#37837;?#37813;嶈?#34249;鑷?#37716;?#37711;?#27996;?#37813;鏈塁PU鏍稿績銆?/p>

浠?#37832;?#37714;嗛厤鐢埛杩囧?#27710;紝?#31476;鏍?#28028;?#37714;嗚?#20635;柊鐨則sung client瀹?#28186;?/h4>

鍋?#29825;client鍏冪礌?#21412;缃?code>maxusers鏁伴?#24526;负1K?#32029;閭?#28052;?#28729;?#38340;?#28051;?#29722;?#37714;嗛厤鏁伴?#24526;负10K(鍘嬫祴浜?#37825;板?#27710;紝鍘嬫祴浠?#37832;?#28751;??#26882;?#32029;閭?#28052;?code>tsung_controller浼?#32513;?#32513;?#37714;嗚?#20635;柊鐨則sung client瀹?#28186;嬶紝鐩村埌10K鐢埛鏁伴噺瀹?#37812;?#37510;?/p>

<client host="client_98" maxusers="1000" weight="1">
    <ip value="10.10.10.98"></ip>
</client>

tsung client鍒嗛厤鐨?#37825;伴噺瓒?#26473;?#38007;韩鍙?#37832;?#37716;?#28051;?#38340;?#37922;埛?#26882;锛?#26473;?#38322;?#29825;?#32515;?#37928;?#37828;?K锛夋椂?#32029;鍏?#38338;?#38007;韩銆?/p>

launcher(_Event, State=#launcher{nusers = 0, phases = [] }) ->
    ?LOG("no more clients to start, stop  ~n",?INFO),
    {stop, normal, State};

launcher(timeout, State=#launcher{nusers        = Users,
                                  phase_nusers  = PhaseUsers,
                                  phases        = Phases,
                                  phase_id      = Id,
                                  started_users = Started,
                                  intensity     = Intensity}) ->
    BeforeLaunch = ?NOW,
    case do_launch({Intensity,State#launcher.myhostname,Id}) of
        {ok, Wait} ->
            case check_max_raised(State) of
                true ->
                    %% let the other beam starts and warns ts_mon
                    timer:sleep(?DIE_DELAY),
                    {stop, normal, State};
                false->
                    ......
            end;
        error ->
            % retry with the next user, wait randomly a few msec
            RndWait = random:uniform(?NEXT_AFTER_FAILED_TIMEOUT),
            {next_state,launcher,State#launcher{nusers = Users-1} , RndWait}
    end.

tsung_controller鎺?#37824;?#28000;庤?#20636;偣閫鍑洪氱煡?#32029;浣?#37714;嗛?#23942;?#37825;版病鏈?#28729;?#37812;愶紝浼?#37722;?#37716;柊鐨則sung client瀹?#28186;?#38171;堜竴鏍?#37711;?#37722;?#37716;?#28000;庤?#20636;偣?#32029;?#21159;鍚?#37712;?#37722;?#37716;tsung client瀹?#28186;?#38171;?#37510;傛暣涓?#26473;?#32459;?#28051;?#29723;屾柟寮?#23536;幆?#32029;鐩村埌10K鐢埛鏁伴噺瀹?#37812;?#38171;?/p>

%% start a launcher on a new beam with slave module
handle_cast({newbeam, Host, Arrivals}, State=#state{last_beam_id = NodeId, config=Config, logdir = LogDir}) ->
    Args = set_remote_args(LogDir,Config#config.ports_range),
    Seed = Config#config.seed,
    Node = remote_launcher(Host, NodeId, Args),
    case rpc:call(Node,tsung,start,[],?RPC_TIMEOUT) of
        {badrpc, Reason} ->
            ?LOGF("Fail to start tsung on beam ~p, reason: ~p",[Node,Reason], ?ERR),
            slave:stop(Node),
            {noreply, State};
        _ ->
            ts_launcher_static:stop(Node), % no need for static launcher in this case (already have one)
            ts_launcher:launch({Node, Arrivals, Seed}),
            {noreply, State#state{last_beam_id = NodeId+1}}
    end;

tsung client鍒嗛厤鐢埛鏁?/h3>

?#31476;涓猼sung client鍒嗛厤鐨勭敤?#22491;鏁帮紝鍙?#28000;悊瑙负浼?#29831;?#28000;?#37716;?#37825;?#37510;俆sung浠粓绔?#37721;?#28000;?#22959;?#37815;?#37928;勭敤?#22491;?#36127;?#28142;搴?#26473;?#29723;?#28729;?#28052;?#37720;嬫祴銆?/p>

鎵鏈夐厤缃畉sung client鍏冪礌锛?#29825;?#32515;甅1锛夋潈?#22136;鐩?#37716;?#28052;嬪?#23676;负鎬?#37833;冮噸TotalWeight?#32029;鐢埛鎬?#37825;颁负MaxMember?#32029;?#31476;涓猼sung client瀹?#28186;?#38171;堟?#37825;?#29825;句负M2锛?#37714;嗛厤鐨勬鎷?#37922;埛鏁板彲?#20824;?#36127;锛?/p>

MaxMember*(Weight/TotalWeight)

?#28214;瑕佹敞鎰?#38171;?br/> - M2 >= M1
- ?#23266;鍘嬫?#23342;樁娈?code><arrivalphase鍏冪礌?#21412;缃?code>duration鍊?#26473;囧?#24549;紝灏?#27996;?#37832;?#31891;鐢埛50涓?#37922;埛鎸夌収姣?#32457;?50閫熺?#22250;楁椂?#26882;闂达紝鏈?#31891;鍒嗛厤鐢埛鏁板皢灏?#27996;?#37832;?#37832;?#37706;?/p>

鍙?#37832;変竴鍙扮墿?#24714;鏈?#37928;則sung master鍚?#37716;?#37826;?#23534;?/h3>
<clients>
  <client host="localhost" use_controller_vm="true"/>
</clients>

?#30149;鏈?#37911;悊浠?#37832;猴紝涓?#28000;庤?#20636;偣閮藉湪?#31476;鍙?#37832;哄櫒涓婏紝?#28214;瑕?#29825;?#32515;?code>use_controller_vm="true"銆傜浉姣攖sung闆嗙兢?#32029;鍗曚竴鑺傜偣tsung鍚?#37716;?#28751;?#23536;?#32480;鍗曪紝涓?#28000;?#28052;?#38338;?#28051;嶉渶瑕丼SH閫氫俊?#32029;鐩?#37818;?#37712;?#38318;皟鐢?#37510;?/p>

local_launcher([Host],LogDir,Config) ->
    ?LOGF("Start a launcher on the controller beam ~p~n", [Host], ?NOTICE),
    LogDirEnc = encode_filename(LogDir),
    %% set the application spec (read the app file and update some env. var.)
    {ok, {_,_,AppSpec}} = load_app(tsung),
    {value, {env, OldEnv}} = lists:keysearch(env, 1, AppSpec),
    NewEnv = [ {debug_level,?config(debug_level)}, {log_file,LogDirEnc}],
    RepKeyFun = fun(Tuple, List) ->  lists:keyreplace(element(1, Tuple), 1, List, Tuple) end,
    Env = lists:foldl(RepKeyFun, OldEnv, NewEnv),
    NewAppSpec = lists:keyreplace(env, 1, AppSpec, {env, Env}),

    ok = application:load({application, tsung, NewAppSpec}),
    case application:start(tsung) of
        ok ->
            ?LOG("Application started, activate launcher, ~n", ?INFO),
            application:set_env(tsung, debug_level, Config#config.loglevel),
            case Config#config.ports_range of
                {Min, Max} ->
                    application:set_env(tsung, cport_min, Min),
                    application:set_env(tsung, cport_max, Max);
                undefined ->
                    ""
            end,
            ts_launcher_static:launch({node(), Host, []}),
            ts_launcher:launch({node(), Host, [], Config#config.seed}),
            1 ;
        {error, Reason} ->
            ?LOGF("Can't start launcher application (reason: ~p) ! Aborting!~n",[Reason],?EMERG),
            {error, Reason}
    end.

鐢埛鐢?#37812;?#37818;?#37714;?/h3>

鐢埛鍜?#28028;?#29831;?#37818;?#37714;?/h4>

姣忎竴涓猼sung client杩?#29723;岀潃?#31476;涓?code>ts_launch/ts_launch_static鏈?#37734;?#23049;?#37712;屾?#28513;?#32029;鎺屾帶?#31891;绔?#22959;?#37815;?#37922;埛鐢?#37812;?#37724;?#28028;?#29831;?#37818;?#37714;?#37510;?/p>

  • 鍚戜?#26127;?#20636;偣ts_config_server璇锋眰闅?#28766;?#27996;庡綋鍓?#28000;?#37832;鸿?#20636;偣鐨?#28028;?#29831;濅俊鎭?/li>
  • 鍚?#37716;?#22959;?#37815;熺粓绔?#37922;埛ts_client
  • 鎺?#37714;?#28051;嬩竴涓?#22959;?#37815;熺粓绔?#37922;埛ts_client?#28214;瑕佺瓑寰呮椂闂达紝涔?#37828;?#37818;?#37714;?#28000;?#37832;虹敤?#22491;鐢?#37812;?#38315;熷害
  • 鎵?#29723;?#37828;?#37722;渶瑕?#37714;?#37817;?#37714;版柊鐨?#38339;?#23048;?#28028;?#29831;?/li>
  • 鎺?#37714;?#22959;?#37815;熺粓绔?#37922;埛鏄?#37722;?#23480;?#32513;忚揪鍒?#27996;?#29825;?#32515;?#37928;?code>maxusers涓?#38340;?
    • 鍒?#28051;?#38340;愶紝鑷韩浣?#37723;?#28729;?#37812;愶紝鍏?#38338;?#38007;韩
  • ?#31790;鐮佷綅浜?tsung-1.6.0/src/tsung ?#27952;?#32141;涓?/li>

涓?#37832;烘?#22796;収xml?#21412;缃?#37922;?#37812;?#37711;?#28766;鐢埛浜?#37922;?#38315;熺?#22263;紝浠?#37832;烘?#22796;収鑷韩鏉冮噸鍒嗛厤鐨?#38315;熺巼杩?#29723;屽?#26336;嫭鎺?#37714;讹紝杩?#28052;?#37828;?#28000;?#37716;?#37714;?#29785;?#37928;勫叿浣?#37723;堢幇銆?/p>

鐢埛鐢?#37812;?#38315;熷害鎺?#37714;?/h4>

鍦Tsung涓?#37922;埛鐢?#37812;?#38315;熷害绉?#28052;嬩负寮?#25652;紝鏍规嵁鎵?#21412;缃?#37928;刲oad灞炴?#26473;?#29723;岄厤缃?/p>

<load>
    <arrivalphase phase="1" duration="60" unit="minute">
        <users maxnumber="500000" arrivalrate="250" unit="second"></users>
    </arrivalphase>
</load>

鍏?#38335;?#28766;炴?#38171;?/p>

  • interarrival?#32029;鐢?#37812;?#37720;嬫祴鐢埛鐨勬椂闂?#38338;撮殧
  • arrivalrate锛?#37719;?#28003;嶆椂闂村唴鐢?#37812;?#37922;埛鏁伴噺
  • 涓?#38000;?#37832;?#31891;閮?#28028;氳杞?#37817;负鐢?#37812;?#37922;埛寮?#25652;?#32495;?#37825;板?#37828;?.25
  • 杩?#28051;?#37828;?#37804;?#37928;勫己搴?#37706;硷紝浣嗛渶瑕佽鍚?#28051;猼sung client鍒?#29785;?/li>
parse(Element = #xmlElement{name=users, attributes=Attrs},
      Conf = #config{arrivalphases=[CurA | AList]}) ->

    Max = getAttr(integer,Attrs, maxnumber, infinity),
    ?LOGF("Maximum number of users ~p~n",[Max],?INFO),

    Unit  = getAttr(string,Attrs, unit, "second"),
    Intensity = case {getAttr(float_or_integer,Attrs, interarrival),
                      getAttr(float_or_integer,Attrs, arrivalrate)  } of
                    {[],[]} ->
                        exit({invalid_xml,"arrival or interarrival must be specified"});
                    {[], Rate}  when Rate > 0 ->
                        Rate / to_milliseconds(Unit,1);
                    {InterArrival,[]} when InterArrival > 0 ->
                        1/to_milliseconds(Unit,InterArrival);
                    {_Value, _Value2} ->
                        exit({invalid_xml,"arrivalrate and interarrival can't be defined simultaneously"})
                end,
    lists:foldl(fun parse/2,
        Conf#config{arrivalphases = [CurA#arrivalphase{maxnumber = Max,
                                                        intensity=Intensity}
                               |AList]},
                Element#xmlElement.content);

tsung_controller瀵规?#24526;竴涓猼sung client鐢?#37812;?#37922;埛寮?#25652;?#37714;?#29785;负 ClientIntensity = PhaseIntensity * Weight / TotalWeight?#32029;鑰?code>1000 * ClientIntensity灏?#37828;?#37828;?#29831;?#37928;勬瘡绉?#37922;?#37812;?#37922;埛閫熺?#22247;?#37510;?/p>

get_client_cfg(Arrival=#arrivalphase{duration = Duration,
                                     intensity= PhaseIntensity,
                                     curnumber= CurNumber,
                                     maxnumber= MaxNumber },
               {TotalWeight,Client,IsLast} ) ->
    Weight = Client#client.weight,
    ClientIntensity = PhaseIntensity * Weight / TotalWeight,
    NUsers = round(case MaxNumber of
                       infinity -> %% only use the duration to set the number of users
                           Duration * ClientIntensity;
                       _ ->
                           TmpMax = case {IsLast,CurNumber == MaxNumber} of
                                        {true,_} ->
                                            MaxNumber-CurNumber;
                                        {false,true} ->
                                            0;
                                        {false,false} ->
                                            lists:max([1,trunc(MaxNumber * Weight / TotalWeight)])
                                    end,
                           lists:min([TmpMax, Duration*ClientIntensity])
                   end),
    ?LOGF("New arrival phase ~p for client ~p (last ? ~p): will start ~p users~n",
          [Arrival#arrivalphase.phase,Client#client.host, IsLast,NUsers],?NOTICE),
    {Arrival#arrivalphase{curnumber=CurNumber+NUsers}, {ClientIntensity, NUsers, Duration}}.

鍓嶉潰璁?#37714;?#23011;忎竴涓猼sung client琚?#37714;嗛厤鐢埛鏁板叕寮忎负锛?code>min(Duration * ClientIntensity, MaxNumber * Weight / TotalWeight)锛?/p>

  • ?#20265;鍏嶆?#27996;?#37825;?#29906;?#37713;洪檺鍒?/li>
  • 闃?#23048;Phase鎸佺画?#26882;闀?#37813;浜?#37922;?#37922;埛鏁板拰tsung client鍒嗛厤鐢埛鏁?#28051;嶈嚦浜?#27996;?#37922;?#37712;茬?#20362;紝?#31476;绉嶅?#24538;皟绛栫暐

鍐?#37930;嬩竴涓媗aunch鍔犺浇?#31476;涓粓绔?#37922;埛?#26882;?#32029;浼?#38007;?#37716;?#37837;规嵁?#32139;鍓?#37714;嗛厤鐢埛鐢?#37812;?#37720;嬪姏绯?#37825;拌幏寰?code>ts_stats:exponential(Intensity)涓嬩竴涓?#22959;?#37815;?#37922;埛浜?#37922;?#32475;?#23536;?#37922;?#37812;?#37928;?#37832;闀挎椂闂达紝鍗?#28003;嶄负姣?#32457;?#37510;?/p>

do_launch({Intensity, MyHostName, PhaseId})->
    %%Get one client
    %%set the profile of the client
    case catch ts_config_server:get_next_session({MyHostName, PhaseId} ) of
        {'EXIT', {timeout, _ }} ->
            ?LOG("get_next_session failed (timeout), skip this session !~n", ?ERR),
            ts_mon:add({ count, error_next_session }),
            error;
        {ok, Session} ->
            ts_client_sup:start_child(Session),
            X = ts_stats:exponential(Intensity),
            ?DebugF("client launched, wait ~p ms before launching next client~n",[X]),
            {ok, X};
        Error ->
            ?LOGF("get_next_session failed for unexpected reason [~p], abort !~n", [Error],?ERR),
            ts_mon:add({ count, error_next_session }),
            exit(shutdown)
    end.

ts_stats:exponential閫昏緫寮?#37711;?#27996;嗘寚鏁?#29825;?#32480;?#38171;?/p>

exponential(Param) ->
    -math:log(random:uniform())/Param.

缁?#32513;?#23536;涓?#37930;嬪惂?#32029;闅愯棌浜嗛儴鍒嗘棤鍏?#28000;?#37934;?#38171;?/p>

launcher(timeout, State=#launcher{nusers        = Users,
                                  phase_nusers  = PhaseUsers,
                                  phases        = Phases,
                                  phase_id      = Id,
                                  started_users = Started,
                                  intensity     = Intensity}) ->
    BeforeLaunch = ?NOW,
    case do_launch({Intensity,State#launcher.myhostname,Id}) of
        {ok, Wait} ->
                            ...
                        {continue} ->
                            Now=?NOW,
                            LaunchDuration = ts_utils:elapsed(BeforeLaunch, Now),
                            %% to keep the rate of new users as expected,
                            %% remove the time to launch a client to the next
                            %% wait.
                            NewWait = case Wait > LaunchDuration of
                                          true -> trunc(Wait - LaunchDuration);
                                          false -> 0
                                      end,
                            ?DebugF("Real Wait = ~p (was ~p)~n", [NewWait,Wait]),
                            {next_state,launcher,State#launcher{nusers = Users-1, started_users=Started+1} , NewWait}
                            ...
        error ->
            % retry with the next user, wait randomly a few msec
            RndWait = random:uniform(?NEXT_AFTER_FAILED_TIMEOUT),
            {next_state,launcher,State#launcher{nusers = Users-1} , RndWait}
    end.

涓嬩竴涓?#37922;埛鐢?#37812;愰渶瑕佺瓑寰?code>Wait - LaunchDuration姣?#32457;掓椂闂淬?/p>

缁?#37713;轰竴涓?#38322;?#37837;?#37825;版嵁?#32029;鍙?#37832;変竴涓?#28000;?#37832;猴紝?#33503;涓?#37922;埛浜?#37922;?#38315;熷害1绉掍竴涓紝鍏?#27996;?#37922;?0涓?#37922;埛锛?/p>

<load>
    <arrivalphase phase="1" duration="50" unit="minute">
        <users maxnumber="10" interarrival="1" unit="second"/>
    </arrivalphase>
</load>

閲?#38342;嗘棩?#32340;閮?#37714;嗭紝璁板綍浜?code>Wait?#26882;闂村硷紝鍏?#28729;炴?#28003;撴椂闂?#26473;橀渶瑕?#37716;?#28051;?code>LaunchDuration锛堣櫧?#21159;杩?#28051;?#37706;?#23536;堝皬锛?#38171;?/p>

ts_launcher:(7:<0.63.0>) client launched, wait 678.5670934164623 ms before launching next client
ts_launcher:(7:<0.63.0>) client launched, wait 810.2982455546687 ms before launching next client
ts_launcher:(7:<0.63.0>) client launched, wait 1469.2208436232288 ms before launching next client
ts_launcher:(7:<0.63.0>) client launched, wait 986.7202548184069 ms before launching next client
ts_launcher:(7:<0.63.0>) client launched, wait 180.7484423006169 ms before launching next client
ts_launcher:(7:<0.63.0>) client launched, wait 1018.9190235965457 ms before launching next client
ts_launcher:(7:<0.63.0>) client launched, wait 1685.0156394273606 ms before launching next client
ts_launcher:(7:<0.63.0>) client launched, wait 408.53992361334065 ms before launching next client
ts_launcher:(7:<0.63.0>) client launched, wait 204.40900996137086 ms before launching next client
ts_launcher:(7:<0.63.0>) client launched, wait 804.6040921461512 ms before launching next client

鎬?#28003;撴潵璇达紝姣忎竴涓?#37922;埛鐢?#37812;?#38338;撮殧闂?#28051;?#37828;浐瀹氬硷紝鏄竴涓?#28598;害鍊硷紝鏈夊亸宸紝浣嗘帴杩戜簬?#27952;鏍?#29825;?#28729;?#38171;?000姣?#32457;?#37922;?#37812;愪竴涓?#37922;埛鏍囧噯闂撮殧锛?#37510;?/p>

鎵?#29723;屾鎷熺粓绔?#37922;埛浼?#29831;?#23092;?#32459;?/h3>

鍏?#27996;?#28028;?#29831;?#37928;?#29831;?#37828;?#38171;?/p>

  • ?#31476;涓猻ession鍏冪礌涓?#37928;勫畾涔変竴绯?#37714;?#29831;锋眰-鍝嶅簲绛?#27996;?#27996;?#29723;屼负绉?#28052;嬩负?#31476;娆?#28729;?#37825;?#28028;?#29831;?/li>
  • ?#31476;涓?#22959;?#37815;?#37922;埛?#28214;瑕佹墽琛屼竴娆?#28729;?#37825;?#28028;?#29831;濓紝?#21159;鍚?#37922;熷?#34249;懆鏈?#28729;?#37812;愶紝?#21159;鍚?#32513;?#37833;?/li>

妯?#37815;熺粓绔?#37922;埛妯潡鏄?code>ts_client锛堢姸鎬?#37832;?#38171;夛紝鎸?#26462;藉湪ts_client_sup涓嬶紝鐢?code>ts_launcher/ts_launcher_static?#30367;鐢?code>ts_client_sup:start_child(Session)鍚?#37716;紝鏄?#37720;嬫祴浠?#37716;?#37928;?#37832;?#31891;鎵?#29723;岃咃紝鎵?#37718;?#27996;?#37813;鏈夎?#24533;疮宸?#37928;勬椿锛?/p>

  • 鎵鏈?#28051;嬩竴姝渶瑕佹墽琛?#37928;?#28028;?#29831;?#37816;?#28000;?#38318;介渶瑕?#37722;戜富鏈?#37928;?code>ts_config_server璇锋眰
  • 鎵?#29723;?#28028;?#29831;?#37816;?#28000;?/li>
  • 鍏?#28003;?#37719;?#29825;皟鐢?#37929;?#25652;?#37719;?#29825;?#37819;?#28000;讹紝姣斿?#20480;s_mqtt缁勮?#21612;細璇濇?#22559;伅
  • 寤虹珛缃戠粶Socket杩?#37818;紝灏佽?#21612;紬澶?#32515;戠粶閫?#38316;?/li>
  • 鍙?#38315;?#29831;?#23033;傛?#29256;嵁?#32029;澶勭?#21975;?#23941;簲
  • 璁板綍?#33503;鍙?#38315;?#37929;戞帶鏁版嵁鍜屾棩?#32340;

ts_client锟?/p>

灏?#32513;?/h3>

绠鍗曟?#23815;悊涓?#28000;?#28052;?#38338;村惎鍔?#37826;?#23534;忥紝浠?#37832;?#37825;伴噺鍒嗛厤绛栫暐?#32029;浠?#37711;?#28003;?#37720;嬫祴浠?#37716;?#28641;備綍鍦?#28000;?#37832;?#28051;?#37714;嗛?#23941;拰杩?#29723;?#32475;?#37712;?#28729;?#37510;?/p>

nieyong 2016-07-25 14:02 鍙?#29723;?#29831;?#29825;?/a>
]]>Tsung绗?#29825;?#28052;?#28051;?#28000;庢鍨嬬瘒http://www.8634070.com/yongboy/archive/2016/07/23/431294.htmlnieyongnieyongSat, 23 Jul 2016 03:56:00 GMThttp://www.8634070.com/yongboy/archive/2016/07/23/431294.htmlhttp://www.8634070.com/yongboy/comments/431294.htmlhttp://www.8634070.com/yongboy/archive/2016/07/23/431294.html#Feedback0http://www.8634070.com/yongboy/comments/commentRss/431294.htmlhttp://www.8634070.com/yongboy/services/trackbacks/431294.html鍓嶈

鏈瘒璁?#29785;Tsung澶?#38007;村?#29115;兘缁?#37812;?#37510;佺粨鏋勶紝浠?#37721;?#28051;?#28000;庢鍨嬶紝浠?#28186;?#37804;?#28003;?#28051;?#37818;屾彙銆?/p>

鎬?#28003;?#32513;?#37812;?/h3>

锟?/p>

tsung_controller 鍜?tsung 杩?#28051;?#28051;?#22959;潡?#32029;璐?#29840;?#37714;嗗竷寮忓?#23339;祴鐨?#37837;稿績鍔熻兘銆?/p>

浠?#37934;佺粍鎴?/h4>

浠?#28000;?#37934;佸?#20635;姊崇?#21973;竴涓媡sung椤圭洰鍔熻兘缁?#37812;?#32513;?#37835;勶紝渚?#27996;庝竴?#27952;浜嗙劧?#32029;鏂?#28186;?#37929;?#37818;?#32497;?#23534;?#37510;?/p>

tsung_struct锟?/p>

涓?#28000;庢鍨嬩竴瑙?/h3>

璁?#28729;氱幆澧冧负鍒嗗竷寮忕幆澧?#28051;婽sung闆嗙兢?#32029;涓嬮潰绠鍗曟?#23815;?#21973;竴涓?#28051;?#37510;佷粠鑺傜偣鍚?#37716;?#23092;?#32459;?#37510;?/p>

tsung_master_slave锟?/p>

娴?#32459;嬪鑷?#29831;?#37828;?#38171;?/p>

  • 涓昏?#20636;偣锛tsung_controller锛?#38315;?#26473;SSH鎴?#37711;?#28729;?#26473;?#32459;嬬粓绔?#38171;?#37722;庨潰浼?#29825;?#37714;?#37823;嶄綔?#27967;?#36127;杞婚噺鐨勫?#23677;叏鏇?#28000;SSH鏂?#23534;?#38171;?#26473;?#37818;?#37714;?#28000;?#37832;?#37716;?#37731;?#37722;?#37716;tsung浠庤?#20636;偣杩?#29723;屾椂?#24134;澧?/li>
  • 涓昏?#20636;偣RPC鎵归噺鍚?#37716;tsung client杩?#32459;?/li>
  • 涓昏?#20636;偣?#36127;姣忎竴涓?#28000;庤?#20636;偣鍚?#37716;?#28028;?#29831;?#37929;戞帶?#32029;鎺?#37714;?#28028;?#29831;?#38315;熷害?#32029;寮鍚痶s_client妯?#37815;熺粓绔?/li>
  • 浠庤?#20636;偣璇锋眰涓昏?#20636;偣鍏?#28003;?#28051;?#37716;?#26473;?#32459;嬶紝?#24143;鍙?#28028;?#29831;?#37816;?#28000;?#28000;?#37721;?#28028;?#29831;?#37711;?#28003;?#37712;?#28729;?/li>
  • 浠庤?#20636;偣寤虹?#23338;?#25198;洰鏍囧?#23339;祴鏈?#37716;?#37731;?#37928;凷OCKET缃戠粶杩?#37818;紝寮濮?#28028;?#29831;?/li>
  • 涓昏?#20636;偣鍙?#28000;?#38315;?#26473;SSH/鍏?#28729;冪粓绔?#37826;?#23534;?#26473;?#37818;?#37714;扮洰鏍囧?#23339;祴鏈?#37716;?#37731;紝鍚?#37716;?#28000;庤?#20636;偣?#32029;?#21159;鍚庢敹闆?#37825;版嵁锛堝彲閫夛紝鍏?#28003;?#32513;嗚?#20646;紝鍚?#32513;?#37826;?#28699;?#28028;?#29825;?#37714;?#38171;?/li>

杩?#32457;嶆鍨?#28051;?#38171;?/p>

  • 鍏?#28766;涓?#37837;?#37818;?#37714;?#22959;?#37815;熺粓绔?#37922;埛鐢?#37812;?#37804;婚?#24531;拰鐢?#37812;?#38315;熷害
  • 涓昏?#20636;偣鍔?#37804;?#32480;悊浠庤?#20636;偣鐢熷?#34249;懆鏈燂紝浠?#37922;?#37714;版?#20249;紝?#33503;涓?#37818;屾彙?#28483;鎵鏈変細璇?#32513;嗚?#20646;紝鍏?#28766;鎺屾帶
  • 浠庤?#20636;偣寰?#26462;伙紝鎵鏈夐渶瑕?#37928;?#28028;?#29831;?#37816;?#28000;紝閮藉繀椤?#29831;锋眰涓昏?#20636;偣?#24143;寰?/li>

涓?#28000;?#28052;?#38338;?#27996;?#27996;?#23092;?#32459;?/h4>

涓嬮潰?#31476;寮?#37733;?#32480;鍗曡鏄?#27996;?#28051;?#28000;?#28052;?#38338;?#37837;稿績妯潡浜?#27996;?#23092;?#32459;嬶紝?#27367;?#21159;绮?#37923;紝鏍稿?#20906;偣涔?#32480;?#37828;秹鍙?#37714;?#27996;?#37510;?/p>

tsung_slave_flow_detai锟?/p>

鍚庨潰浼?#28725;瑰叿浣?#37719;?#29825;?#38318;?#37714;?#37832;夋洿?#36127;璇?#32513;?#29825;?#26473;?#37510;?/p>

?#31476;娆?#37720;嬫?#23338;洖璇?#38171;ts_client锛?#23480;綔娴?#32459;?/h4>

鍏?#28729;?#37828;?#37813;?#37818;?#28051;婁竴涓?#23092;?#32459;嬪?#25733;紝宸?#32513;?#37722;?#37716;?#27996;嗕竴涓猼s_client妯潡?#32029;鍗虫墽琛屼竴涓?#28729;?#37825;?#37922;熷?#34249;懆鏈?#28028;?#29831;?#22959;?#37815;熺粓绔?#37510;?#28729;?#37928;勫紑鍚?#28186;?#29863;?#27996;嶵sung Controller鍚?#37716;ts_launch/ts_launch_static妯潡銆?/p>

澶?#38007;存祦绋嬪?#24807;涓?#38171;?/p>

ts_client_structure锟?/p>

浼?#29831;?#28000;涔堟椂鍊?#32513;?#37833;?/h4>
  • 閽堝浠庤?#20636;偣涓婏紝锛堜竴涓粓绔?#37922;埛鐨?#38171;変竴娆?#28729;?#37825;?#28028;?#29831;?#38171;session锛?#38171;?
    • 璇锋眰涓昏?#20636;偣ts_config妯潡?#32029;?#24143;鍙?#28028;?#29831;漇ession?#20426;鎭紝鍖?#37722;竴娆?#28028;?#29831;濋渶瑕?#28729;?#37812;?#28000;?#37716;?#37804;?#37825;Count
    • 浠庤?#20636;偣ts_client 姣?#37813;?#29723;屼竴娆?#27996;?#28000;讹紝浠?#37716;?#37804;?#37825;Count鍑?
    • ?#32139;Count鍊间负0?#26882;?#32029;璇?#37828;?#28000;?#37716;?#37813;?#29723;?#28729;屾?#26346;紝ts_client鐢熷?#34249;懆鏈熷婊紝?#31476;娆?#28729;?#37825;?#28028;?#29831;?#32513;?#37833;?/li>
  • 浠庤?#20636;偣鎵鍒嗛厤鐨?#37813;鏈変細璇?#38318;?#32513;?#37833;?#27996;嗭紝琛?#32448;?#28000;庤?#20636;偣鐢熷?#34249;懆鏈?#28052;?#28028;?#32513;?#37833;?/li>
  • 涓昏?#20636;偣鎺?#37714;?#37928;?#37813;鏈?#28000;庤?#20636;偣閮?#32513;?#37833;?#27996;嗭紝鍗虫墍鏈変細璇?#38318;戒竴?#31476;瀹?#37812;愶紝閭?#28052;?#37825;?#28003;?#37720;嬫祴涔?#32513;?#37833;?#27996;嗭紝鏁?#28051;?#37720;嬫?#23339;祦绋?#32513;?#37833;?/li>

灏?#32513;?/h3>

?#29056;浜嶦rlang澶?#37922;?#37714;嗗竷寮忓熀?#27932;鏀?#37816;侊紝浠庤?#20636;偣鐨勭?#29112;瀛?#27996;?#28729;屽叏鍙桾sung涓昏?#20636;偣鐨勬帶鍒讹紝鎸夐渶鍒涘缓?#32029;浠?#37716;?#28729;?#37812;?#32513;?#37833;燂紝涓?#28000;?#37719;忚皟琛?#27996;戞?#20345;按鑸?#26916;虹晠銆?/p>

鍡紝鍚庨潰灏?#28000;?#32513;?#28051;?#28000;?#28729;?#37916;?#37928;勪竴浜?#32513;嗚妭銆?/p>

nieyong 2016-07-23 11:56 鍙?#29723;?#29831;?#29825;?/a>
]]>Tsung绗?#29825;?#28052;嬪紑?#30226;http://www.8634070.com/yongboy/archive/2016/07/22/431291.htmlnieyongnieyongFri, 22 Jul 2016 07:36:00 GMThttp://www.8634070.com/yongboy/archive/2016/07/22/431291.htmlhttp://www.8634070.com/yongboy/comments/431291.htmlhttp://www.8634070.com/yongboy/archive/2016/07/22/431291.html#Feedback1http://www.8634070.com/yongboy/comments/commentRss/431291.htmlhttp://www.8634070.com/yongboy/services/trackbacks/431291.html鍓嶈

鏈夋?#23341;瘯椹?#37716;?#37928;勫紑鍙戞寮忥紝?#27952;鐨勫湪浜庣?#32346;涓?#37716;眰?#28528;鍔熻兘鏄?#37713;?#32429;?#37928;勶紝姣忎竴娆?#37826;板銆佷慨鏀?#32475;?#37716;綔纭繚閮?#28051;?#28028;氬?#21342;搷鍒?#37916;?#37832;?#37716;熻兘銆?#37716;熻兘寮鍙?#28729;?#37812;愪?#21997;紝?#28214;瑕?#38318;?#32515;?#37714;扮嚎涓婏紝绯?#32513;?#38003;藉?#29112;壙杞藉澶?#37928;勭敤?#22491;閲忓憿?#32029;杩欐椂鍊?#28751;遍渶瑕佸?#37716;?#27996;庢?#38003;藉?#23339;?#23350;紝涔熺涔嬩负鍘嬪姏娴嬭?#26346;紝鐣?#28729;?#32495;?#32513;?#38003;藉?#29112;壙杞?#37711;?#28003;?#28729;归噺涓?#38340;愶紝浠?#28729;瑰簲瀵?#28051;?#37716;?#37928;?#26473;愯惀?#28214;瑕侊紝鎵?#28729;规垨缂?#28729;癸紝?#32318;涓?#37832;?#25652;?#37510;?/p>

宸?#23046;插?#21227;叾浜嬶紝蹇?#37711;堝埄鍏?#37731;?#37510;傛?#23678;彙?#31476;绉嶅?#23339;祴宸?#37711;凤紝?#33503;鍒?#28729;炲簲鐢?#37714;?#28729;?#29882;电幆澧?#28051;紝?#33503;浠?#23005;?#28051;?#37826;?#26473;?#28000;紝鍘嬪姏娴嬭瘯椹?#37716;?#37818;?#37716;?#37813;寮鍙?#37722;?#32468;?#25652;?#37922;?#28598;勭?#21976;兘閫愭笎瀹屽杽銆?/p>

?#27952;鍓?#37812;?#37908;?#37928;勬敮鎸佹敮?#23508;TCP銆丠TTP绛?#26473;?#37818;?#38315;?#38316;?#37928;勫?#23339;祴宸?#37711;?#28051;?#28751;戯紝浠?#37715;嶆帴瑙?#26473;嘇pache JMeter?#32029;鍚庨潰鍙堟帴瑙?#26473;?a href="tsung.erlang-projects.org">Tsung?#32029;?#27932;?#36127;鍦?#28729;?#38340;呯幆澧?#28051;?#28003;?#37922;?#23011;旇緝澶氾紝鏀?#37816;佷?#26495;瘜鐨?#28051;?#37716;?#37734;烘櫙瀹?#28052;夛紝?#33503;涓?#37721;?#37813;?#28766;曟?#23534;猴紝?#27932;姝Tsung寮?#37716;?#37818;?#38013;愪箣銆?/p>

?#36127;浠涔?#29781;?#38315;夋嫨Tsung

  • ?#29056;浜嶦rlang?#32029;?#33503;鍙?#28598;勭?#21976;?#38003;藉?#26020;紝鍙?#28000;?#22959;?#37815;?#29906;?#28598;熷娴烽噺鐢埛?#32029;鍙?#29781;佷綘鏈?#29906;?#28598;熷鐨?#37832;哄櫒
  • 鍙?#37929;?#27996;嶦rlang?#32029;澶劧鏀寔鍒嗗竷寮忥紝寰堟?#25577;鐨?#26473;?#29723;屽湪?#31476;涓?#38342;嗙兢涓?/li>
  • 鏀寔鍗?#29825;?#28028;?#28598;?WebDAV/WebScoket/MQTT/MySQL/PGSQL/Shell/AQMP/JABBER/XMPP/LDAP 绛?/li>
  • 浼犺緭閫?#38316;撴敮?#23508; TCP/UDP/SSL?#32029;鏇村?#26334;?#20635;敮?#23508;IPv4/IPv6
  • 鏀寔鍗?#37832;虹粦瀹?#28598;?#28051;狪P锛氭棤璁?#37828;?#38095;氭?#28910;P?#32029;杩?#37828;?#37911;悊缃?#37719;?#32513;?#28729;欼P?#32029;鍙?#28000;?#32464;佺?#26449;崟鏈虹鍙?5535鐨?#38340;?#37714;讹紝鎵?#28766;?#28751;藉彲鑳藉鐨勭?#25120;粶杩?#37818;?#37713;?#37721;?#37734;板潃
  • 鏀寔鐩戞帶琚?#37720;嬫祴鐨?#37832;?#37716;?#37731;紝閫?#26473;Erlang Agent/SNMP/Munin
  • 鍘嬫祴缁嗚妭XML鍙厤缃紝杩?#37828;竴涓?#28729;屽叏?#29056;浜庢儏鏅?#37928;勫?#23338;姏娴嬭?#26337;?#23676;负娓?#37719;曪紝渚?#29863;?#27996;?#28003;?#37928;勬兂?#34180;?#32029;鍛堢幇瀹?#37825;?#28051;?#37716;?#37928;勮杈?
    • 鍦烘櫙鍙?#28000;?#37828;?#37716;?#37804;?#37928;勶紝?#28533;鑷?#27996;?#37826;?#28000;?#37510;佷唬鐮佹垨鑰?#37832;?#37716;?#37731;?#37725;嶅簲鍙?#28000;?#37835;?#37812;?#28051;嬩竴涓?#29831;锋眰鐨勫?#20635;暟?#32029;杩?#28751;?#37828;?#37721;?#32514;?#32459;?#37928;?#29831;锋眰鍢?/li>
    • 琛屼负鍙?#28000;?#23075;锋惌?#32029;鍥?#29831;?#37721;?#28000;?#37734;?#28051;?#37722;屽?#28888;櫙涓紝鎸夌収涓?#37722;?#37928;勮?#23676;负瑙勮寖鍚?#38007;?#39582;?#29723;?#26473;?#29723;?/li>
    • 浼戠?#29381;紝鎴?#37830;傚仠鏈?#37714;讹紝鏄?#37721;?#28000;殢鏈?#37928;勶紝浜?/li>
    • 鍘嬫祴鐢埛浜?#37922;?#37826;?#23534;忥紝鍔?#37804;?#37832;夊簭鎴栭殢鏈?/li>

鎬?#28052;嬶紝Tsung鏄竴娆?#23534;?#31790;鐨勯珮鎬兘鍒嗗竷寮忓?#23338;姏娴嬭瘯宸?#37711;凤紝鏀寔鍙?#32514;?#32459;?#37928;勬儏鏅?#37718;?#23092;嬭瘯鏂规?#22572;紝瑕?#37722;戝?#25118;尌瀹?#37928;勭?#35268;紝渚?#29863;?#27996;?#27996;?#28000;?#37928;勬兂?#34180;鍔?#37724;屽垱閫犳?#37510;?/p>

?#36127;浠涔?#29781;佸?#23338;姏娴嬭瘯椹?#37716;?#37723;?锛?/h3>

杞?#28000;?绯?#32513;熸灦鏋勫線寰?#28483;鐪?#27996;庢?#28003;?#32513;?#37835;勶紝杩?#28051;?#37721;?#28000;?#37828;竴涓?#38315;愭笎瀹屽杽鐨?#26473;?#32459;?#37510;?#26473;?#32457;嶈嚜鎴?#37928;?#28051;?#37826;?#28729;屽杽鐨勯鍔?#23536;寰?#28533;鑷?#27996;?#28729;?#29882;?#37510;佺嚎涓?#38000;?#26976;?#37510;傝屽?#23338;姏娴嬭瘯鍙?#28000;?#37819;愪?#28055;竴绉嶆帹鍔紝灏藉績灏?#37716;涙闇茬潃鏋?#37835;勫湪鎬兘瀹归噺瀛?#37734;?#37928;勪竴浜?#28051;嶈冻鍜岀?#27946;?#20964;紝?#32318;浣跨潃鍚戠潃鏇村鐨?#37826;?#37722;戝?#25117;睍銆?/p>

绯?#32513;?#37928;?#37835;勫缓渚?#29863;?#27996;?#37711;?#28003;?#37721;?#28051;?#37813;?#29723;?#37928;?#27996;猴紝灏?#32480;?#37828;竴?#20834;璧勬繁鐨勫伐绋嬪?#22572;紝涓?#37716;?#28051;?#23011;忎竴娆?#37716;熻兘鐨勫揩閫熸洿杩?#37510;佷换?#32141;?#32148;鍦?#28766;閮?#28103;?#37824;?#38318;?#28028;?#28725;?#38007;村?#21342;搷銆佹?#26663;鏁?#28003;撴兘?#32029;杩?#28751;?#37828;?#27996;?#28000;父璇?#37928;?鈥?a href="https://zh.wikipedia.org/zh/%E8%9D%B4%E8%9D%B6%E6%95%88%E5%BA%94">铦磋澏鏁堝簲鈥滐紝鐗典竴鍙?#38000;屽姩鍏韩銆?/p>

濡備綍?#24385;鏃?#37808;熺煡?#33503;涓旀彁鏃?#28103;?#28598;嶏紝杩?#28751;遍渶瑕佸?#23338;姏娴嬭瘯鐨勯鍔紝?#33503;涓斿?#23338;姏娴嬭瘯搴旇鎴愪负?#31476;涓父瑙勫寲鐨勪?#23341;?#23683;?#23676;负?#32029;鏃父鍖?#37928;勫姩?#32148;銆?#37734;?#23011;忎竴娆?#28103;?#37824;?#28052;嬪悗?#32029;閮?#29781;?#26473;囦竴杞?#37928;勫?#23339;祴鐨勭鍘?#28052;嬪悗?#32029;鎻愪?#28056;綋鍓?#37722;?#32468;?#25652;?#37922;?#28598;勭悊鐨勬兘銆?#28729;归噺绛?#37711;?#28003;撴寚鏍囷紝鐢?#27996;庢?#22247;鍚?#32513;?#28051;?#37716;?#28051;婄嚎涓?#37716;?#37928;勫紑灞?#37510;?/p>

瀹?#38340;?#37823;嶄綔涓?#37928;勫缓璁?/h3>

鍦竴鑸?#27996;?#38001;?#32515;?#37711;?#37721;革紝?#31476;鑸嚎涓?#32459;嬪簭淇?#37824;?#37722;?#28052;嬪悗?#32029;?#28214;瑕佺粡杩嘠A鍥槦/閮?#38338;?#37711;?#38318;?#37716;?#38003;藉?#28850;綊銆佹牎楠?#28052;嬪悗鎵嶈?#34249;涓婄嚎?#32029;寰寰?#24049;灏戝?#23339;?#23340;幆鑺傦紝?#27932;?#36127;浠?濂?#28000;苟涓嶄繚璇佺郴缁熷?#21229;?#21976;?#38003;藉拰瀹归噺鏄?#37722;?#37805;?#37718;栵紝绯?#32513;?#37928;勬?#38003;藉?#34425;?#23338;湪绯?#32513;熸?#28003;?#37928;勫?#29115;兘涓婏紝濡備綍?#20265;鍏嶅湪鎬兘涓?#37713;虹幇鈥?#37911;典竴鍙?#38000;屽姩鍏韩鈥滐紝?#32531;璁?#37832;夋潯浠?#37928;凲A鍚?#28699;?鍥槦鑰?#38095;戝鍔犳?#38003;藉?#23339;?#23340;幆鑺傦紝鍔熻兘 + 鎬?#38003;藉?#23684;?#23941;?#28850;?#25502;紝淇?#37824;瑰?#21342;搷?#20579;娓?#37829;?#37510;?#38315;?#37828;?#37718;?#37510;?/p>

绗?#29825;板垪琛?/h3>

鏈?#32495;?#37714;?#32471;?#29825;帮紝?#29056;浜巘sung-1.6.0?#31790;鐮?#37737;虹涓?#37714;?#37835;愶紝杩?#29723;岀幆澧冧负Linux Centos 6銆?/p>

绗?#29825;板垪琛?#38171;?/p>

  1. Tsung绗?#29825;?#28052;?#28051;?#28000;庢鍨嬬瘒
  2. Tsung绗?#29825;?#28052;?#28051;?#28000;庤?#21228;簮鍗忚?#20906;瘒
  3. Tsung绗?#29825;?#28052;嬪?#23339;祴绔?#29863;勬簮闄?#37714;剁瘒
  4. Tsung绗?#29825;?#28052;嬪垎甯?#23534;?#28583;?#23534;鸿烦鍑SSH缇佺?#23108;瘒
  5. Tsung绗?#29825;?#28052;婭P鐩?#26473;炴敮鎸佺瘒
  6. Tsung绗?#29825;?#28052;?#37929;戞帶鏁版嵁鏀?#38342;嗙瘒
  7. Tsung绗?#29825;?#28052;嬫彃浠剁紪鍐欑瘒
  8. Tsung绗?#29825;?#28052;?00涓?#37922;埛鍘嬫?#23339;墽琛屾楠瘒
  9. Tsung绗?#29825;?#28052;婭P鍦板潃鍜?#32468;?#37721;?#38340;?#37714;剁?#20346;?#23544;瘒

?#36127;浜?#37826;?#28186;跨悊瑙紝?#31476;浜?#37922;?#29831;嶈鏄?#38171;?/p>

  • 涓昏?#20636;偣?#32029;涔熺涔嬩负Master Node?#32029;鎸?#37928;?#37828;?#26473;?#29723;宼sung_controller鐨勫簲鐢?#37832;?#37716;?#28729;?#28186;嬶紝杩?#29723;宼sung鍚?#37716;?#25652;?#37922;?#38007;?#37716;?#27996;?#37922;?#37413;渢sung_controller@鏈哄櫒鍚?IP鈥?#38010;傜偣鍚?#32457;帮紝?#31476;鑸?#28003;?#37922;?#26473;Erlang鐨勫悓瀛?#28028;?#23536;?#37828;庣櫧
  • 浠庤?#20636;偣?#32029;鍗硉sung client搴?#37922;?#28729;?#28186;嬶紝瀵瑰簲 tsung/src/tsung 椤圭洰浠?#37934;侊紝鐢眛sung_controller涓昏?#20636;偣鎺?#37714;?#37722;?#37716;?#37510;?#37711;?#38338;?#37510;佷换鍔?#37714;嗛厤绛?/li>

灏?#32513;?/h3>

鍙?#28051;庝竴涓?#28729;炴椂鎬?#27996;?#27996;?#23534;?#37928;?#26916;圭洰?#32029;浠庝竴寮濮嬪崟鏈烘敮鎾戜?#23941;1涓?#37922;埛銆佸?#20914;璇锋眰鍝嶅簲?#26882;闂寸害900姣?#32457;掞紝鍒扮洰鍓嶆贩鍚?#38318;?#32515;?#37928;勫崟鏈烘敮鎾?0涓?#37922;埛銆佸?#20914;?#22247;?#23941;簲?#26882;闂翠负16姣?#32457;掞紝杩?#28051;?#26473;?#32459;?#28051;Tsung涓?#37826;?#37928;勫?#23339;?#23339;帹鍔潃鏋?#37835;?#38315;愭笎绋?#28729;?#37510;佺郴缁熸壙杞?#28729;归噺銆丵PS浼?#37718;?#32475;?#28729;屽叏杈?#37837;?#37510;?#26473;?#37828;竴涓?#37720;嬪姏娴嬭瘯椹?#37716;?#37804;兘鏀?#26473;?#37928;勬祦绋嬶紝姣忎竴姝?#37928;勬敼杩?#38003;藉寰?#37714;版鍚戝?#23945;銆?/p>

杩欎竴绯?#37714;?#32471;?#29825;帮紝鎵璋堟?#31295;績鏄疶sung?#32029;?#26852;璁?#37828;?#29825;?#37933;?#26473;?#37828;?#37824;?#26473;涳紝鏈?#31891;閮?#37828;负浜嗙悊瑙?#37714;?#37731;?#37928;?#37826;规柟?#28528;?#28528;?#32029;鏂?#28186;跨潃?#22684;浜?#28729;?#29882;电幆澧?#28051;紝鍘嬫?#23339;墍甯潵鐨勮兘?#22138;鑳藉?#29116;鍔?#37812;戜滑鐨勭?#23338;簭/鏈?#37716;?#37804;兘?#24385;鍗?#37510;?#32459;?#28729;?#26473;?#29723;岋紝杩?#38000;屾?#26449;鏂?#28186;?#37812;戜滑杩?#29723;?#28729;归噺瑙勫垝銆佺嚎涓?#38318;?#32515;?#32475;?#37510;?/p>

nieyong 2016-07-22 15:36 鍙?#29723;?#29831;?#29825;?/a>
]]>TCP鍗?#29825;?#32514;洪櫡涓?#28729;屽叏璁板綍http://www.8634070.com/yongboy/archive/2015/05/07/424917.htmlnieyongnieyongThu, 07 May 2015 06:56:00 GMThttp://www.8634070.com/yongboy/archive/2015/05/07/424917.htmlhttp://www.8634070.com/yongboy/comments/424917.htmlhttp://www.8634070.com/yongboy/archive/2015/05/07/424917.html#Feedback3http://www.8634070.com/yongboy/comments/commentRss/424917.htmlhttp://www.8634070.com/yongboy/services/trackbacks/424917.html

?#27970;銆?#37715;嶈

TCP鑷?#28000;?974?#21246;琚?#37721;?#37828;?#37713;烘潵涔嬪悗?#32029;鍘?#32513;?0澶氬?#26449;?#25117;?#26346;紝?#27952;鍓?#37812;愪负鏈閲嶈鐨?#27996;?#38001;?#32515;戝?#34425;鍗?#29825;?#37510;傛湁绾跨?#25120;粶?#24134;澧?#28051;嬶紝TCP琛?#37916;?#37928;勫铏庢?#33636;?#30839;紝浣嗗湪绉?#37716;?#27996;?#38001;?#32515;戝?#23680;墿鑱?#32515;戠幆澧?#28051;嬶紝绋?#23536;?#29723;?#37916;板緱鐣?#37832;?#28051;嶈冻銆?/p>

绉?#37716;?#27996;?#38001;?#32515;戠獊鍑虹?#35268;?#28051;?#32459;?#28729;?#38171;氫俊鍙?#28051;?#32459;?#28729;氾紝缃戠粶杩?#37818;?#28051;?#32459;?#28729;?#37510;傝櫧?#21159;?#27952;鍓嶅?#25117;睍鍒?G?#32029;?#22684;鏈虹?#25120;粶甯?#28729;?#37832;夋墍澧?#23534;猴紝浣嗗洜鍏?#23092;?#37716;?#37911;规紝?#20426;鍙?#28052;?#28051;?#37828;?#38317;?#28052;?#32459;?#28729;?#38171;氬闀?#38315;?#37711;?#27996;溅?#32029;鎴?#37820;?#28052;?#37737;庨?#20345;椂?#32029;鎴?#37723;?#26440;?#28051;?#32515;?#28725;嗛?#21976;椂绛夌幆澧冿紝鐜?#28729;炵幆澧?#23536;堝?#23942;潅銆?/p>

浠?#28051;?#29825;?#29825;哄熀浜Linux鏈?#37716;?#37731;幆澧冿紝鍋?#28729;氱幆澧冧负绉?#37716;?#27996;?#38001;?#32515;戠幆澧?#37510;?#29825;板綍鎴戠洰鍓嶆墍鐭TCP鐨勪竴浜?#28051;嶈冻?#32029;鏈夋墍鍋?#23480;紝璇?#32513;?#28051;庢寚姝?#37510;?/p>

?#31476;銆?#28051;夋鎻墜

鍦?#32429;?#28729;?#28028;?#38315;?#37825;版嵁涔?#37715;嶉渶瑕佷?#22795;鎻墜?#32029;鏄剧劧鏈?#27996;?#28598;?#28003;欙紝涓?#37923;屾彁鍑?#27996;員CP Fast Open (TFO)鎵?#28766;?#37832;?#37714;讹紝涓?#23046;?#37819;墜涔嬪悗灏?#37721;?#28000;?#37721;?#38315;佹?#29238;涓?#37716;?#37825;版嵁浜?#37510;?#28003;?#26473;欓渶瑕?#28729;埛绔?#37724;?#37832;?#37716;?#37731;?#32468;?#37712;?#37837;稿眰?#28528;閮?#37824;?#37816;佹?#23944;锛?Linux鍐?#37837;?.6瀹埛绔紝3.7鏀寔鏈?#37716;?#37731;?#32468;?#37510;?/p>

杩?#38339;?#38339;?#29831;?#38171;?a href="https://lwn.net/Articles/508865/">TCP Fast Open: expediting web services

浜?#37510;傛參鍚?#37716;?/h3>

?#31476;娆?#37928;凥TTP璇锋眰?#32029;搴?#37922;眰鍙?#38315;佽緝澶HTML椤甸潰鐨?#37825;版嵁?#32029;?#28214;瑕佺粡杩囪嫢骞?#28051;?#23536;杩?#23536;幆?#26882;闂?Round-Trip Time)涔嬪悗?#32029;鎷?#28617;炵獥鍙?#37813;嶈?#34249;?#29112;墿灞?#37714;?#37832;澶?#38315;?#37722;?#37825;板硷紝涓?#38338;?#26473;?#32459;嬮?#22246;负鍐?#28003;?#37510;?#26473;?#28051;?#37721;傛暟鐩?#37818;?#37711;?#32495;荤潃绯?#32513;?#37722;?#37722;?#38322;忥紝鍚?#37722;愰噺澶?#27996;嗭紝绯?#32513;熷欢杩?#28751;?#27996;?#37510;?#28003;?#29825;?#32515;?#37812;?#28598;?#28598;紝?#28214;瑕佹?#35268;嵁涓?#37716;?#26473;?#29723;屾?#22795;嫨銆?/p>

3.0鍐?#37837;?#28052;?#37715;嶅垵濮嬪寲鎷?#28617;炵獥鍙?initcwnd)澶?#28751;忎负3銆備竴涓?#23480;插?#34425;珛杩?#37818;垵濮?#28028;犺緭鏁版嵁?#26882;鍙?#28028;?#38315;?涓狹SS?#32029;?#23266;1涓狹SS?#36127;1400閭?#28052;堜竴娆?#37804;?#37721;?#28028;?#38315;?K鐨?#37825;版嵁?#32029;?#23266;?#36127;10?#32029;?#31476;娆?#37804;?#37721;?#28028;?#38315;?3K鐨?#37825;版嵁銆?/p>

璋锋瓕缁?#26473;囪?#20906;?#26067;紝?#32531;璁?#32457;?#37716;?#27996;?#38001;?#32515;WEB?#24134;澧?#28051;嬪缓璁甶nitcwnd璁?#32515;?#37812;?0?#32029;linux鍐?#37837;?.0鐗?#37832;?#28052;嬪?#24232;粯璁?#37706;间负10銆傞亣鍒拌緝浣?#37712;?#37837;革紝?#28214;瑕佹墜鍔?#26473;?#29723;?#29825;?#32515;?#37510;?/p>

?#23266;鏄?#28766;鍩?#32515;戠幆澧?#37832;?#32491;?#28028;?#28598;?#37825;版嵁鎴?#37826;?#28000;?#37928;?#28028;犺緭?#28214;?#30512;?#32029;鍙?#28000;?#38000;?#38095;?#38315;傚綋鏀?#28729;戒竴浜?#37510;?/p>

?#23266;闀?#26473;?#37818;?#23524;虹珛涔嬪悗浼犺緭鐨?#38318;?#37828;?#28751;忔?#22559;伅?#32029;姣?#23046;?#28028;犺緭浜?#26473;?#37714;?#28051;?#37714;?K?#32029;閭?#28052;堟參鍚?#37716;?#37824;?#37716;?#28051;?#37722;?#38318;?#37828;棤鍏崇揣瑕?#37928;?#27996;嬫儏浜?#37510;?/p>

杩?#38339;?#38339;?#29831;?#38171;?/p>

涓?#37510;傜嚎澶?#38339;诲(Head-of-line blocking, HOL)

TCP鍗?#29825;?#37825;版嵁浼犺緭?#28214;瑕佹?#22794;簭浼犺緭?#32029;鍙?#28000;悊瑙负FIFO鍏?#26473;?#37711;堝?#27946;槦鍒楋紝?#32139;鍓嶉潰鏁版嵁浼犺緭涓?#28598;?#37722;庯紝鍚?#32513;?#37825;版嵁鍗?#37711;?#37721;兘绛?#23536;咃紝闄?#38344;?#23480;?#32513;?#28051;?#28598;?#37928;?#37825;版嵁琚噸浼犲?#21057;璁?#37818;?#37824;?#28000;?#37722;庯紝鍚?#32513;?#37825;版嵁鍖?#37813;?#28028;氳浜?#28000;?#32513;?#28729;埛绔?#29825;?#28598;囷紝杩?#28751;?#37828;?#37813;璋?#37928;勭嚎澶达紙HOL?#32029;head-of-line blocking锛?#38339;诲銆傛?#26055;緝娴?#29840;规湇鍔?#37731;?#29999;?#28729;藉張闄?#28003;?#27996;?#32495;?#32513;熸兘?#32029;涓嶉珮鏁?#37510;?/p>

1. 澶?#29882;?#28598;?#37922;?#28051;嶇?#21976;兂

HTTP/2?#24385;鍑?#37928;?#28051;?#37716;眰?#28528;澶?#29882;?#28598;?#37922;紝?#27367;?#21159;鍦竴瀹?#32459;嬪害涓?#29785;?#37712;?#27996;咹TTP/1.*鍗曡矾浼犺緭闂?#26864;橈紝浣嗕緷?#21159;鍙?#37714;?#27996;?#37813;渚?#29863;?#37928;凾CP鏈韩?#22158;澶?#38339;诲鐨勭?#27946;櫡銆傛?#21227;缓浜嶵CP涓婂眰鍗?#29825;?#37928;勫璺?#28598;?#37922;紝?#31476;鏃?#37721;戠?#29111;?#34425;?#25198;嚎澶?#38339;诲?#28871;紝?#28214;瑕?#28751;忓績瀵?#23536;?#28598;?#29882;?#37928;?#28051;?#37716;?#37825;版嵁鍙?#38315;?#28598;?#29840;?#38338;?#26864;?#37510;?/p>

2. TCP Keepalive鏈?#37714;?#28598;?#37825;?/h4>

?#24714;璁?#28051;奣CP鐨凨eepalive?#32346;娲?#37813;?#28766;?#37832;?#37714;讹紝鍦?#37713;虹?#25198;嚎澶?#38339;诲鐨勬椂鍊欙紝鍙?#38315;佷?#23941;嚭鍘昏?#31476;鐩?#38339;诲?#28871;紝瀹屽叏澶?#37825;?#37510;?/p>

绫?#28028;?#27996;嶯FS鏂?#28000;剁郴缁燂紝?#31476;鑸?#38322;?#37922;?#37721;屽悜鐨凾CP Keepalive?#32346;娲?#37832;?#37714;讹紝鐢?#28000;?#29785;勯伩鏌愪竴绔洜?#22158;澶?#38339;诲鍑虹?#26495;鑷Keepalive?#26852;鏁?#37928;?#38338;?#26864;橈紝鍙婃椂鎰熺煡?#31476;绔?#28699;樻?#32472;儏鍐?#37510;?/p>

3. ?#22158;澶?#38339;诲瓒呮椂?#24385;绀?/h4>

鏁版嵁鍖?#37721;?#38315;佷?#21997;紝鍚?#37716;?#37818;?#37824;剁璁?#28729;氭椂鍣紝瓒呮椂鍚?#28028;?#38322;嶅?#25135;紝閲嶅?#25116;緷?#21159;鏃犵璁紝鍚?#32513;?#37825;版嵁浼氫竴鐩村爢绉?#37714;板緟鍙?#38315;侀槦鍒?#28051;紝杩?#38322;?#28028;?#37832;変竴涓?#38339;诲瓒呮椂?#32029;绠楁硶寰堝?#23942;潅銆?#28051;婂眰搴?#37922;?#28028;?#37818;?#37824;?#37714;版潵鑷?#37712;?#37837;?#37719;?#29825;?#37837;?#37928;勬眹鎶?No route to host"鐨勯敊璇俊鎭紝榛?#29825;?#28051;嶅浜?6鍒嗛?#29112;椂闂淬?#37734;?#37832;?#37716;?#37731;?#32468;?#38171;堟病鏈?#28051;?#37716;績璺虫敮?#23508;鐨勬儏鍐?#28051;?#38171;?#37721;?#38315;?#37825;版嵁鍓?#37814;婄粓绔?#23534;?#37714;?#37826;嚎?#32029;椤?#28186;跨粨鍚圱CPDUMP鎴?#37718;咃紝绛?5鍒嗛挓宸?#37721;?#37712;?#37837;歌鍛?EHOSTUNREACH"?#25930;璇紝搴?#37922;眰?#28528;灏?#37721;?#28000;?#37930;嬪埌"No route to host"鐨?#38315;氱煡銆?/p>

鍥?#37510;?#37733;?#23046;?#37821;嗘墜

涓?#32468;?#26473;?#37818;?#37812;?#37716;熷?#34425;珛涔嬪悗?#32029;?#28214;瑕?#37711;?#38338;椂?#32029;?#28214;瑕佷骇鐢?#37733;?#23046;?#27996;?#27996;掞紝杩?#37734;?#32457;?#37716;?#27996;?#38001;?#32515;戠幆澧?#28051;嬶紝鏄?#23536;?#37832;?#27996;?#28598;?#28003;?#37510;傚揩閫?#37711;?#38338;紝?#25577;閫熷?#23941;簲?#32029;鍐?#28003;?#27996;?#27996;?#28725;?#38007;?#32515;戠粶甯?#28729;借鍗?#37922;?#37510;?/p>

浜?#37510;傜璁?#37832;?#37714;?#38315;氱煡鍒?#28051;婂眰搴?#37922;?#38171;?/h3>

杩?#37828;竴涓?#23011;旇緝缇?#28610;?#37928;?#37808;?#37832;涳紝涓婂眰搴?#37922;?#37734;皟鐢?#37712;?#37837;?#28766;傛帴鍙?#37721;?#38315;?#28598;?#23048;垫?#29256;嵁?#32029;鍐?#37837;?#28729;?#37812;?#37721;?#38315;佸苟涓?#37824;?#37714;板?#35268;柟瀹?#37825;?#32429;?#29825;紝?#21159;鍚庨氱煡涓婂眰搴?#37922;?#23480;?#32513;忓彂閫佹垚鍔燂紝閭?#28052;堝湪?#31476;浜涚幆澧?#28051;嬶紝鍙?#28000;?#38010;傜?#20343;笉灏戜笟鍔眰?#28528;浜?#27996;?#23005;?#26976;?#37510;?/p>

鍏?#37510;侼AT缃?#37711;?#29906;呮椂

IPV4鏈夐檺?#32029;灞鍩?#32515;戠幆澧?#37706;?#37716;?#27996;嶯AT璺?#37922;?#29825;?#28598;?#37813;?#28766;?#27996;嗘帴鍏粓绔?#29825;?#28598;?#37928;?#37825;伴噺銆傚綋寤虹珛?#31476;涓猅CP闀?#26473;?#37818;椂?#32029;NAT璁?#28598;囬渶瑕佺淮鎶竴涓?#37712;?#38318;粓绔?#26473;?#37818;?#28598;?#38318;?#37832;?#37716;?#37731;?#37813;浣?#37922;?#37928;勫唴閮IP:PORT涓?#37713;?#37720;?#37928;処P:PORT鏄?#28751;勫?#29808;簲鍏?#32495;?#37510;?#26473;?#28051;?#37711;?#32495;婚渶瑕佺淮鎶紝姣旇緝鑰?#29840;瑰唴瀛?#29863;勬簮?#32029;鏈?#29906;呮椂瀹氭椂鍣?#23059;?#37918;嗭紝鍚?#37714;?#28028;?#28725;?#38007;村唴瀛樻?#25120;垎銆?/p>

涓?#37722;孨AT璁?#28598;?#29906;呮椂鍊?#28051;嶄竴鏍凤紝?#27932;姝?#37813;嶉渶瑕佸績璺宠緟鍔紝纭繚缁?#26473;NAT璁?#28598;?#37928;?#26473;?#37818;竴鐩翠繚鎸侊紝?#20265;鍏嶅洜杩?#38336;?#37928;勬椂闂?#29722;涪鎺?#37510;傛?#26047;?#20638;?#22557;涓?#37733;界鍔?#32515;戠粶杩?#37818;?#37816;佷?#21614;椂闂翠竴鑸?#29825;?#32515;负涓嶈秴杩?鍒嗛挓銆?#37722;勭缃戠粶鐣?#37832;?#23480;?#23534;傦紝寮?#37711;?#37829;鸿?#34249;績璺?#37832;?#37714;?#23011;旇緝鍚?#38315;?#37510;?/p>

涓?#37510;傜粓绔疘P婕父

?#22684;鏈虹粓绔?#32513;忓父鍦?G/3G/4G鍜學IFI涔?#38338;村垏鎹紝瀵?#38007;碔P鍦板潃棰戠箒鍙戠?#29112;?#29808;彉銆?#26473;?#37837;?#38315;?#37812;?#37928;勫悗鏋?#28751;?#37828;?#23480;?#37832;?#37928;勭?#25120;粶璇锋眰-鍝嶅?#26055;鏀?#23534;?#37724;岀粓姝紝?#28214;瑕佷汉宸?#39582;?#26864;?#37812;栭噸鏂板彂璧?#29831;锋眰?#32029;瀛?#37734;?#29863;勬簮娴?#29840;?#37916;拌薄銆?/p>

鏀寔Multipath TCP鐨勭粓绔?#29825;?#28598;囷紝鍙?#28000;?#37722;屾椂鍒?#37922;?2G/3G/4G 鍜?WiFi 寤虹珛Mutlpath杩?#37818;紝閫?#26473;囧?#27697;偣浼?#37718;?#32515;戠粶涓嬭浇?#32029;涓?#27996;掍负澶?#28000;?#37510;傚彲浠?#23536;堝瑙?#37712;?#28598;?#28051;?#32515;戠粶鍏?#28699;?#37928;勬儏鍐?#28051;嬶紝?#31476;涓?#32515;戠粶涓?#37826;?#28051;?#28028;?#28725;?#38007;村叏灞璇锋眰澶勭悊涓?#37826;紝鍦?#29825;?#28598;?#37928;?#26473;?#37818;?#32459;?#28729;?#37724;屽彲闈犳?#37826;归潰鏈夋墍澧?#23534;?#37510;?/p>

?#32139;?#21159;?#32029;鏈?#37716;?#37731;?#28052;?#38338;?#28052;熷彲浠?#37714;?#37922;Multipath TCP鐨勫涓?#32515;戠粶澧?#23534;虹?#25120;粶鍚?#37722;愰噺銆?/p>

鐜扮姸鏄?#38171;?/p>

  1. ?#27952;鍓嶅彧鏈IOS 7浠?#37721;?#37722;?#32513;?#37911;?#37832;?#37824;寔
  2. Linux kernel 3.10瀹為?#23677;垎鏀?#28051;婂彲浠?#37930;嬪?#26495;叾鏀?#37816;佽韩褰紝浣嗕綍?#26882;鍚堝苟鍒?#28051;?#37714;嗘敮涓婏紝鏆傛椂鏈?#37933;?

杩?#38339;?#38339;?#29831;?#38171;?a href="http://blog.multipath-tcp.org/blog/html/index.html">A closer look at the scientific literature on Multipath TCP

鍏?#37510;俆CP缂?#28699;樿鑳

?#32139;璺?#37922;?#37731;?#37818;?#37824;?#37714;?#37928;?#37825;版嵁鍖?#29906;?#29906;?#37711;堕槦鍒?#38336;?#25652;椂?#32029;?#31476;鑸?#28028;氶殢鏈?#28051;?#37718;咃紝浠?#37713;?#28751;戣鑳銆傞?#22557;涓婂眰搴?#37922;?#32459;嬪簭鑰岃?#32029;?#27426;杩熷鍔狅紝鎴?#29831;?#29825;负鏁版嵁涓?#28598;紝鎴?#26473;?#37818;?#28051;?#28598;?#32475;?#37510;?/p>

閬?#37714;?#26473;?#32457;嶆儏鍐碉紝?#31476;鑸缓璁揩閫熷?#25117;寘?#32029;浠伩鍏?#28051;?#28598;?#37928;?#37825;版嵁閮?#37714;?#37510;?#37712;?#37837;稿眰?#28528;浠?#37827;?#37719;?#32510;?#37714;?#37832;?#26570;鐗堬紝涓?#28003;?#27996;?.6鍗?#37721;?#37510;?/p>

杩?#38339;?#38339;?#29831;?#38171;?a href="http://en.wikipedia.org/wiki/Bufferbloat">Bufferbloat

涔?#37510;俆CP涓?#37828;?#32513;?#28725;瑰彲闈?#37928;?/h3>
  1. IP鍜孴CP鍗?#29825;?#37734;?#28598;?#38318;?#38318;?#28028;?#37832;check sum?#25930;璇?#37837;?#26976;屽拰鏈?#37714;讹紝16浣嶈绀猴紝鍙嶇爜鐩?#37716;狅紝缁?#37835;滄眰鍙嶏紝鍏?#28003;?#37721;?#37721;傝?TCP鏍?#26976;屽拰鐨勫?#29114;?#21975;拰瀹?#37916;?/a>銆備竴鑸敊璇?#23536;?#26462;?#37833;?#37721;?#22955;娴嬪?#28888;潵?#32029;浣嗛亣鍒?#28051;?#28051;?6浣?#37825;板瓧鐩?#37716;?#37722;?#32513;?#37835;?#28051;嶅彉鐨勬儏鍐?#28751;变竴绛硅帿灞?#27996;?
  2. 浠?#28598;?#32515;戝抚CRC32鏍?#26976;屼竴鑸?#37807;?#37712;?#28051;嬮兘寰圤K?#32029;浣嗗彲?#20824;閬?#37714;?#28051;?#32468;?#38341;旂澶?#28051;?#29882;?#37922;?#37731;?#37807;?#37712;?#28051;嬶紝灏?#37832;?#37721;?#38003;藉?#34425;幇闂?#26864;橈紝姣斿?#20638;?#22562;?#26337;佸?#22559;?#24874;緵鐨勪竴寮?#37733;?#38171;?

    涓?#37733;?#28051;瑿lient鍚慡erver鍙戜簡?#31476;涓猅CP segment?#32029;杩?#28051;猻egment鍏堣灏佽鎴愪竴涓狪P packet?#32029;鍐嶈灏佽鎴ethernet frame?#32029;鍙?#38315;?#37714;拌矾鐢?#37731;?#38171;堝浘涓?#23057;堟伅a锛?#37510;俁outer鏀?#37714;ethernet frame (b)?#32029;杞?#37721;?#37714;板彟?#31476;涓?#32515;?#23048;?c)?#32029;鏈鍚嶴erver鏀?#37714;d?#32029;閫氱煡搴?#37922;?#32459;嬪簭銆侲thernet CRC?#20824;?#32346;璇乤鍜宐鐩?#37722;岋紝c鍜宒鐩?#37722;?#38171;汿CP header check sum鐨勫己搴?#28051;嶈冻浠繚璇佹敹鍙payload鐨勫唴瀹逛竴鏍?#37510;傚彟澶栵紝濡傛灉鎶奟outer鎹?#37812;NAT?#32029;閭?#28052;圢AT鑷?#23480;?#28028;?#37835;?#38315;燾锛堟浛鎹?#37818;夋簮鍦板潃锛夛紝杩欐椂鍊檃鍜宒鐨刾ayload涓嶈兘鐢tcp header checksum鏍?#26976;?#37510;?/p>

  3. 璺?#37922;?#37731;?#37721;?#38003;藉?#21057;劧鍑虹?#25198;浠?鍐?#28699;?#37825;呴殰瀵?#38007;存敹鍙IP鎶?#37826;囧?#34425;?#26495;?#27484;it/鍗昩it鐨勫?#23944;浆鎴?#37721;?#28699;?#38010;?#27996;?#37817;紝杩?#28051;?#37721;嶈浆濡傛灉鍙戠?#29111;湪payload鍖猴紝閭?#28052;堟?#29363;硶鐢?#38334;捐矾?#30512;銆佺?#25120;?#28355;眰銆佷?#29370;?#25779;眰鐨刢heck sum鏌?#37713;烘潵?#32029;鍙兘閫?#26473;囧簲鐢眰鐨刢heck sum?#28533;妫娴?#37510;傚洜姝缓璁?#25652;?#37922;眰瑕?#29825;炬硶娣?#37716;?#37837;?#26976;?#37825;版嵁鍔熻兘銆?/p>

  4. 澶?#37826;?#28000;?#28051;嬭浇娣?#37716;?#37837;?#26976;屼繚璇?#37825;版嵁瀹?#37825;存紝?#31476;鑸?#38322;?#37922;MD5?#32029;涔?#37922;?#27996;庨姝?#28729;?#37711;?#32481;?#37824;?/p>

鍙傝?#29863;?#37826;?#38171;?/p>

鍗?#37510;?#28751;?#32513;?/h3>

鍦?#26473;?#28051;?#23114;?#28051;栫晫閮?#37828;疶CP鐨勭幆澧?#28051;嬶紝瑕佹兂瀵筎CP鍔?#28598;墜鏈紝杩?#28051;?#37828;?#28051;嶅鍙兘鐨勶紝?#27932;?#36127;瀹?#23480;?#32513;忓浐鍖?#37714;板凡鏈?#37928;勭郴缁?#37712;?#37837;?#37724;屽浐浠?#28051;?#37510;傛?#26047;鍗?#32510;粓绔?#38171;堟?#26047;?#20395;ndroid/IOS绛?#38171;?#32495;?#32513;??#27984;浠讹紝Linux鏈?#37716;?#37731;?#37712;?#37837;革紝涓?#38338;?#29825;?#28598;?涓?#28000;?#29825;?#28598;?#38171;堝璺?#37922;?#37731;?#32475;?#38171;夛紝杩?#37828;竴涓?#23092;?#28598;?#23480;?#32459;嬶紝?#27952;鍓?#37930;?#28052;?#28051;?#37916;?#28729;?#37510;?/p>

TCP浣?#27996;?#32495;?#32513;?#37712;?#37837;稿眰?#32029;鍐?#37837;?#32460;?#38338;?#37928;勫崌绾?#37510;佷慨澶嶏紝鏈?#36127;楹荤儲銆傛湇鍔?#37731;?#32468;?#37719;?#32510;?#26473;?#28610;?#29831;翠竴浜涳紝鐢埛?#31891;绔?#32495;?#32513;?#37928;勫崌绾?#38317;?#37721;竴涓?#38341;?#37510;?#37922;埛绌?#38338;?鐢埛鏍?#37928;勫簲鐢?#37719;?#32510;?#37510;佹敼閫?#37929;?#28725;规瘮?#28533;璇村彲鎺?#37804;?#23534;猴紝?#29056;浜庢Google涓?#28729;?#28000;?#37929;?#37818;?#37734;UDP鍗?#29825;?#28051;?#26473;?#29723;屾?#21227;缓銆佸苟涓旇繍琛屽湪鐢埛绌?#38338;?#37928;凲UIC鍗?#29825;紝缁?#37722;?#27996;哢DP鐨勮?#23130;?#24531;拰TCP鐨勫彲闈犳紝鏄竴涓?#23011;旇緝?#26570;棰?#37928;?#37826;?#37722;?#37510;?/p>

?#23266;鏄?#28725;?#28000;?#37722;?#25652;曞眰浼犺緭鍗?#29825;?#37832;夋墍鏈?#37832;?#37928;?#29831;?#38171;?/p>

  • 鍦?#37922;埛绌?#38338;达紙鐢埛鏍?#38171;?#37713;虹?#26495;彲浠?#28729;?#37714;?#37928;勫崗璁紝绫?#28028;?#27996;嶲UIC
  • 浼?#32513;?#37928;凾CP/UDP鍙?#28000;?#26473;?#29723;屽湪鐢埛绌?#38338;达紝鐩?#37818;?#37923;?#26473;囧唴鏍?
  • 瀹?#37825;村崗璁?#37837;?#28000;?#38344;?#37804;侀摼鎺?#25652;撳舰寮忔?#24874;緵缁?#28051;婂眰搴?#37922;?
  • 涓婂眰搴?#37922;?#37721;?#28000;?#37734;?#32514;?#29831;?#37510;佹墦鍖?#37928;勬椂鍖?#37722;?#37711;?#37813;渚?#29863;?#37719;?#29825;?#37837;?#38344;?#37804;侀摼鎺?#25652;so鏂?#28000;?
  • dpdk/netmap绛塒acket IO妗?#37835;?+ 鐢埛绌?#38338;村崗璁爢鏍堬紝鏁版嵁灏?#28000;?#32515;?#37719;?#37929;?#37818;?#38315;佽揪涓婂眰搴?#37922;?
  • Linux鍐?#37837;?#38322;嶈?#20345;?#38340;?#28003;庯紝?#29238;瑙?#37928;凷SH绯?#32513;熺淮鎶?

?#27367;?#21159;TCP瀛?#37734;?#26473;?#37837;?#37510;?#38317;?#37837;?#37928;?#38338;?#26864;橈紝浣嗙洰鍓嶈繕鏄?#37827;犳硶缁?#26473;?#37928;勭?#25120;粶鍩虹璁?#37826;斤紝浣?#32459;?#23536;?#37828;庣櫧?#31476;浜?#28051;嶈冻鐨勫湴鏂癸紝鎴?#29825;?#28028;?#28725;规?#25116;滑?#32139;鍓?#28003;?#37922;?#37928;勭?#25198;姸鏈夋墍甯?#37716;?#37510;?/p>

]]>闅忔墜璁?#28052;婽CP Keepalive绗?#29825;?/title><link>http://www.8634070.com/yongboy/archive/2015/04/14/424413.html</link><dc:creator>nieyong</dc:creator><author>nieyong</author><pubDate>Tue, 14 Apr 2015 09:08:00 GMT</pubDate><guid>http://www.8634070.com/yongboy/archive/2015/04/14/424413.html</guid><wfw:comment>http://www.8634070.com/yongboy/comments/424413.html</wfw:comment><comments>http://www.8634070.com/yongboy/archive/2015/04/14/424413.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.8634070.com/yongboy/comments/commentRss/424413.html</wfw:commentRss><trackback:ping>http://www.8634070.com/yongboy/services/trackbacks/424413.html</trackback:ping><description><![CDATA[<div class="wrap"> <h3 id="-">?#27970;銆?#37715;嶈</h3> <p>TCP鏄棤鎰熺煡鐨勮?#27693;嫙杩?#37818;紝涓?#38338;?#37826;?#23534;涓?#32468;?#28051;?#28028;?#32468;嬪埢寰?#37714;?#38315;氱煡銆備竴鑸?#37734;?#28003;?#37922;?#38336;?#26473;?#37818;?#37928;勭幆澧?#28051;嬶紝?#28214;瑕佸績璺充繚娲?#37832;?#37714;?#37721;?#28000;媺寮?#37808;熺煡鍏?#28699;樻椿銆?#28051;?#37716;眰?#28528;鏈夊績璺?#37832;?#37714;讹紝TCP鍗?#29825;?#28052;熸?#24874;緵浜嗗績璺充繚娲?#37832;?#37714;?#37510;?/p> <h3 id="-tcp-keepalive-">?#31476;銆俆CP Keepalive瑙?#29831;?/h3> <p>闀?#26473;?#37818;?#37928;勭幆澧?#28051;嬶紝浜?#28000;竴鑸?#28003;?#37922;?#28051;?#37716;眰?#28528;鎴?#28051;婂眰搴?#37922;眰鍗?#29825;?#38171;?#29831;稿MQTT?#32029;SOCKET.IO绛?#38171;夐?#23684;潰瀹?#28052;?#37724;?#28003;?#37922;?#37510;備竴鏃?#37832;夌鏁版嵁?#28214;瑕佷紶閫掞紝?#23266;姝椂杩?#37818;?#23480;?#32513;忚涓?#28000;?#29825;?#28598;?#37826;?#23534;?#32029;搴?#37922;?#32459;嬪簭?#30149;鏈?#37721;婃椂鎰熺煡鐨?#29831;濓紝閭?#28052;堝氨浼?#28725;?#38007;村湪?#31476;涓棤鏁?#37928;?#37825;版嵁閾捐矾?#30512;?#28528;鍙?#38315;佷笟鍔?#37825;版嵁?#32029;缁?#37835;?#28751;?#37828;?#37721;?#38315;?#28598;?#29840;?#37510;?/p> <p><img src="http://www.netis.com.cn/flows/wp-content/uploads/2012/10/111.png" alt="" /></p> <p>?#26852;璁?#37828;洜?#36127;瀹埛绔?#37808;?#28598;?#37826;?#37922;?#37510;佹鏈?#37510;佸穿婧?#37510;侀噸鍚紝杩?#37828;?#28051;?#38338;?#29882;?#37922;?#32515;戠?#28356;棤鏁?#37826;?#23534;銆丯AT瓒呮椂绛夛紝鏈?#37716;?#37731;?#32468;?#29781;佸仛鍒板揩閫?#37808;熺煡澶?#29840;紝鍑?#28751;戞棤鏁堥摼鎺?#37823;嶄綔銆?/p> <h4 id="1-">1. 浜?#27996;?#26473;?#32459;?/h4> <p><img src="http://www.netis.com.cn/flows/wp-content/uploads/2012/10/151.png" alt="" /></p> <h4 id="2-">2. 鍗?#29825;?#29785;?#29831;?/h4> <p>涓嬮潰鍗?#29825;?#29785;?#29831;伙紝?#29056;浜?a href="https://tools.ietf.org/html/rfc1122#section-4.2.3.6">RFC1122#TCP Keep-Alives</a>銆?/p> <ol> <li>TCP Keepalive?#27367;涓?#37828;?#37837;囧噯瑙勮寖?#32029;浣?#37823;嶄綔绯?#32513;熶竴鏃?#28729;?#37916;帮紝榛?#29825;?#37807;?#37712;?#28051;嬮?#35763;负鍏?#38338;紝鍙?#28000;?#29722;?#28051;婂眰搴?#37922;?#23534;鍚?#37724;屽叧闂?#37510;?/li> <li>TCP Keepalive蹇?#26916;?#37734;病鏈?#28000;讳綍鏁版嵁锛堝寘鎷珹CK鍖?#38171;夋帴鏀?#28052;嬪悗鐨勫懆鏈?#37712;?#37813;?#28028;氳鍙?#38315;侊紝鍏?#29825;搁厤缃紝榛?#29825;?#37706;?#28051;嶈?#34249;灏?#27996;?涓?#28751;忔椂</li> <li>涓嶅寘鍚?#37825;版嵁鐨凙CK娈?#37734;?#29722;玊CP鍙?#38315;佹椂?#30149;鏈?#37721;?#38344;犳繚璇侊紝鎰?#37719;充竴鏃?#37721;?#38315;侊紝涓嶇?#32346;?#31476;瀹?#37721;?#38315;佹垚鍔?#37510;傜郴缁?#28729;?#37916;?#28051;嶈兘瀵?#28000;讳綍鐗?#28729;?#37818;?#38333;堝?#21612;綔姝?#26473;?#37818;?#28725;?#23536;?/li> <li>瑙勮寖?#32531;璁keepalive?#32346;娲?#37718;?#28051;嶅?#26055;鍖?#37722;?#37825;版嵁?#32029;浣?#28052;熷彲浠?#37718;?#37722;?涓棤鎰?#28052;?#37928;勫瓧鑺傦紝姣斿0x0銆?/li> <li>SEG.SEQ = SND.NXT-1?#32029;鍗TCP?#32346;娲?#37818;?#23092;嬫姤鏂囧簭鍒?#37721;?#28751;?#37715;嶄竴涓猅CP鎶?#37826;囧簭鍒?#37721;?#37713;?銆係ND.NXT = RCV.NXT?#32029;鍗?#28051;嬩竴娆?#37721;?#38315;佹?#29238;鎶?#37826;囧簭鍙?#32475;?#27996;嶢CK?#31789;鍒?#37721;?#38171;?#37804;?#28052;嬩繚娲?#37814;?#37826;?#28051;嶅湪绐?#37721;?#37818;?#37714;惰寖鍥村唴 鏈変竴寮?#37733;撅紝鍙?#28000;?#23536;?#28729;规槗璇?#37828;庯紝浣?#29831;?#28000;?#32513;?#29785;?#28725;烼cp Keepalive閮?#37714;?#38171;?/li> </ol> <p><img src="http://www.8634070.com/images/blogjava_net/yongboy/Windows-Live-Writer/dec027faa0ee_D437/image_thumb_2.png" alt="" /></p> <ol> <li>涓嶅濂?#37928;凾CP?#29218;鏍?#28729;?#37916;帮紝鍙兘浼?#29781;佹眰?#32346;娲?#37814;?#37826;囧繀椤绘?#21700;甫鏈?涓?#28699;?#38010;?#37928;?#37825;版嵁璐?#26462;?/li> <li>TCP Keepalive搴旇鍦?#37832;?#37716;?#37731;?#32468;?#37722;?#37922;紝瀹埛绔?#28051;嶅仛浠讳綍鏀?#37716;?#38171;涜嫢鍗曠嫭鍦?#28729;埛绔?#37722;?#37922;紝?#23266;瀹埛绔?#23534;傚父?#31359;婧?#37812;?#37713;虹幇杩?#37818;?#37825;呴?#28368;紝瀛?#37734;?#37832;?#37716;?#37731;棤闄?#37832;?#37928;勪负宸?#37813;?#23534;鐨?#28003;?#23480;?#28598;?#37825;?#37928;?#37826;?#28000;舵弿杩?#32471;秷鑰?#29863;勬簮鐨?#28051;噸闂?#26864;?#37510;?#28003;嗗湪鐗规鐨NFS鏂?#28000;剁郴缁熺幆澧?#28051;嬶紝?#28214;瑕?#28729;埛绔?#37724;?#37832;?#37716;?#37731;?#32468;?#38318;?#29781;?#37722;?#37922;Tcp Keepalive鏈?#37714;?#37510;?/li> <li>TCP Keepalive涓?#37828;疶CP瑙勮寖鐨勪竴閮?#37714;嗭紝鏈?#28051;夌偣?#28214;瑕佹敞鎰?#38171;?ul> <li>鍦?#37933;?#37830;?#37928;?#37825;呴殰鏈?#38338;达紝瀹?#28000;?#37721;兘寮曡?#34562;竴涓?#38009;?#28610;?#26473;?#37818;?#38171;good connection锛夎閲?#37824;?#38171;坉ropped锛?/li> <li>瀹?#28000;秷璐?#27996;?#28051;嶅繀瑕?#37928;勫?#34249;甫</li> <li>鍦?#28000;?#37825;版嵁鍖?#29825;?#29840;?#37928;?#27996;?#38001;?#32515;戞秷璐?#38171;堥澶?#38171;夎姳璐?#38322;?#38333;?/li> </ul> </li> </ol> <h3 id="-tcp-keepalive-">浜?#37510;俆cp keepalive 濡備綍浣?#37922;?/h3> <p>浠?#28051;嬬幆澧?#37828;?#37734;Linux鏈?#37716;?#37731;?#28051;?#26473;?#29723;?#37510;?#25652;?#37922;?#32459;嬪簭?#23266;?#20802;浣?#37922;紝?#28214;瑕?#29825;?#32515;甋O_KEEPALIVE濂?#37818;?#37721;?#38315;夐?#35268;?#23944;?#34249;鐢?#37825;?#37510;?/p> <h4 id="1-">1. 绯?#32513;?#37712;?#37837;?#37721;傛?#20276;厤缃?/h4> <ol> <li>tcp_keepalive_time?#32029;鍦TCP?#32346;娲?#37813;?#23534;鐨勬儏鍐?#28051;嬶紝鏈鍚庝竴娆?#37825;版嵁浜?#37817;?#37714;癟CP鍙?#38315;?#32471;竴涓繚娲?#37818;?#23092;嬪寘鐨?#38338;撮殧?#32029;鍗?#37711;?#29825;?#37928;勬?#20346;画绌?#38338;叉椂闀匡紝鎴?#38000;?#29831;?#23011;?#23046;?#23005;父鍙?#38315;佸績璺?#37928;勫懆鏈燂紝榛?#29825;?#37706;间负7200s锛?h锛?#37510;?/li> <li>tcp_keepalive_probes 鍦tcp_keepalive_time涔嬪悗?#32029;?#30149;鏈夋帴鏀?#37714;板?#35268;柟纭?#29825;紝缁?#32513;?#37721;?#38315;佷繚娲?#37818;?#23092;嬪寘娆?#37825;帮紝榛?#29825;?#37706;间负9锛堟锛?/li> <li>tcp_keepalive_intvl?#32029;鍦tcp_keepalive_time涔嬪悗?#32029;?#30149;鏈夋帴鏀?#37714;板?#35268;柟纭?#29825;紝缁?#32513;?#37721;?#38315;佷繚娲?#37818;?#23092;嬪寘鐨勫彂閫侀?#25120;?#22263;紝榛?#29825;?#37706;间负75s銆?/li> </ol> <p>鍙?#38315;侀?#25120;巼tcp_keepalive_intvl涔?#28000;?#37721;?#38315;佹鏁皌cp_keepalive_probes?#32029;灏?#23536;?#37714;?#27996;?#28000;?#23534;濮嬫帰娴嬪?#29256;斁寮?#37818;?#23092;?#32429;?#28729;?#26473;?#37818;?#37826;?#23534;鐨勬椂闂?/p> <p>?#23266;璁?#32515;紝鏈?#37716;?#37731;?#37734;?#28729;埛绔?#26473;?#37818;?#32460;?#38338;?#37928;勬椂鍊欙紝姣?0绉?#37721;?#38315;佷竴娆繚娲?#37818;?#23092;嬪寘鍒?#28729;埛绔紝?#23266;?#30149;鏈?#37721;婃椂鏀?#37714;?#28729;埛绔?#37928;凾CP Keepalive ACK纭?#29825;紝灏?#32513;?#32513;?#32475;?#23536;?5绉?2=30绉?#37510;傛?#28052;嬪彲浠?#37734;?0s+30s=120绉?#38171;?#28051;?#37714;嗛挓锛夋椂闂村唴鍙?#22955;娴嬪埌杩?#37818;?#28598;?#37825;?#28051;?#37722;?#37510;?/p> <p>浠?#28051;嬫敼鍔紝?#28214;瑕?#37712;?#37711;?#37714;?etc/sysctl.conf鏂?#28000;?#38171;?/p> <pre><code>net<span class="hljs-class">.ipv4</span><span class="hljs-class">.tcp_keepalive_time</span>=<span class="hljs-number">90</span> net<span class="hljs-class">.ipv4</span><span class="hljs-class">.tcp_keepalive_intvl</span>=<span class="hljs-number">15</span> net<span class="hljs-class">.ipv4</span><span class="hljs-class">.tcp_keepalive_probes</span>=<span class="hljs-number">2</span> </code></pre><p>?#32346;瀛?#38315;鍑猴紝?#21159;鍚?#37813;?#29723;?code>sysctl -p</code>鐢?#37825;?#37510;傚彲閫?#26473;?<code>sysctl -a | grep keepalive</code> 鍛?#28000;?#22955;娴嬩竴涓?#37828;?#37722;?#23480;?#32513;?#37922;?#37825;?#37510;?/p> <blockquote> <p>閽堝宸?#32513;?#29825;?#32515;甋O_KEEPALIVE鐨勫鎺?#28699;楋紝搴?#37922;?#32459;嬪簭涓?#37922;噸鍚紝鍐?#37837;?#37929;?#37818;?#37922;?#37825;?#37510;?/p> </blockquote> <h4 id="2-java-netty-">2. Java/netty鏈?#37716;?#37731;?#28641;備綍浣?#37922;?/h4> <p>鍙渶瑕?#37734;?#37832;?#37716;?#37731;?#32468;竴鏂?#29825;?#32515;?#37719;?#37721;紝瀹埛绔?#28729;屽叏涓?#37922;?#29825;?#32515;紝姣斿?#20634;熀浜netty 4鏈?#37716;?#37731;?#32459;嬪簭锛?/p> <pre><code>ServerBootstrap b = <span class="hljs-keyword">new</span> ServerBootstrap(); b.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, <span class="hljs-number">100</span>) .childOption(ChannelOption.SO_KEEPALIVE, <span class="hljs-keyword">true</span>) .handler(<span class="hljs-keyword">new</span> LoggingHandler(LogLevel.INFO)) .childHandler(<span class="hljs-keyword">new</span> ChannelInitializer<SocketChannel>() { <span class="hljs-annotation">@Override</span> <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">initChannel</span><span class="hljs-params">(SocketChannel ch)</span> <span class="hljs-keyword">throws</span> Exception </span>{ ch.pipeline().addLast( <span class="hljs-keyword">new</span> EchoServerHandler()); } }); <span class="hljs-comment">// Start the server.</span> ChannelFuture f = b.bind(port).sync(); <span class="hljs-comment">// Wait until the server socket is closed.</span> f.channel().closeFuture().sync(); </code></pre><p>Java绋嬪簭鍙?#38003;藉仛鍒?#29825;?#32515;甋O_KEEPALIVE閫夐?#30328;紝鑷?#27996;嶵CP_KEEPCNT?#32029;TCP_KEEPIDLE?#32029;TCP_KEEPINTVL绛?#37721;傛?#20276;厤缃紝鍙兘渚?#29863;?#27996;巗ysctl?#21412;缃紝绯?#32513;?#26473;?#29723;岃鍙?#37510;?/p> <h4 id="3-c-">3. C璇?#29815;濡備綍璁?#32515;?/h4> <p>涓嬮潰浠?#37934;佹憳鍙?#38007;猯ibkeepalive?#31790;鐮侊紝C璇?#29815;鍙?#28000;?#29825;?#32515;洿?#36127;璇?#32513;?#37928;凾CP鍐?#37837;?#37721;傛暟銆?/p> <pre><code><span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">socket</span><span class="hljs-params">(<span class="hljs-keyword">int</span> domain, <span class="hljs-keyword">int</span> type, <span class="hljs-keyword">int</span> protocol)</span> </span>{ <span class="hljs-keyword">int</span> (*libc_socket)(<span class="hljs-keyword">int</span>, <span class="hljs-keyword">int</span>, <span class="hljs-keyword">int</span>); <span class="hljs-keyword">int</span> s, optval; <span class="hljs-keyword">char</span> *env; *(<span class="hljs-keyword">void</span> **)(&libc_socket) = dlsym(RTLD_NEXT, <span class="hljs-string">"socket"</span>); <span class="hljs-keyword">if</span>(dlerror()) { errno = EACCES; <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>; } <span class="hljs-keyword">if</span>((s = (*libc_socket)(domain, type, protocol)) != -<span class="hljs-number">1</span>) { <span class="hljs-keyword">if</span>((domain == PF_INET) && (type == SOCK_STREAM)) { <span class="hljs-keyword">if</span>(!(env = getenv(<span class="hljs-string">"KEEPALIVE"</span>)) || strcasecmp(env, <span class="hljs-string">"off"</span>)) { optval = <span class="hljs-number">1</span>; } <span class="hljs-keyword">else</span> { optval = <span class="hljs-number">0</span>; } <span class="hljs-keyword">if</span>(!(env = getenv(<span class="hljs-string">"KEEPALIVE"</span>)) || strcasecmp(env, <span class="hljs-string">"skip"</span>)) { setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, &optval, <span class="hljs-keyword">sizeof</span>(optval)); } <span class="hljs-preprocessor">#ifdef TCP_KEEPCNT</span> <span class="hljs-keyword">if</span>((env = getenv(<span class="hljs-string">"KEEPCNT"</span>)) && ((optval = atoi(env)) >= <span class="hljs-number">0</span>)) { setsockopt(s, SOL_TCP, TCP_KEEPCNT, &optval, <span class="hljs-keyword">sizeof</span>(optval)); } <span class="hljs-preprocessor">#<span class="hljs-keyword">endif</span></span> <span class="hljs-preprocessor">#ifdef TCP_KEEPIDLE</span> <span class="hljs-keyword">if</span>((env = getenv(<span class="hljs-string">"KEEPIDLE"</span>)) && ((optval = atoi(env)) >= <span class="hljs-number">0</span>)) { setsockopt(s, SOL_TCP, TCP_KEEPIDLE, &optval, <span class="hljs-keyword">sizeof</span>(optval)); } <span class="hljs-preprocessor">#<span class="hljs-keyword">endif</span></span> <span class="hljs-preprocessor">#ifdef TCP_KEEPINTVL</span> <span class="hljs-keyword">if</span>((env = getenv(<span class="hljs-string">"KEEPINTVL"</span>)) && ((optval = atoi(env)) >= <span class="hljs-number">0</span>)) { setsockopt(s, SOL_TCP, TCP_KEEPINTVL, &optval, <span class="hljs-keyword">sizeof</span>(optval)); } <span class="hljs-preprocessor">#<span class="hljs-keyword">endif</span></span> } } <span class="hljs-keyword">return</span> s; } </code></pre><h4 id="4-kttcp-eepalive-">4. 閽堝宸?#37832;?#32459;嬪簭?#30149;鏈?#32429;?#32514;栫爜KTTCP EEPALIVE瀹?#37916;?/h4> <p>瀹屽叏鍙?#28000;?#37706;?#37716;?#27996;?#32471;?#28051;?#37826;?#23480;?#37711;?a href="http://libkeepalive.sourceforge.net/">libkeepalive</a>?#32029;閫?#26473;嘗D_PRELOAD鏂?#23534;?#28729;?#37916;?#37510;傛?#26047;</p> <pre><code>LD_PRELOAD=/the/path/libkeepalive<span class="hljs-class">.so</span> java -jar /your/path/yourapp<span class="hljs-class">.jar</span> & </code></pre><p>杩?#28051;?#23480;?#37711;?#26473;?#37832;変竴涓?#23011;旇緝鏂?#28186;?#37928;勫湴鏂癸紝鍙?#28000;?#37929;?#37818;?#37734;?#32459;嬪簭杩?#29723;?#37715;嶆寚瀹歍CP?#32346;娲?#29831;?#32513;嗗?#20635;暟?#32029;鍙?#28000;?#37930;佸?#23130;厤缃畇ysctl.conf鐨勯?#33636;儲锛?/p> <pre><code>LD_PRELOAD=/the/path/libkeepalive.so <span class="hljs-string">\</span> > KEEPCNT=<span class="hljs-number">20</span> <span class="hljs-string">\</span> > KEEPIDLE=<span class="hljs-number">180</span> <span class="hljs-string">\</span> > KEEPINTVL=<span class="hljs-number">60</span> <span class="hljs-string">\</span> > java -jar /your/path/yourapp.jar & </code></pre><p>閽堝?#30789;緝鑰?#23536;?#28052;?#28051;嶆洿?#26570;鐨勭?#23338;簭?#32029;鍙?#28000;?#28751;?#29831;曚竴涓嬪槢銆?/p> <h3 id="-linux-keepalive-">涓?#37510;侺inux鍐?#37837;稿眰?#28528;瀵筴eepalive澶勭悊</h3> <p>鍙傛?#26495;拰瀹?#28052;?/p> <pre><code><span class="hljs-hexcolor">#def</span>ine MAX_TCP_KEEPIDLE <span class="hljs-number">32767</span> <span class="hljs-hexcolor">#def</span>ine MAX_TCP_KEEPINTVL <span class="hljs-number">32767</span> <span class="hljs-hexcolor">#def</span>ine MAX_TCP_KEEPCNT <span class="hljs-number">127</span> <span class="hljs-hexcolor">#def</span>ine MAX_TCP_SYNCNT <span class="hljs-number">127</span> <span class="hljs-hexcolor">#def</span>ine TCP_KEEPIDLE <span class="hljs-number">4</span> <span class="hljs-comment">/* Start keeplives after this period */</span> <span class="hljs-hexcolor">#def</span>ine TCP_KEEPINTVL <span class="hljs-number">5</span> <span class="hljs-comment">/* Interval between keepalives */</span> <span class="hljs-hexcolor">#def</span>ine TCP_KEEPCNT <span class="hljs-number">6</span> <span class="hljs-comment">/* Number of keepalives before death */</span> </code></pre><p>net/ipv4/Tcp.c?#32029;鍙?#28000;?#37813;?#37714;板?#29808;簲鍏?#32495;?#38171;?/p> <pre><code> <span class="hljs-keyword">case</span> <span class="hljs-string">TCP_KEEPIDLE:</span> val = (tp->keepalive_time ? : sysctl_tcp_keepalive_time) / HZ; <span class="hljs-keyword">break</span>; <span class="hljs-keyword">case</span> <span class="hljs-string">TCP_KEEPINTVL:</span> val = (tp->keepalive_intvl ? : sysctl_tcp_keepalive_intvl) / HZ; <span class="hljs-keyword">break</span>; <span class="hljs-keyword">case</span> <span class="hljs-string">TCP_KEEPCNT:</span> val = tp->keepalive_probes ? : sysctl_tcp_keepalive_probes; <span class="hljs-keyword">break</span>; </code></pre><p>?#22453;濮嬪寲锛?/p> <pre><code> <span class="hljs-keyword">case</span> <span class="hljs-type">TCP_KEEPIDLE</span>: <span class="hljs-keyword">if</span> (<span class="hljs-function"><span class="hljs-keyword">val</span> <span class="hljs-title"><</span> 1 <span class="hljs-title">||</span> <span class="hljs-title">val</span> <span class="hljs-title">></span> <span class="hljs-title">MAX_TCP_KEEPIDLE</span>) </span> err = -<span class="hljs-type">EINVAL</span>; <span class="hljs-keyword">else</span> { tp->keepalive_time = <span class="hljs-function"><span class="hljs-keyword">val</span> <span class="hljs-title">*</span> <span class="hljs-title">HZ</span>;</span> <span class="hljs-keyword">if</span> (sock_flag(sk, <span class="hljs-type">SOCK_KEEPOPEN</span>) && !((<span class="hljs-number">1</span> << sk->sk_state) & (<span class="hljs-type">TCPF_CLOSE</span> | <span class="hljs-type">TCPF_LISTEN</span>))) { __u32 elapsed = tcp_time_stamp - tp->rcv_tstamp; <span class="hljs-keyword">if</span> (tp->keepalive_time > elapsed) elapsed = tp->keepalive_time - elapsed; <span class="hljs-keyword">else</span> elapsed = <span class="hljs-number">0</span>; inet_csk_reset_keepalive_timer(sk, elapsed); } } <span class="hljs-keyword">break</span>; <span class="hljs-keyword">case</span> <span class="hljs-type">TCP_KEEPINTVL</span>: <span class="hljs-keyword">if</span> (<span class="hljs-function"><span class="hljs-keyword">val</span> <span class="hljs-title"><</span> 1 <span class="hljs-title">||</span> <span class="hljs-title">val</span> <span class="hljs-title">></span> <span class="hljs-title">MAX_TCP_KEEPINTVL</span>) </span> err = -<span class="hljs-type">EINVAL</span>; <span class="hljs-keyword">else</span> tp->keepalive_intvl = <span class="hljs-function"><span class="hljs-keyword">val</span> <span class="hljs-title">*</span> <span class="hljs-title">HZ</span>;</span> <span class="hljs-keyword">break</span>; <span class="hljs-keyword">case</span> <span class="hljs-type">TCP_KEEPCNT</span>: <span class="hljs-keyword">if</span> (<span class="hljs-function"><span class="hljs-keyword">val</span> <span class="hljs-title"><</span> 1 <span class="hljs-title">||</span> <span class="hljs-title">val</span> <span class="hljs-title">></span> <span class="hljs-title">MAX_TCP_KEEPCNT</span>) </span> err = -<span class="hljs-type">EINVAL</span>; <span class="hljs-keyword">else</span> tp->keepalive_probes = <span class="hljs-function"><span class="hljs-keyword">val</span>;</span> <span class="hljs-keyword">break</span>; </code></pre><p>杩?#38322;屽彲浠?#37813;?#37714;板閮?#37714;嗗?#21229;悊閫昏緫?#32029;net/ipv4/Tcp_timer.c:</p> <pre><code class="lang-C"><span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">tcp_keepalive_timer</span> <span class="hljs-params">(unsigned <span class="hljs-keyword">long</span> data)</span> </span>{ <span class="hljs-keyword">struct</span> sock *sk = (<span class="hljs-keyword">struct</span> sock *) data; <span class="hljs-keyword">struct</span> inet_connection_sock *icsk = inet_csk(sk); <span class="hljs-keyword">struct</span> tcp_sock *tp = tcp_sk(sk); __u32 elapsed; <span class="hljs-comment">/* Only process if socket is not in use. */</span> bh_lock_sock(sk); <span class="hljs-keyword">if</span> (sock_owned_by_user(sk)) { <span class="hljs-comment">/* Try again later. */</span> inet_csk_reset_keepalive_timer (sk, HZ/<span class="hljs-number">20</span>); <span class="hljs-keyword">goto</span> <span class="hljs-keyword">out</span>; } <span class="hljs-keyword">if</span> (sk->sk_state == TCP_LISTEN) { tcp_synack_timer(sk); <span class="hljs-keyword">goto</span> <span class="hljs-keyword">out</span>; } <span class="hljs-comment">// 鍏?#38338;姸鎬?#37928;勫?#21229;悊</span> <span class="hljs-keyword">if</span> (sk->sk_state == TCP_FIN_WAIT2 && sock_flag(sk, SOCK_DEAD)) { <span class="hljs-keyword">if</span> (tp->linger2 >= <span class="hljs-number">0</span>) { <span class="hljs-keyword">const</span> <span class="hljs-keyword">int</span> tmo = tcp_fin_time(sk) - TCP_TIMEWAIT_LEN; <span class="hljs-keyword">if</span> (tmo > <span class="hljs-number">0</span>) { tcp_time_wait(sk, TCP_FIN_WAIT2, tmo); <span class="hljs-keyword">goto</span> <span class="hljs-keyword">out</span>; } } tcp_send_active_reset(sk, GFP_ATOMIC); <span class="hljs-keyword">goto</span> death; } <span class="hljs-keyword">if</span> (!sock_flag(sk, SOCK_KEEPOPEN) || sk->sk_state == TCP_CLOSE) <span class="hljs-keyword">goto</span> <span class="hljs-keyword">out</span>; elapsed = keepalive_time_when(tp); <span class="hljs-comment">/* It is alive without keepalive 8) */</span> <span class="hljs-keyword">if</span> (tp->packets_out || sk->sk_send_head) <span class="hljs-keyword">goto</span> resched; elapsed = tcp_time_stamp - tp->rcv_tstamp; <span class="hljs-keyword">if</span> (elapsed >= keepalive_time_when(tp)) { <span class="hljs-keyword">if</span> ((!tp->keepalive_probes && icsk->icsk_probes_out >= sysctl_tcp_keepalive_probes) || (tp->keepalive_probes && icsk->icsk_probes_out >= tp->keepalive_probes)) { tcp_send_active_reset(sk, GFP_ATOMIC); tcp_write_err(sk); <span class="hljs-comment">// 鍚戜?#23106;眰搴?#37922;?#23033;?#37814;?#26473;?#37818;?#23534;傚父</span> <span class="hljs-keyword">goto</span> <span class="hljs-keyword">out</span>; } <span class="hljs-keyword">if</span> (tcp_write_wakeup(sk) <= <span class="hljs-number">0</span>) { icsk->icsk_probes_out++; <span class="hljs-comment">// 杩?#38322;?#28000;?#28000;?#37828;?#29825;?#37825;帮紝?#33503;?#30149;鏈?#37712;嶆鍙?#38315;佷繚娲?#37818;?#23092;嬪寘</span> elapsed = keepalive_intvl_when(tp); } <span class="hljs-keyword">else</span> { <span class="hljs-comment">/* If keepalive was lost due to local congestion, * try harder. */</span> elapsed = TCP_RESOURCE_PROBE_INTERVAL; } } <span class="hljs-keyword">else</span> { <span class="hljs-comment">/* It is tp->rcv_tstamp + keepalive_time_when(tp) */</span> elapsed = keepalive_time_when(tp) - elapsed; } TCP_CHECK_TIMER(sk); sk_stream_mem_reclaim(sk); resched: inet_csk_reset_keepalive_timer (sk, elapsed); <span class="hljs-keyword">goto</span> <span class="hljs-keyword">out</span>; death: tcp_done(sk); <span class="hljs-keyword">out</span>: bh_unlock_sock(sk); sock_put(sk); } </code></pre> <p>keepalive_intvl_when 鍑?#37825;?#28729;?#28052;?#38171;?/p> <pre><code><span class="hljs-function"><span class="hljs-keyword">static</span> inline <span class="hljs-keyword">int</span> <span class="hljs-title">keepalive_intvl_when</span><span class="hljs-params">(<span class="hljs-keyword">const</span> <span class="hljs-keyword">struct</span> tcp_sock *tp)</span> </span>{ <span class="hljs-keyword">return</span> tp->keepalive_intvl ? : sysctl_tcp_keepalive_intvl; } </code></pre><h3 id="-tcp-keepalive-">鍥?#37510;俆CP Keepalive 寮?#37721;?#37928;勯敊璇?/h3> <p>鍚?#37922;TCP Keepalive鐨勫簲鐢?#32459;嬪簭?#32029;?#31476;鑸?#37721;?#28000;?#37817;曡幏鍒?#28051;嬮潰?#22161;绉?#32491;诲?#23342;敊璇?/p> <ol> <li>ETIMEOUT 瓒呮椂?#25930;璇紝鍦?#37721;?#38315;佷竴涓?#37818;?#23092;嬩繚鎶?#37718;?#32513;?#26473;?tcp_keepalive_time + tcp_keepalive_intvl * tcp_keepalive_probes)?#26882;闂村悗浠嶇劧?#30149;鏈夋帴鏀?#37714;ACK纭?#29825;?#37807;?#37712;?#28051;嬭鍙?#37928;勫?#20634;父?#32029;濂?#37818;?#28699;楄鍏?#38338;?pre><code>java<span class="hljs-class">.io</span><span class="hljs-class">.IOException</span>: Connection timed out </code></pre></li> <li>EHOSTUNREACH host unreachable(涓?#37832;?#28051;嶅彲杈??#25930;璇紝杩?#28051;?#25652;旇鏄疘CMP姹?#37814;?#32513;?#28051;婂眰搴?#37922;?#37928;?#37510;?pre><code>java<span class="hljs-class">.io</span><span class="hljs-class">.IOException</span>: No route to host </code></pre></li> <li>閾?#37818;?#29722;噸缃紝?#31891;绔?#37721;?#38003;藉穿婧冩鏈洪噸鍚?#28052;嬪悗?#32029;鎺?#37824;?#37714;版潵鑷?#37832;?#37716;?#37731;?#37928;?#37814;?#37826;囷紝?#21159;鐗?#37828;?#27996;洪潪?#32029;鍓?#37832;?#23536;浜嬶紝鍙兘鎶?#28000;?#37827;犲?#22565;噸缃?#28729;?#37723;?#28052;?#37510;?pre><code>java<span class="hljs-class">.io</span><span class="hljs-class">.IOException</span>: Connection reset by peer </code></pre></li> </ol> <h3 id="-">浜?#37510;傚父瑙?#37928;?#28003;?#37922;?#22959;?#23534;?/h3> <ol> <li>榛?#29825;?#37807;?#37712;?#28051;?#28003;?#37922;keepalive鍛?#37832;熶负2涓?#28751;忔椂?#32029;濡?#28051;?#38315;夋嫨?#27967;鏀癸紝灞?#27996;?#29831;?#37922;?#38012;冪?#36798;紝閫?#37812;?#29863;勬簮娴?#29840;?#38171;?#37712;?#37837;?#28028;氫负姣忎竴涓?#26473;?#37818;?#38318;?#37813;?#23534;?#31476;涓繚娲?#29825;椂鍣紝N涓?#26473;?#37818;?#28028;?#37813;?#23534;N涓繚娲?#29825;椂鍣?#37510;? 浼?#37716;?#23536;?#37828;?#37828;?#38171;?/li> </ol> <ul> <li>TCP鍗?#29825;眰?#28528;?#32346;娲?#37818;?#23092;?#37832;?#37714;讹紝绯?#32513;?#37712;?#37837;?#28729;屽叏鏇?#28051;婂眰搴?#37922;?#38007;?#37716;?#32513;?#37707;氬浜?/li> <li>鍐?#37837;稿眰?#28528;璁椂鍣?#37929;?#23011;?#28051;婂眰搴?#37922;紝?#27967;?#36127;楂?#37825;?/li> <li>涓婂眰搴?#37922;?#37721;渶瑕?#28598;勭悊鏁版嵁鏀?#37721;?#37510;?#26473;?#37818;?#23534;傚父閫氱煡鍗?#37721;?/li> <li>鏁版嵁鍖?#28751;嗘洿?#36127;?#25571;鍑?/li> </ul> <ol> <li>鍏?#38338;TCP鐨刱eepalive?#32029;瀹屽叏浣?#37922;?#28051;?#37716;眰?#28528;?#32318;璺充繚娲?#37832;?#37714;? 瀹屽叏搴?#37922;?#37818;?#32480;績璺筹紝鐏垫椿鍜屽彲鎺紝姣斿?#20635;?#24526;竴涓?#26473;?#37818;績璺?#37723;?#37832;?#37928;勫彲鏍规嵁?#28214;瑕?#37713;?#28751;?#37812;栧欢闀?/li> <li>涓?#37716;績璺?+ TCP keepalive?#31476;璧?#28003;?#37922;紝浜?#37929;镐綔?#36127;琛?#37711;咃紝浣員CP?#32346;娲?#37818;?#23092;嬪懆鏈熷?#23677;簲鐢?#37928;勫績璺?#37723;?#37832;?#29781;?#37719;忚皟?#32029;浠?#27996;?#29723;?#37826;瑰彲?#32029;涓嶈?#34249;宸?#29882;?#26473;囧?#32029;鍚?#37714;?#28751;嗚揪涓?#37714;?#29825;炬兂鐨?#37825;堟灉銆傛?#23338;鐨勫叕鍙?#37813;?#20187;IM骞?#37721;?#28051;?#37716;績璺?-5鍒嗛?#29112;?#40511;兘?#30367;鏁?+ tcp keepalive 300绉掞紝缁勫?#22557;?#24526;綔?#32029;?#23873;璇?#37825;堟灉涔?#28051;嶉敊銆?/li> </ol> <p>?#27367;?#21159;璇存病鏈夊浐瀹?#37928;勬寮忓彲閬?#23536;紝閭?#28052;?#37832;?#28000;?#28051;嬪師鍒?#37721;?#28000;?#37721;傝?#38171;?/p> <ul> <li>涓嶆兂鎶樿?#25733;紝閭?#28751;?#23534;?#37922;TCP Keepalive鍚紝瀹屽叏渚?#29863;?#25652;?#37922;眰?#32318;璺?#37832;?#37714;讹紝鐏垫椿鍙?#37818;?#37804;?#23534;?/li> <li>闄?#38344;炲彲浠?#23536;堝鎶?#37818;TCP Keepalive鏈?#37714;讹紝閭?#28751;?#37721;?#28000;?#37837;规嵁?#28214;瑕?#38007;?#37922;?#28003;?#37922;?#37722;?/li> </ul> <h3 id="-http-keep-alive-">鍏?#37510;傛敞鎰忓拰 HTTP鐨凨eep-Alive鍖?#37714;?/h3> <ul> <li>HTTP鍗?#29825;?#37928;凨eep-Alive鎰?#37733;?#37734;?#27996;?#26473;?#37818;?#28598;?#37922;紝鍚屼竴涓?#26473;?#37818;?#28051;?#28051;?#29723;屾柟寮?#28028;?#38315;?#29831;锋眰-鍝嶅簲鏁版嵁</li> <li>TCP鐨刱eepalive鏈?#37714;?#37808;?#37733;?#37734;?#27996;庝繚娲?#37510;佸績璺筹紝妫娴?#26473;?#37818;敊璇?#37510;?/li> </ul> <h3 id="-">涓?#37510;?#23534;?#37922;?/h3> <ol> <li><a href="http://www.netis.com.cn/flows/2012/11/tcpkeepalive/">鎴戞潵璇?#29831;碩CP?#32346;娲?/a></li> <li><a href="http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/">TCP Keepalive HOWTO</a></li> </ol> </div><img src ="http://www.8634070.com/yongboy/aggbug/424413.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.8634070.com/yongboy/" target="_blank">nieyong</a> 2015-04-14 17:08 <a href="http://www.8634070.com/yongboy/archive/2015/04/14/424413.html#Feedback" target="_blank" style="text-decoration:none;">鍙?#29723;?#29831;?#29825;?/a></div>]]></description></item><item><title>绉?#37716;APP鍚?#32468;?#32515;戠粶澶勭?#21973;竴浜?#38338;?#26864;?#29825;板綍http://www.8634070.com/yongboy/archive/2015/03/30/423963.htmlnieyongnieyongMon, 30 Mar 2015 09:11:00 GMThttp://www.8634070.com/yongboy/archive/2015/03/30/423963.htmlhttp://www.8634070.com/yongboy/comments/423963.htmlhttp://www.8634070.com/yongboy/archive/2015/03/30/423963.html#Feedback2http://www.8634070.com/yongboy/comments/commentRss/423963.htmlhttp://www.8634070.com/yongboy/services/trackbacks/423963.html

?#27970;銆?#37715;嶈

杩?#38322;?#29825;?#37928;勭鍔APP涓?#29781;佹寚鐨?#37828;?#28729;?#37719;?#39582;?#37721;帮紝澶?#38318;?#37714;嗘儏鍐?#28052;?#38315;?#37922;?#27996;嶪OS绛?#32457;?#37716;?#39582;?#37721;帮紝鍙兘?#22136;?#20579;鍢?#28028;?#37734;?#37722;?#37719;?#38318;?#37714;嗗憿銆?/p>

?#31476;銆傚?#23677;叆澶SDK瀛?#37734;?#37928;勯?#24877;偅

浣嗗嚒?#31476;涓父鐢?#37928;凙PP閮?#28028;氬?#23677;叆鑷?#28751;戜竴涓猄DK?#32029;涓?#37722;屾潵?#31790;鎴?#37722;屼竴?#28533;?#31790;?#32029;鏈夊鍛SDK?#32029;鏈夋帹閫丼DK?#32029;鏈夋兘姹?#37814;SDK?#32029;鏈?#37922;埛璺熻釜SDK?#32029;鏈?#32513;?#29825;?#23092;侀噺SDK绛夛紝鏈夋敮浠楽DK绛?#32475;?#37510;傝櫧?#21159;甯潵浜?#37716;熻兘鐨勫鐢?#37724;岃鑰紝渚?#27996;?#32510;?#37722;戞墿灞曪紝浣嗗彲?#20824;浼?#28699;?#37734;?#38171;?/p>

  1. ?#31476;涓猄DK鍙?#28000;?#37930;嬪?#27691;竴涓?#37722;?#37721;癝ervice?#32029;澶?#28051;猄DK澶?#28051;猄ervice瀛?#37734;?#38171;堢矖鐣?#28051;?#29825;?#32480;?#38171;?
  2. 杩?#29723;岀?#25780;參鐨?#38338;?#26864;橈紝澶?#28051;猄DK鎴?#28598;?#37716;熻兘鐨勬?#28513;锛堣嫢涓嶆?#22800;渶鍔犺浇鐨?#29831;?#38171;変細瀵?#38007;?#26473;?#29723;岀?#25780;參?#32029;绗?#37722;?#37832;?#22935;剁悊璁猴紝鏈鎱?#37928;?#38317;?#28051;?#37815;?#37809;?#27996;嗘?#28003;撴浼?
  3. 姣忎竴涓猄DK閮?#37832;?#38007;?#23480;?#37837;稿績璇夋眰?#32029;鍚?#38007;负鏀匡紝瀹?#37916;?#37826;?#23534;?#37722;勫紓銆傛?#28003;?#37835;?#37835;?#37828;?#37722;?#37722;?#38315;傦紝甯潵浜嗛?#24876;舰鐨勫吋瀹规垚鏈?
  4. 褰?#23005;?#37719;忚皟杩愪綔鍏?#28729;规?#38338;?#26864;橈紝?#31476;鏃?#37713;虹?#29256;煇涓?#38341;?#37722;獴UG?#32029;浼?#28051;?#28028;?#28725;?#38007;?#26473;為攣鍙嶅簲
  5. CPU銆?#37712;?#28699;?#37510;佺?#25120;粶绛?#29863;勬簮绔?#27996;?#38338;?#26864;橈紝?#20802;鍗忚皟閮?#23536;堥毦
  6. 缃戠粶璧勬簮鍚?#38007;负鏀匡紝鏃犳硶鍏?#27996;紝?#27967;涓?#37922;彁杩?#37818;?#28598;?#37922;?

?#23266;鏄?#37722;屼竴?#28533;?#31790;鐨凷DK?#32029;?#32139;闂?#26864;?#37721;戠敓鐨勬椂鍊?#26473;?#38003;藉鏈夋墍鍗忎綔绋嶄綔?#30367;鏁达紝?#27367;?#21159;杩?#28052;?#37828;?#23011;旇緝鐞嗘兂鐨勬儏鍐?#37510;?#28598;?#38318;?#37928;凷DK鍙兘闂?#26864;?#37721;嶉?#22557;拰BUG淇?#23005;紝?#26882;鏁堟?#28751;?#28051;嶅濂?#29831;?#27996;?#37510;?/p>

瑙?#38000;櫧?#21159;甯潵浜?#37716;熻兘鐨?#37813;?#28766;曟紝甯殢涔嬪甫?#28533;浜?#29863;勬簮鍒?#37922;?#37826;归潰鐨?#38322;嶅?#23941;?#23678;氮璐癸紝鎰堝鐨凷DK宓屽叆瓒?#37832;?#37721;兘瀵?#38007;存?#28003;?#26473;?#29723;岀?#25780;參?#32029;?#28214;瑕佽皑鎱?#28003;?#37922;?#37510;?/p>

浜?#37510;侫PP鍚?#37721;癝ervice鏁伴噺寰堝

?#31476;鑸?#28729;?#37719;撴墜鏈?#28028;氭?#24874;緵鍚?#37721;?#26473;?#32459;?#37928;勬煡鐪嬶紝?#31476;鑸珹PP浼?#37722;?#37716;?#28598;?#28051;?#37722;?#37721;?#37832;?#37716;紝姣斿?#20636;埍濂囪壓APP灏?#23536;堝彉鎬侊紝5涓?#37832;?#37716;?#28699;?#37734;?#38171;堜閰APP涔熷涓?#27996;嗗鍘伙紝3-4涓?#37832;?#37716;?#28699;?#37734;?#38171;?#38171;?/p>

?#31476;鑸緝澶?#37711;?#37721;革紝閮?#28028;?#38007;?#23480;?#23534;鍙慡DK?#32029;浣?#32432;?#27996;KPI绛?#28051;?#32513;?#38000;?#37837;革紝寰堝皯鏈?#27996;?#28028;?#29825;?#37930;?#28000;庢?#28003;?#28051;?#38000;?#38095;戞妸澶?#28051;猄erice鏈?#37716;?#37722;堝?#26421;负?#31476;涓紝鑺傜?#20343;竴?#20579;鐢埛鐨勮?#21228;簮鍗?#37922;紝涓嶈繃閭渶瑕佽?#26976;岀爺鍙戜汉鍛?#37928;?#37835;?#37835;勮兘鍔?#27996;?#37510;?/p>

?#27367;?#21159;灏忕櫧鐢埛涓嶄竴瀹?#28028;?#37836;?#37930;嬪悗鍙?#37832;?#37716;紝浣嗚嫢骞?#28051;?#37722;?#37721;?#37832;?#37716;紝姣忎竴涓?#38318;介渶瑕佺淮鎶?#38007;韩鏈?#37716;?#28699;樻?#32472;娴嬶紝姣忎竴涓?#38318;?#28028;?#37719;?#37922;嫢骞?#37712;?#28699;橈紝?#23266;鍚堝?#26421;负?#31476;涓紝鑷劧鍑?#28751;戜簡CPU鍗?#37922;?#37724;屽唴瀛?#29863;勬簮鍗?#37922;紝浠?#37721;婄淮鎶?#37812;?#37832;紝杩?#37828;?#37832;?#27996;?#28751;忓繀瑕?#37928;?#37510;?/p>

涓?#37510;侶TTP鐭?#26473;?#37818;?#29831;锋眰杩?#27996;庨?#25120;箒

?#31476;鑸潵璁诧紝鎵?#23534;?#31476;涓狝PP鐨勬椂鍊欙紝閫?#26473;Wireshark鎶?#37718;?#23480;?#37711;?#37721;?#28000;?#37930;嬪?#25292;嫢骞?#28051;狧TTP杩?#37818;?#37932;?#38338;村?#34425;?#23350;紝璇稿?#20635;窐瀹濓紝澶尗?#32029;缇?#37733;紝浼?#38320;?#32475;堿PP?#32029;婊?#28766;?#37928;?#38318;?#37828;HTTP璇锋眰?#32029;鐪嬬潃璁?#27996;?#37808;?#29785;?#37832;?#27996;?#28751;?#37805;?#37804;栵紝涓?#37716;?#37825;版嵁銆?#29825;?#28598;囦俊鎭?#28051;?#28028;?#37510;丼DK?#20426;鎭?#37814;?#37721;?#37510;?#37737;嬬偣璺熻釜銆?#28598;村鍥?#37911;?#37510;丠TML璧勬簮绛夛紝閭?#37721;竴涓?#25652;?#28598;?#37510;?/p>

浣?#28052;熸病鍔炴硶?#32029;涓?#37716;?#28766;曠?#27946;偅涔?#28051;板瘜?#32029;?#28214;瑕佹秷鑰?#26473;囧鐨勮?#21228;簮銆?#28598;?#38318;?#37714;?#29831;锋眰閮藉彧涓?#23049;?#27996;庝竴閮?#37714;?#37825;版嵁銆傞?#22557;?#29808;崟?#31476;鏄?#32448;虹?#23684;潰灞忓?#26346;紝鍙?#28000;?#38315;?#26473;囦竴涓?#29831;锋眰?#24143;寰?#37722;堝苟鍚?#37928;勫?#23941;簲缁?#37835;滐紝鍑?#28751;戠?#25120;粶璧勬簮?#31223;鑰?#37510;?/p>

?#22684;鏈烘窐瀹?#37724;屾墜鏈篞Q?#32029;鍦HTTP璇锋眰浼?#37718;?#37826;归潰?#32029;宸?#32513;?#37734;?#28003;?#37922;IP鐩?#26473;?#37510;丠TTP闀?#26473;?#37818;?#37510;丼PDY绛?#26473;?#29723;屽姞閫熷?#21229;?#21997;紝鍊?#23536;?#28699;範銆?/p>

鍥?#37510;俆CP闀?#26473;?#37818;?#37714;?#37922;?#37916;?#28051;嶉珮

杩?#38322;屾墍璇撮暱杩?#37818;紝鏇村鐨?#37828;?#37816;嘥CP鏂?#23534;?#26473;?#37818;紝涔熷寘鎷HTTP鏂?#23534;?#37928;勯暱杩?#37818;紝浣嗘?#26449;?#27693;寚鐨?#37828;?#37711;?#37832;?#37721;屽悜閫?#38316;?#37928;勯暱杩?#37818;?#37510;?#37719;?#38315;?#38316;?#37928;?#37826;?#23534;忥紝鍗?#29825;?#37813;闄愶紝璧勬簮鍒?#37922;?#37916;?#28051;?#37828;?#38317;?#28052;堥珮銆?/p>

?#32139;鍓峊CP闀?#26473;?#37818;?#37734;?#37711;?#28699;樻椿鏈?#38338;达紝澶?#38318;藉彧涓?#23049;?#27996;?#28028;犺緭?#31476;绫?#37711;?#28003;?#28051;?#37716;?#37712;?#28729;癸紝姣斿?#20414;USH鎺?#38315;侊紝?#31476;鍙版墜鏈?#26473;?#37818;竴澶紝涔熸帴鏀?#28051;?#27996;嗗嚑鏉?#23057;堟伅?#32029;鏈棰戠箒鐨勫氨鏄績璺充繚娲?#37825;版嵁鍖呬紶閫佷簡銆?/p>

?#31476;鏃秹鍙?#37714;版柊鐨?#28051;?#37716;紝澶?#28729;?#38318;?#37828;?#29781;佹?#26495;缓?#31476;鏉?#37711;柊TCP杩?#37818;紝褰?#23005;?#28051;?#37716;?#28051;?#37711;?#38001;?#37730;涳紝鐪?#28051;婂幓寰?#38000;?#37722;堝?#23119;紝浣嗗嵈閫?#37812;愪簡浼佷笟澶噺鐨?#38322;嶅?#23944;?#21228;簮娴?#29840;?#38171;氭柊鐨?#28051;?#37716;渶瑕?#28598;勭?#21975;彟澶?#37928;?#26473;?#37818;?#37818;?#37711;紝璧勬簮閲嶅鎶?#37711;紝涓?#37716;眰?#28528;鍢涳紝涔?#28028;?#28699;?#37734;竴鍗?#23480;?#37721;?#37928;?#38322;嶅彔銆傚綋?#21159;?#32029;?#23266;涓嶅湪涔?#26473;?#27996;?#37928;?#29831;濓紝灏?#37721;綋鍒?#29825;?#27996;嗭紝浣?#37828;?#28003;?#29781;?#37828;?#38003;藉?#29110;负?#31223;璐?#38000;呮墜鏈?#37928;勮?#21228;簮?#31223;鑰?#38000;?#38095;戯紝閭?#28186;?#37828;?#37922;埛鐨勭?#24539;浜?#37510;?/p>

闀?#26473;?#37818;?#37928;?#28051;?#37716;眰?#28528;澶?#29882;?#28598;?#37922;紝鏀?#37816;佺被浼?#27996;庢?#22246;竴鎽?#37510;佹姠绾?#37718;?#37510;?#28729;?#37832;?#37510;?#28729;?#37832;嶅挩璇?#32475;夛紝鍚屼竴涓?#26473;?#37818;?#28028;犺緭涓?#37722;岀?#35826;瀷鐨?#37825;版嵁?#32029;鍗?#38010;傜?#20343;簡鏈?#37716;?#37731;?#29863;勬簮?#32029;鍙堟彁楂?#27996;?#32515;戠粶杩?#37818;?#37714;?#37922;?#37916;囷紝涓?#32468;?#37928;勭淮鎶?#37812;?#37832;?#38340;?#28003;?#37510;傞?#22557;瀹埛绔?#38000;岃?#32029;澶?#29882;?#28051;?#37716;?#28598;?#37922;?#37734;竴鏉TCP杩?#37818;?#28051;?#28028;犺緭?#32029;?#28214;瑕佷笟鍔?#29882;?#37922;?+ 鐩?#25652;?#28051;?#37716;?#28598;勭?#21975;嵆鍙?#37510;傛湇鍔?#37731;?#32468;?#37730;涳紝鎺?#37711;?#28051;?#37722;?#37928;?#28051;?#37716;?#28598;勭?#21997;紝渚?#38344;?#28051;?#37716;?#29882;?#37922;?#26473;?#29723;屾?#22559;伅鍒嗗彂銆?/p>

棰?#28598;?#29831;濓紝涓句竴涓?#28186;?#28699;愶紝骞虫椂浠讳竴?#26882;闂寸偣?#23475;3000鍗?#28051;?#37922;埛杩?#37818;紝鎸夋?#24531;彴鎺?00涓?#29825;?#32480;楋紝10-20鍙?#37832;哄櫒鎺?#37711;?#28598;勭悊瓒?#37721;紝鎺?#38315;佸?#23119;紝鑱?#28598;?#37727;婏紝瀹?#37832;嶅挩璇紝骞冲父鍐嶆潵?#31476;涓?#28610;?#26473;愭?#22246;竴鎽?#38318;?#29723;?#37510;傚?#26449;簳浜?#29781;佹墿瀹?#37714;?浜?#23480;?#37721;?#37922;埛鎽囧?#23107;憞鐨?#37814;?#28051;?#37814;?#29783;?#37814;?#32510;?#37718;咃紝杩?#37828;?#37722;屼竴涓?#26473;?#37818;?#37928;?#37826;?#23534;忥紝涓嶈?#22247;鍔?#27996;嗘柊鐨?#28051;?#37716;?#32491;诲瀷鏁版嵁浼?#38315;掞紝鏈?#37716;?#37731;?#37730;涳紝鎵?#28766;?#37714;?0-80鍙板氨寰圤K浜?#37510;?#37922;埛閲忎竴鏃?#38340;嶈?#26020;紝鎾?#28051;嬪浣?#37832;哄櫒灏?#29723;?#37510;傛垨璁革紝鏈?#32460;?#37721;?#28000;?#37712;欎竴?#30226;渚涗竴浜?#37922;埛鍦嚎鐨勭郴缁熸灦鏋?#37928;?#37826;规硶 :))

浜?#37510;侶TTP 鎸佷箙杩?#37818;?#28003;?#37922;?/h3>

閽堝HTTP/1.1鍙兘寰堝浜?#37928;勬濈淮鏂?#23534;忥紝杩樺仠鐣?#37734;?#23092;?#29785;堝櫒?#24134;澧冿紝?#31476;鑸?#23092;?#29785;堝櫒鏈?#28051;嶆敮鎸佹垨鏀?#37816;佷?#23941;?#29111;?#26020;紝浣嗗湪闈炴祻瑙堝櫒?#24134;澧?#28051;嬶紝閽堝?#31536;PP搴?#37922;?#37928;勭幆澧冿紝灏戜簡寰堝浼?#32513;熸祻瑙堝櫒?#24134;澧?#37928;?#38340;?#37714;讹紝浣?#29781;?#28729;屽叏鍙戞尌鍜岄噴鏀HTTP/1.1鍗?#29825;?#37813;甯潵鐨勬?#20343;箙鐗规紝杩欎?#22359;渶瑕佹繁搴悊瑙?#37719;?#29825;?#29785;勮寖鍜屽叿浣?#37928;?#28003;?#37922;幆澧?#32475;?#26473;?#29723;屾?#22795;嫨銆?/p>

1. HTTP/1.1 KeepAlive鐗规?#28003;?#37922;?/h4>

?#27367;璇HTTP/1.1 Keep-Alive鐗规?#37824;寔澶?#28051;?#29831;锋眰鍦?#37722;屼竴涓?#26473;?#37818;?#28051;?#37818;掗槦鍙?#38315;侊紝鍦?#23092;?#29785;堝櫒绔?#23005;父鐨凥TML绛?#29863;勬簮璇锋眰?#32029;浼氬甫?#28533;?#22158;澶?#38339;诲寮?#32468;紝鍚庝竴涓?#29831;锋眰渚?#29863;?#27996;?#37715;嶄竴涓?#29831;锋眰瀹?#37812;愶紝?#31476;鏃?#37713;虹?#20276;?#35826;?#28871;紝鍚?#32513;?#29831;锋眰鍙兘鎺掗槦绛?#23536;?#37510;?/p>

浣嗚嫢閽堝闈炴祻瑙堝櫒銆佷笟鍔?#22959;?#37736;?#28051;?#37828;?#23536;堝?#23942;潅鐨勭幆澧冿紝姣斿?#20635;棩?#32340;閲?#38342;?璺熻釜绛夊父瑙佷笟鍔紝灞?#27996;?#32480;鍗?#23536;幆鐨?#29831;锋眰-鍝嶅簲妯?#37736;嬶紝鍝嶅簲浠?#28000;呴渶瑕丠TTP 200?#23032;鎬佺爜鍗?#37721;?#38171;?#26473;?#29781;佹?#20635;湇鍔?#37731;?#32468;?#37818;?#37824;?#28052;嬪悗寮傛澶勭悊鐩?#37818;?#26473;?#37733;?00?#23032;鎬?#38171;夛紝鍚?#32513;?#37928;?#29831;锋眰鍙渶瑕佹帓闃燂紝?#33503;涓?#28051;?#28028;?#28725;瑰欢杩?#37832;夎鍒?#29781;佹眰?#32029;閭?#28052;圞eep-Alive鐗规?#28751;?#23536;?#38315;?#37722;?#37510;備竴鑸?#37713;虹?#20276;?#35826;?#28871;紝閭?#28751;?#37808;忓?#23815;潃缃戠粶?#23032;鍐?#28051;?#28729;?#28052;?#29785;傦紝鍏?#38338;劧鍚庨?#23945;敭?#31476;涓狧TTP鎸佷箙杩?#37818;?#28751;?#29723;?#37510;?/p>

鏈?#27996;涚幆澧冿紝鍙渶瑕?#37721;?#38315;?#37825;版嵁?#32029;瀹埛绔?#28051;?#37711;冲績鏈夋病鏈夊?#23941;簲锛?#37812;?#28051;嶆帴鏀跺?#23941;簲锛夛紝绫?#28028;?#27996;嶶DP鐨?#37826;?#23534;忥紝姣斿瀹炴椂鏃織锛堢獊鍑?#28729;炴椂鐗规?#38171;夛紝浣?#26473;欓渶瑕?#28729;埛绔?#23534;傛澶勭?#21975;?#23941;簲銆?/p>

?#31476;鑸?#29785;嗛?#25120;綉绔?#38318;?#28028;?#37832;?#28729;炴椂璺熻釜鐢埛姝?#37734;?#37822;?#37824;?#28051;?#37928;勮?#21979;?#25118;鏀剧姸鎬侊紝閭?#28751;遍渶瑕佸?#34425;珛?#31476;涓?#37816;佷箙鐨凥TTP/1.1杩?#37818;紝鍗虫椂銆佹?#20346;画浼?#38315;?#29785;嗛瑙傜湅浜?#28000;讹紝鑷劧灏遍伩鍏?#27996;?#37933;?#26473;?#37818;?#28598;氭鍒涘缓銆?#37711;?#38338;?#37928;勫紑閿銆?/p>

2. HTTP/1.1 Pipelining

寤虹?#23338;湪Keep-Alive鎸佷箙鍖?#37737;虹涔?#28051;婏紝涓?#37826;?#29831;戜负绠嚎鍖栵紝鏀寔杩?#32513;?#37928;勫?#20636;瓑鐨凣ET/HEAD鏂规?#26337;?#38155;眰?#32029;瀹?#38340;呯幆澧?#28051;嬶紝?#33503;?#30149;鏈夎娴?#29785;堝櫒鎵鏀寔銆?/p>

鍚屼竴涓?#26473;?#37818;紝澶勭悊鍚屾牱鐨?#28051;夋璇锋眰-鍝嶅簲?#32029;Keep-Alive鍜孭ipelining鏂?#23534;?#28051;?#37722;?#38171;?/p>

娴?#29785;堝櫒?#24134;澧?#28051;嶆敮?#23508;鐨勭?#35268;紝鍦?#25652;?#37922;幆澧?#28051;?#37812;?#29825;?#37721;?#28000;?#37813;?#37714;板叾閫?#37922;?#32460;?#38338;淬傛?#26047;鍏?#37832;?#38315;?#26473;GET鏂?#23534;忔?#24874;氦鏁版嵁鐨勬儏鍐?#38171;堟?#26047;GET鏂?#23534;?#23033;?#37814;?#37734;扮悊浣?#32515;紝GET鏂?#23534;忔?#24874;氦鐢埛璁?#28598;囦俊鎭紝GET鏂?#23534;?#23033;?#37814;?#37922;埛?#22684;鏈?#37814;?#37716;?#37807;?#37712;?#32475;?#38171;夛紝澶?#28051;?#29831;?#23033;傛壒閲忓彂閫?#37510;?/p>

浣嗘崲?#31476;涓?#37804;濈淮鏂?#23534;忥紝?#23266;鑳藉鍚堝苟鎵归噺璇锋眰?#36127;?#31476;涓狿OST鎻愪氦?#32029;涓嶈蛋绠嚎鍖?#37826;?#23534;忥紝鍙兘浼?#37831;村悎閫備竴浜?#37510;?/p>

閽堝涓嶅閲嶈鏁版嵁?#32029;鍙?#38315;?#28729;屾?#26346;紝涓?#37922;?#32475;?#23536;呭?#23941;簲銆?/p>

3. HTTP/2

?#23266;?#20802;浜?#29785;HTTP/2鐨勮?#21230;寖?#32029;鍙?#28000;?#37721;傝?#37832;崥瀹?#37928;勫叾瀹?#37826;?#28699;?#37510;傜洰鍓?#28729;埛绔?#25652;?#37724;?#37832;?#37716;?#37731;?#32468;?#25652;擄紝鏀寔閮?#28051;嶅濂斤紝?#28214;瑕佽瀵熶竴娈垫椂闂达紝鍏?#37721;?#28729;?#37716;?#28598;燂紝瀹屽叏鍙?#28000;?#38007;?#28051;?#23534;鍙戯紝鎴栧熀浜嶴PDY 2.0涔熷彲?#32029;?#27952;鍓嶆窐瀹滱PP銆佽吘璁墜QQ绛夛紝涔?#38318;藉湪浣?#37922;?#37510;?/p>

HTTP/1.1鑳藉瀹屽叏瑙?#37712;?#37928;?#38338;?#26864;橈紝灏辨病鏈夊繀瑕佷娇鐢HTTP/2?#32029;鍚庤?#38315;?#37812;愪簡瀹?#37916;?#37832;?#27996;?#28598;嶆潅?#32029;鍙兘涓?#28000;?#29825;?#28598;?#38171;堢綉鍏?#37510;佷唬?#24714;銆丆DN绛?#38171;?#38318;?#26473;樻病鏈変负涔嬪?#27692;?#34249;?#21975;?#22247;憿?#32029;浣咹TTP/2姣?#32468;?#37828;?#29906;嬪娍銆?/p>

?#27367;?#21159;瑙勮寖鍙?#28729;?#28052;変竴涓狧ostname鍙?#37711;?#29825;镐竴涓?#26473;?#37818;紝鍙兘瀹?#38340;?#37807;?#37712;?#28051;?#28028;氶渶瑕?-3鏉?#38336;?#26473;?#37818;?#28000;?#27996;?#28598;鸿緝澶?#37928;勭?#25120;粶甯?#28729;?#29863;勬簮銆?/p>

鍏?#37510;?#28751;?#32513;?/h3>

鎬?#28052;?#29831;村憿?#32029;鍦綋鍓?#32457;?#37716;APP?#24134;澧?#28051;?#38171;?/p>

  • TCP闀?#26473;?#37818;?#37928;?#38315;?#38316;?#37922;?#38315;?#37928;?#28028;犺?#25780;綔鍔?#37724;屽埄鐢?#37916;?#23536;?#28003;?
  • HTTP/1.1鐨勬?#20343;箙鐗规?#23536;?#28729;规槗琚?#27996;哄?#30028;暐?#32029;鏈兘姝?#32429;?#28003;?#37922;?
  • HTTP/2澶?#29882;?#28598;?#37922;?#37706;?#23536;?#37832;?#23536;?

?#26852;璁哄?#31476;绉?#37826;?#23534;忥紝閮介渶瑕佺?#29112;倝鍗?#29825;?#37724;?#32515;戠粶?#32029;閫?#37722;?#37928;勭幆澧?#28003;?#37922;?#38315;?#37722;?#37928;勫崗璁?#37911;规紝鎵嶈?#34249;?#29111;?#25118;尌鍑烘綔鍦?#37928;勬?#38003;藉?#28888;潵銆?/p>

]]>HTTP/2绗?#29825;?#28052;嬮敊璇?#28598;勭?#21975;拰瀹?#37711;?/title><link>http://www.8634070.com/yongboy/archive/2015/03/24/423791.html</link><dc:creator>nieyong</dc:creator><author>nieyong</author><pubDate>Tue, 24 Mar 2015 07:27:00 GMT</pubDate><guid>http://www.8634070.com/yongboy/archive/2015/03/24/423791.html</guid><wfw:comment>http://www.8634070.com/yongboy/comments/423791.html</wfw:comment><comments>http://www.8634070.com/yongboy/archive/2015/03/24/423791.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.8634070.com/yongboy/comments/commentRss/423791.html</wfw:commentRss><trackback:ping>http://www.8634070.com/yongboy/services/trackbacks/423791.html</trackback:ping><description><![CDATA[<div class="wrap"> <h3 id="-">?#27970;銆?#37715;嶈</h3> <p>杩?#38322;?#37825;寸悊浜嗕竴涓嬮敊璇?#37724;?#28729;?#37711;?#37929;?#37711;?#38318;?#37714;?#32480;鍗?#29825;板綍銆?/p> <h3 id="-http-2-">?#31476;銆侶TTP/2?#25930;璇?/h3> <h4 id="1-">1. ?#25930;璇?#28729;?#28052;?/h4> <p>HTTP/2瀹?#28052;?#27996;?#28051;?#32457;?#32491;诲?#23342;敊璇?#38171;?/p> <ul> <li>瀵?#38007;?#37825;?#28051;?#26473;?#37818;?#28051;嶅彲浣?#37922;?#37928;勯敊璇负杩?#37818;敊璇?connection error) </li><li>鍗曠嫭鍑虹?#26495;湪鍗?#28051;?#26473;?#37818;?#28051;?#37928;勯敊璇负娴侀敊璇?stream error) </li></ul> <h4 id="2-">2. ?#25930;璇?#28000;?#37934;?/h4> <p>?#25930;璇?#28000;?#37934;侊紝32浣嶆鏁?#37825;拌绀洪敊璇?#37720;熷洜?#32029;RST_STREAM鍜孏OAWAY甯?#28051;?#37718;?#37722;?#37510;?/p> <p><img alt="" src="http://images.blogjava.net/blogjava_net/yongboy/Windows-Live-Writer/5264ea818301_D4ED/http2_errors_thumb.png" /></p> <p>鏈?#37933;?#37812;?#28051;嶆敮?#23508;鐨勯敊璇?#28000;?#37934;?#37721;?#28000;?#38315;夋嫨蹇界暐?#32029;鎴栦綔?#36127;INTERNAL_ERROR?#25930;璇?#28725;?#23536;?#38318;藉彲浠?#37510;?/p> <h3 id="3-">3. 杩?#37818;敊璇?#28598;勭悊</h3> <p>?#31476;鑸潵璁?#26473;?#37818;敊璇?#23536;?#28051;噸?#32029;浼?#28725;?#38007;村?#21229;悊杩?#32459;嬫?#29363;硶杩?#29723;?#28051;嬪?#20249;紝鎴栧?#21342;搷鍒?#37825;?#28051;?#26473;?#37818;?#37928;勭姸鎬?#37510;?/p> <ul> <li>?#31891;绔竴鏃?#38316;?#28051;?#26473;?#37818;敊璇紝?#28214;绗竴?#26882;闂村湪鏈鍚庝竴涓?#37721;?#37922;?#23092;佷?#23106;彂閫佸寘鍚敊璇?#37720;熷洜GOAWAY甯?#26473;囧?#20249;紝?#21159;鍚?#37711;?#38338;?#26473;?#37818;? </li><li>GOAWAY鏈?#37721;兘涓嶈瀵?#32468;?#37812;?#37716;熸帴鏀?#37714;帮紝?#23266;鎴?#37716;熸帴鏀?#37721;幏寰?#26473;?#37818;?#29722;粓姝?#37928;勫?#29111;洜 </li><li>?#31891;绔?#37721;?#37734;?#28000;讳綍?#26882;闂寸粓姝?#26473;?#37818;紝涔熷彲浠?#37814;?#23092;侀敊璇綔?#36127;杩?#37818;敊璇?#28725;?#23536;?#37510;?#28003;嗛?#34249;?#26055;鍦?#37711;?#38338;?#26473;?#37818;?#28052;?#37715;嶅彂閫佷竴涓狦OAWAY甯?#37723;婄煡瀵规柟 </li></ul> <h4 id="4-">4. 娴侀敊璇?/h4> <p>?#31476;鑸潵璁?#37711;?#28003;撴?#20343;笂鐨勬祦?#25930;璇?#28051;?#28028;氬?#21342;搷鍒板叾瀹?#23092;?#37928;勫?#21229;悊銆?/p> <ul> <li>?#31891;绔?#22955;娴嬪?#29256;祦?#25930;璇紝?#28214;瑕?#37721;?#38315;佷竴涓猂ST_STREAM甯紝鍏?#37718;?#37722;?#27996;?#37823;嶄綔鍒伴敊璇?#23092;佹爣璇?#32471;? </li><li>RST_STREAM搴斿綋鏄?#37721;?#38315;侀敊璇?#23092;?#37832;鍚庝竴涓?#29999;紝鍐?#37722;敊璇?#37720;熷洜銆? </li><li>鍙?#38315;佹?#29808;湪鍙?#38315;佷?#23338;悗?#32029;?#28214;瑕?#37713;嗗鎺?#37824;?#28725;?#32468;?#28751;?#29781;佹垨鍗?#28751;嗗彂閫?#26473;囨潵鐨勫抚鏁版嵁?#32029;澶勭悊鏂?#23534;?#28751;?#37828;?#36423;界暐涔嬶紝闄?#38344;?#37828;?#37721;?#28000;?#28103;?#37824;?#26473;?#37818;姸鎬佸抚 </li><li>?#31476;鑸潵璁诧紝?#31891;绔?#28051;嶅?#26055;鍙?#38315;?#28598;?#28051;猂ST_STREAM甯紝浣嗚嫢鍦竴涓?#23536;杩旀椂闂?#28052;嬪悗宸?#37711;?#38338;?#37928;勬?#20343;笂鑳藉缁?#32513;?#37818;?#37824;跺抚?#32029;鍒欓渶瑕?#37721;?#38315;?#37712;嶆鍙?#38315;佷竴涓猂ST_STREAM甯紝澶勭悊杩?#32457;嶈?#23676;负涓?#32468;?#37928;勫疄鐜?#37510;? </li><li>?#31891;绔?#37734;?#37818;?#37824;?#37714;RST_STREAM甯?#28052;嬪悗?#32029;涓嶈?#34249;?#23941;簲?#31476;涓猂ST_STREAM甯紝?#20265;鍏嶆寰幆 </li></ul> <h4 id="5-">5. 杩?#37818;粓姝?/h4> <p>TCP杩?#37818;?#29722;?#37711;?#38338;?#37812;栭噸缃椂浠?#37832;?#28598;?#27996;?open"鎴?half closed"鐨勬祦灏?#28051;嶈兘鑷?#37716;?#38322;嶈瘯銆?/p> <h3 id="-http-2-">浜?#37510;侶TTP/2瀹?#37711;?#23049;?#37808;?#27996;嬮</h3> <h4 id="1-">1. 璺?#37719;?#29825;?#37824;?#37713;?/h4> <p>璺?#37719;?#29825;?#37824;?#37713;伙紝瀛楅潰涓婄悊瑙?#28751;?#23536;?#32480;鍗曪紝姣斿?#20635;敾鍑昏?#37835;勫缓HTTP/1.1璇?#23033;傜洿鎺?#26462;?#37721;戠粰浠?#28000;?#37824;?#37816;丠TTP/2鐨?#37832;?#37716;?#37731;紝浠?#37832;?#23536;呰幏鍙?#37824;?#37713;?#37825;堟灉銆?/p> <p>杩?#38322;?#37832;変竴?#30226;璁?#29785;?#29882;?#37719;?#29825;?#37824;?#37713;?#37928;?#37826;?#32468;?#38171;?a href="http://www.freebuf.com/articles/web/19622.html">http://www.freebuf.com/articles/web/19622.html</a></p> <p>TLS鐨勫姞瀵?#37832;?#37714;?#28003;?#23536;?#37824;?#37713;昏?#23536;堥?#25424;幏寰?#37828;?#37826;囷紝鍙?#28598;TLS鐨凙LPN鍗?#29825;?#37813;?#28766;?#37721;?#28000;?#23536;?#26462;?#37833;?#28598;勭悊璇?#23033;傛槸鍚渶瑕佷綔?#36127;HTTP/2璇锋眰杩?#29723;屽?#21229;?#21997;紝鎬?#28052;嬪彲鏈?#37825;?#38339;绘瀵瑰熀浜嶵LS鐨勫叾瀹?#37719;?#29825;?#37824;?#37713;?#37510;?/p> <p>?#29056;浜?#37837;囧噯鐗圱CP?#30149;鏈塗LS鍜孉LPN鐨勫府?#32342;?#32029;瀹埛绔?#37813;鍙?#38315;?#26473;?#37818;簭瑷鍓嶇紑?#36127;PRI瀛?#32471;?#28051;?#37922;潵娣锋?#21689;TTP/1.1鏈?#37716;?#37731;紝浣?#28725;瑰叾瀹?#37719;?#29825;病鏈夋?#24874;?#28055;繚鎶紝浠?#38340;愪?#24226;銆?#28003;嗗湪澶勭?#21976;椂?#32029;?#23266;鎺?#37824;?#37714;癏TTP/1.1鐨?#29831;锋眰?#32029;?#30149;鏈?#37718;?#37722;Upgrade鍗?#32510;?#28699;?#23048;碉紝鍒欓渶瑕?#29825;负鏄竴涓?#29882;?#37719;?#29825;?#37824;?#37713;?#37510;?/p> <p>鎬?#28052;嬶紝绋嬪簭瑕?#28751;藉彲?#20824;鐨勫澹紝瀹归敊?#32029;閽堝闈炴硶鐨?#29831;锋眰?#32029;鐩?#37818;?#37711;?#38338;?#28725;规柟杩?#37818;?#37510;?/p> <h4 id="2-">2. 涓?#28000;?#32468;?#37825;版嵁杞?#37817;?#28751;佽鐨勬敾鍑?/h4> <p>涓?#28000;嬫墍?#20187;鐨凥TTP/1.1鍜孒TTP/2涔?#38338;?#26462;?#37817;紝浼?#28699;?#37734;?#37824;?#37713;荤偣锛?/p> <ol> <li>HTTP/2澶?#28699;?#23048;?#37722;?#32457;扮?#26667;爜鍏?#29825;?#28003;?#37922;HTTP/1.1?#30149;鏈?#28003;?#37922;?#37714;?#37928;勫瀛?#23048;?#37722;?#32457;帮紝涓?#28000;嬪湪杞?#37817;HTTP/2鍒癏TTP/1.1?#26882;灏?#28729;规槗鍑虹?#26495;寘鍚?#38344;?#23049;曡?#38155;眰澶?#28699;?#23048;礖TTP/1.1鏁版嵁銆? </li><li>HTTP/2鍏?#29825;?#28598;?#28699;?#23048;?#37706;?#37721;?#28000;?#37828;?#38344;炴硶鍊硷紝璇稿鍥炶溅(CR, ASCII 0xd), 鎹?#29723;?(LF, ASCII 0xa), ?#27970;瀛?#32471;?(NUL, ASCII 0x0)?#32029;杩?#37734;?#38315;?#28699;?#29785;?#37835;?#28729;?#37916;版椂鏄竴涓?#26891;庨櫓銆?</li></ol> <p>瑙?#37712;?#37826;?#23534;忥紝?#31476;鏃?#37721;戠?#20276;?#28852;硶澶?#28699;?#23048;?#37722;?#32457;帮紝浠?#37721;?#38344;炴硶澶?#28699;?#23048;?#37706;硷紝閮戒綔?#36127;涓?#28729;?#37825;淬?#23048;嬬己鏁版嵁瀵?#23536;咃紝鎴?#28051;?#23534;冿紝鎴栧?#30028;暐銆?/p> <h4 id="3-">3. 鎺?#38315;?#37712;?#28729;?#37928;勭紦瀛?/h4> <p>鎺?#38315;?#37712;?#28729;规?#22793;繚璇?#37928;?#37832;?#37716;?#37731;?#37819;愪?#28083;紝鏄?#37722;?#32514;?#28699;?#37922;?#28598;?#28699;?#23048;礐ache-Control鎺?#37714;?#37510;?/p> <p>浣嗚嫢鏈?#37716;?#37731;?#28051;?#28598;?#32457;熸埛?#33328;寮?#38171;SAAS锛夛紝姣忎竴涓?#32457;熸埛浣?#37922;竴灏?#38318;?#37714;哢RL绌?#38338;达紝姣斿 tenant1.domain.com?#32029;tenant2.domain.com?#32029;鏈?#37716;?#37731;渶瑕佺?#32346;?#30149;鏈夋?#22559;潈鐨勭?#29112;埛涓嶈?#34249;?#29112;帹閫?#29906;?#27996;庨鏈?#37928;勮?#21228;簮?#32029;瑕?#37929;?#23480;?#37832;?#37712;?#28729;?#37510;?/p> <p>鍘?#28654;?#37832;?#37716;?#37731;病鏈夎鎺堟潈浣?#37922;?#37818;?#38315;侊紝鏃?#28051;嶈?#34249;杩?#29785;勫彂閫佹帹閫侊紝涔?#28051;嶈?#34249;?#29115;缂?#28699;?#37510;?/p> <h4 id="4-">4. 鎷?#32513;?#37832;?#37716;?#37824;?#37713;?#23049;?#37808;?#27996;嬮</h4> <ul> <li>HTTP/2?#27932;?#36127;瑕佷负娴?#37510;佹姤澶村帇缂?#37510;佹祦?#22138;鎺?#37714;剁瓑鐗规?#37719;?#37922;?#29863;勬簮?#32221;澶氾紝?#27932;姝?#38333;堝?#35268;?#24526;竴涓?#26473;?#37818;?#37928;勫唴瀛?#37714;嗛?#23944;璁?#32515;?#38340;?#26864;濓紝鍚?#37714;?#23536;堝皯鐨?#26473;?#37818;?#37719;?#23114;?#37712;?#28699;橈紝鏃犳硶姝父鏈?#37716;? </li><li>閽堝?#29808;崟涓?#26473;?#37818;紝瑙勮寖瀵PUSH_PROMISE甯?#37825;伴噺?#30149;鏈夌害鏉燂紝浣?#28729;埛绔渶瑕?#29825;?#32515;竴涓?#28051;?#38340;愬硷紝杩?#28052;?#37828;?#32429;?#28729;氶渶瑕佺淮鎶?#37928;?reserved (remote)"?#23032;鎬?#37928;?#37825;伴?#24549;紝瓒?#37713;洪檺棰濋渶瑕佹姤ENHANCE_YOUR_CALM绫诲?#23339;祦?#25930;璇? </li><li>SETTINGS甯?#37832;?#37721;兘浼氳婊?#37922;?#28725;?#38007;村绔渶瑕佽姳璐规椂闂?#29785;?#37835;?#28598;勭悊璁?#32515;?#38340;?#37714;剁?#22811;紝婊?#37922;?#37807;?#37712;?#37718;?#37815;?#37718;?#37722;?#37832;?#28729;?#28052;?#37928;勫?#20635;暟?#32029;浠?#37721;?#37722;屼竴涓?#37721;傛?#26495;?#27693;鍑虹幇绛夛紝绫?#28028;?#27996;WINDOW_UPDATE鍜孭RIORITY甯?#38318;?#28028;?#28699;?#37734;?#23114;?#37922;?#37928;勬儏鍐?#38171;?#26473;?#27996;?#29999;?#29722;?#23114;?#37922;?#28725;?#38007;?#29863;勬簮鑰?#29840;规儏鍐?#28051;噸 </li><li>澶噺灏忓抚鎴?#32460;哄抚?#31476;鏍?#28028;氳婊?#37922;紝浣嗗張绗?#37722;?#38315;昏緫?#32029;鑰?#29840;规湇鍔?#37731;?#29863;勬簮鍦?#28598;勭悊鎶?#37826;囧閮?#28051;婇潰銆傛?#26047;?#20636;?#40511;礋杞DATA甯紝浠?#37721;?#37922;?#27996;庢?#21700;甫鎶?#37826;囧閮?#37825;版嵁鐨凜ONTINUATION甯紝閮藉睘浜?#28729;?#37711;?#38341;愭偅 </li><li>鎶?#28598;村帇缂?#28699;?#37734;綔鍦?#26891;庨櫓?#32029;涔?#28028;氳婊?#37922;紝璇?#37807;?#37721;?#37721;傝僅PACK鍗?#29825;?#32471;?#28051;?#32468;?#38171;?a href="http://http2.github.io/http2-spec/compression.html#Security">http://http2.github.io/http2-spec/compression.html#Security</a> </li><li>?#31891;绔?#28051;?#38315;?#37721;?#38315;?#37928;凷ETTINGS甯?#37813;瀹?#28052;?#37721;傛暟涓?#37828;?#32468;嬪嵆鍙?#28000;?#37922;?#37825;?#37928;勶紝杩?#28028;?#28725;?#38007;村绔?#37734;?#28729;?#38340;?#37823;嶄綔?#26882;鍙兘浼?#29906;?#26473;?#37832;?#26570;鐨?#38340;?#37714;?#37510;傚缓璁?#37929;?#37818;?#37734;?#26473;?#37818;?#23524;虹?#23339;椂鍦?#26473;?#37818;簭瑷鍐?#37718;?#37722;?#29825;?#32515;?#37706;硷紝灏?#32480;?#28641;傛?#32029;瀹埛绔?#28052;?#28028;?#28699;?#37734;?#29906;?#37713;?#37832;?#37716;?#37731;?#32468;?#26473;?#37818;簭瑷涓?#37813;璁?#32515;?#37928;?#37832;?#26570;闄?#28729;氬?#37510;?</li></ul> <p>鎬?#28052;嬶紝璇稿?#20418;ETTINGS甯?#37510;?#28751;忓抚鎴?#32460;哄抚?#32029;鎶?#28598;村帇缂?#29722;?#37722;堢悊婊?#37922;椂?#32029;琛?#37828;?#28051;婄湅绗?#37722;?#38315;昏緫?#32029;浼?#38315;?#37812;?#29863;勬簮杩囧害?#31223;鑰?#37510;?#26473;欓渶瑕?#37832;?#37716;?#37731;?#32468;?#37929;戞帶璺熻釜鍒版绉嶈?#23676;负?#32029;?#33503;涓?#29825;?#32515;?#28003;?#37922;?#37825;伴噺鐨?#28051;?#38340;愶紝?#31476;鏃?#37721;戠幇鐩?#37818;?#37814;ENHANCE_YOUR_CALM绫诲瀷杩?#37818;敊璇?#37510;?/p> <h4 id="5-">5. 鎶?#28598;村潡澶?#28751;?#38340;?#37714;?/h4> <p>鎶?#28598;村潡杩囧瀵?#38007;?#28729;?#37916;伴渶瑕佺淮鎶?#28598;噺鐨勭姸鎬?#23534;閿銆傚彟澶栵紝鏍规嵁鎶?#28598;?#28699;?#23048;?#26473;?#29723;岃矾鐢?#37928;勬儏鍐碉紝?#23266;姝?#37814;?#28598;?#28699;?#23048;?#37713;虹?#26495;湪?#31476;绯?#37714;?#37814;?#28598;村潡甯?#37928;?#37832;鍚庝竴涓?#29999;?#38322;岄潰?#32029;鍙兘浼?#28725;?#38007;存?#29363;硶姝父璺?#37922;?#37714;扮洰鐨勫湴銆傝嫢琚?#32514;?#28699;?#28028;?#28725;?#38007;?#38000;?#29840;瑰?#22138;鐨勫唴瀛?#37510;?#26473;欓渶瑕?#29825;?#32515;甋ETTINGS_MAX_HEADER_LIST_SIZE鍙傛?#20276;檺鍒?#37814;?#28598;?#37832;澶?#37706;硷紝浠?#28751;藉彲?#20824;鐨勯伩鍏嶅?#34425;幇浠?#28051;?#37807;?#37712;?#37510;?/p> <p>鏈?#37716;?#37731;竴鏃?#37818;?#37824;?#37714;?#29906;?#26473;?#37814;?#28598;?#38340;?#37714;?#29831;锋眰?#32029;?#28214;瑕佸?#23941;簲?#31476;涓?31锛?#29831;锋眰澶?#26473;囧锛?HTTP?#23032;鎬佺?#20362;紝瀹埛绔?#37723;?#37721;?#37929;?#37818;?#28051;?#37818;夊?#23941;簲銆?/p> <h4 id="6-">6. 鍘嬬缉浣?#37922;?#37928;勫畨鍏?#38341;愭偅</h4> <ul> <li>閽堝瀹?#37711;?#38315;?#38316;擄紝涓嶈兘浣?#37922;?#37722;屼竴涓?#37720;嬬缉瀛?#37711;?#37720;嬬缉?#32346;瀵?#37928;勫叧閿?#37825;版嵁鍜?#37828;?#37721;?#37824;?#37713;昏?#37818;?#37714;?#37928;?#37825;版嵁 </li><li>?#28533;?#31790;鏁版嵁涓嶈兘纭?#28729;氫负瀹屽叏鍙?#38344;狅紝灏?#28051;嶅?#26055;浣?#37922;?#37720;嬬缉鏈?#37714;? </li><li>閫?#37922;?#23092;?#37928;勫帇缂?#28051;嶈?#34249;湪?#29056;浜嶵LS鐨凥TTP/2涓?#28003;?#37922;?#26473;欎竴閮?#37714;嗭紝鍙?#37721;傝?<a href="http://http2.github.io/http2-spec/compression.html#Security">http://http2.github.io/http2-spec/compression.html#Security</a> </li></ul> <h4 id="7-">7. 濉?#37711;?#28003;?#37922;?#37928;勫畨鍏?#38341;愭偅</h4> <p>?#31476;鑸潵璁诧紝濉?#37711;?#37721;?#37922;潵娣锋?#21975;抚鐨勭湡瀹炶礋杞介暱搴紝绋?#37716;犱繚鎶紝闄?#28003;庢敾鍑?#37928;勫彲?#20824;鎬?#37510;?#28003;嗚嫢涓嶅綋鐨勫鍏?#32475;栫暐锛氬浐瀹氬鍏?#37825;?#37510;?#37721;?#26462;?#37833;?#37818;?#28725;?#37713;哄鍏?#29785;勫垯绛夋儏鍐?#38318;?#28028;?#38340;?#28003;庝繚鎶?#37928;勫姏搴紝閮?#37832;?#37721;兘浼氳鏀?#37713;昏?#37934;?#29785;?#37510;?/p> <p>涓?#28000;?#29825;?#28598;囧?#26055;?#32346;鐣DATA甯?#37928;勫鍏?#38171;堥渶瑕侀伩鍏嶅涓?#37813;杩颁竴浜涙儏鍐?#38171;夛紝浣嗗彲涓?#23534;僅EADERS鍜孭USH_PROMISE甯?#37928;勫鍏?#37510;?/p> <h3 id="-tls">涓?#37510;俆LS</h3> <p>HTTP/2鍔?#28725;嗗?#34425;?#23338;湪TLS鍩虹?#32029;鍏?#27996;嶵LS?#32029;?#28142;鍩虹櫨绉戜笂鏈?#29785;?#38322;?#38171;?a href="http://zh.wikipedia.org/wiki/%E5%82%B3%E8%BC%B8%E5%B1%A4%E5%AE%89%E5%85%A8%E5%8D%94%E8%AD%B0">http://zh.wikipedia.org/wiki/%E5%82%B3%E8%BC%B8%E5%B1%A4%E5%AE%89%E5%85%A8%E5%8D%94%E8%AD%B0</a></p> <p>?#25011;鍙栦竴寮?#37733;撅紝鍙?#29831;?#37828;庡熀浜嶢LPN鍗?#29825;?#37813;?#28766;?#28729;?#28052;?#37928;勫?#24531;?#21976;祦绋?#38171;?/p> <p><img alt="" src="http://www.8634070.com/images/blogjava_net/yongboy/Windows-Live-Writer/5264ea818301_D4ED/image_thumb_14.png" /></p> <p>鍏?#28729;?#29781;佹眰锛?/p> <ul> <li>鍙?#38003;藉熀浜嶵LS >= 1.2鐗?#37832;?#37510;傜洰鍓峊LS 1.3?#36127;鑽夋?#22562;増鏈紝姝?#23534;忕増鏈洰鍓?#28751;?#37832;?#37721;?#37933;?#37510;傜洰鍓嶅彧鏈塗LS 1.2鍙?#38315;?#37510;? </li><li>蹇?#26916;绘敮?#23508;Server Name Indication (SNI) [TLS-EXT]鎵?#28766;曪紝瀹埛绔?#37734;?#26473;?#37818;?#37719;忓?#21979;樁娈甸渶瑕佹?#21700;甫涓婂煙鍚? </li><li>?#29056;浜嶵LS 1.3鎴栨洿楂?#37911;?#37832;?#37835;勫缓?#32029;浠呴渶瑕佹敮?#23508;SNI鎵?#28766;?#37510;俆LS 1.2瑕佹眰?#32221;澶? </li><li>?#29056;浜嶵LS 1.2鏋勫缓 <ul> <li>蹇?#26916;荤鐢?#37720;嬬缉鏈?#37714;?#37510;?#28051;嶆?#26495;綋鍘嬬缉鏈?#37714;?#28028;?#28725;?#38007;翠俊鎭?#28598;?#38343;诧紝HTTP/2鎶?#28598;?#37832;?#37720;嬬缉鏈?#37714;? </li><li>蹇?#26916;荤鐢噸鏂板?#24531;晢鏈?#37714;?#37510;傜粓绔?#28725;?#23536;匱LS 1.2?#22136;鏂板?#24531;?#21973;綔?#36127;PROTOCOL_ERROR绫诲瀷杩?#37818;敊璇?#28725;?#23536;?#38171;?#28725;?#37934;佸浠?#37716;?#28725;嗘鏁伴檺鍒?#28725;?#38007;?#26473;?#37818;竴鐩存寕璧?#32475;?#23536;?#28051;嶅彲鐢? </li><li>?#31891;绔?#37721;?#28000;?#38315;?#26473;囬噸鏂板?#24531;?#21976;?#24874;緵瀵?#28729;埛绔?#37713;?#29831;佷繚鎶?#37716;?#38003;藉湪鎻墜鏈?#38338;达紝?#22136;鏂板?#24531;?#21975;繀椤?#37721;戠?#29111;湪鍙?#38315;?#26473;?#37818;簭瑷涔?#37715;嶈繘琛?#37510;傛湇鍔?#37731;綋鐪嬪?#20276;噸鏂板?#24531;晢璇?#23033;傛椂搴旇璇锋眰瀹埛绔?#29831;佷鍦?#26473;?#37818;?#23524;虹?#23338;悗 </li><li>?#32139;瀹埛绔?#29831;锋眰鍙椾繚鎶?#37928;勭壒瀹?#29863;勬簮?#26882;?#32029;鏈?#37716;?#37731;?#37721;?#28000;?#37725;嶅簲HTTP_1_1_REQUIRED?#25930;璇紝鍙?#37832;?#37825;?#38339;绘?#22136;鏂板?#24531;晢鏈?#37714;?</li></ul></li></ul> <h3 id="-">鍥?#37510;?#28751;?#32513;?/h3> <p>杩?#38322;?#32480;鍗?#29825;板綍HTTP/2?#25930;璇?#37724;?#28729;?#37711;?#37929;?#37711;?#27996;嬮?#30328;紝鏈?#32495;?#37714;?#29785;勮寖瀛範鍒版鍛婁竴娈佃惤銆?/p></div><img src ="http://www.8634070.com/yongboy/aggbug/423791.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.8634070.com/yongboy/" target="_blank">nieyong</a> 2015-03-24 15:27 <a href="http://www.8634070.com/yongboy/archive/2015/03/24/423791.html#Feedback" target="_blank" style="text-decoration:none;">鍙?#29723;?#29831;?#29825;?/a></div>]]></description></item></channel></rss> <a href="http://www.8634070.com/"><span class="STYLE1">˫ɫֱ</span></a> <div style="position:fixed;left:-9000px;top:-9000px;"><nobr id="k0jz6"><delect id="k0jz6"><pre id="k0jz6"><sub id="k0jz6"></sub></pre></delect></nobr><sup id="k0jz6"><meter id="k0jz6"><small id="k0jz6"><rp id="k0jz6"></rp></small></meter></sup><pre id="k0jz6"></pre><video id="k0jz6"></video><ruby id="k0jz6"></ruby><progress id="k0jz6"><ins id="k0jz6"><rt id="k0jz6"></rt></ins></progress><video id="k0jz6"></video><sup id="k0jz6"></sup><noscript id="k0jz6"></noscript><em id="k0jz6"><meter id="k0jz6"></meter></em><tt id="k0jz6"><dfn id="k0jz6"></dfn></tt><ruby id="k0jz6"></ruby><i id="k0jz6"><xmp id="k0jz6"><div id="k0jz6"><tr id="k0jz6"></tr></div></xmp></i><strike id="k0jz6"></strike><sup id="k0jz6"><menu id="k0jz6"><small id="k0jz6"></small></menu></sup><small id="k0jz6"><wbr id="k0jz6"><noframes id="k0jz6"></noframes></wbr></small><tr id="k0jz6"></tr><em id="k0jz6"><ol id="k0jz6"></ol></em><noscript id="k0jz6"><output id="k0jz6"></output></noscript><acronym id="k0jz6"></acronym><div id="k0jz6"><ol id="k0jz6"><mark id="k0jz6"><sub id="k0jz6"></sub></mark></ol></div><option id="k0jz6"><delect id="k0jz6"></delect></option><tr id="k0jz6"><object id="k0jz6"><code id="k0jz6"><track id="k0jz6"></track></code></object></tr><menu id="k0jz6"><small id="k0jz6"><rp id="k0jz6"></rp></small></menu><rp id="k0jz6"><b id="k0jz6"></b></rp><pre id="k0jz6"></pre><div id="k0jz6"><ol id="k0jz6"><object id="k0jz6"><sub id="k0jz6"></sub></object></ol></div><pre id="k0jz6"></pre><sup id="k0jz6"><menu id="k0jz6"><small id="k0jz6"><wbr id="k0jz6"></wbr></small></menu></sup><noframes id="k0jz6"></noframes><rt id="k0jz6"><tt id="k0jz6"><xmp id="k0jz6"></xmp></tt></rt><menuitem id="k0jz6"><meter id="k0jz6"></meter></menuitem><delect id="k0jz6"><meter id="k0jz6"></meter></delect><font id="k0jz6"><nobr id="k0jz6"><em id="k0jz6"><tr id="k0jz6"></tr></em></nobr></font><noframes id="k0jz6"><sup id="k0jz6"><menu id="k0jz6"><small id="k0jz6"></small></menu></sup></noframes><option id="k0jz6"><menuitem id="k0jz6"><meter id="k0jz6"><video id="k0jz6"></video></meter></menuitem></option><pre id="k0jz6"><cite id="k0jz6"><listing id="k0jz6"></listing></cite></pre><noframes id="k0jz6"></noframes><cite id="k0jz6"><center id="k0jz6"></center></cite><optgroup id="k0jz6"></optgroup><pre id="k0jz6"><code id="k0jz6"><listing id="k0jz6"><option id="k0jz6"></option></listing></code></pre><sup id="k0jz6"><menu id="k0jz6"><form id="k0jz6"></form></menu></sup><nobr id="k0jz6"><em id="k0jz6"><menu id="k0jz6"><thead id="k0jz6"></thead></menu></em></nobr><em id="k0jz6"></em><pre id="k0jz6"></pre><div id="k0jz6"><ruby id="k0jz6"><rp id="k0jz6"><strike id="k0jz6"></strike></rp></ruby></div><ruby id="k0jz6"></ruby><listing id="k0jz6"></listing><em id="k0jz6"></em><tr id="k0jz6"></tr> <rp id="k0jz6"></rp><video id="k0jz6"></video><acronym id="k0jz6"><del id="k0jz6"></del></acronym><del id="k0jz6"><delect id="k0jz6"></delect></del><output id="k0jz6"><font id="k0jz6"><nobr id="k0jz6"><em id="k0jz6"></em></nobr></font></output><rt id="k0jz6"><tt id="k0jz6"><nobr id="k0jz6"></nobr></tt></rt><strike id="k0jz6"><delect id="k0jz6"><object id="k0jz6"></object></delect></strike><xmp id="k0jz6"><div id="k0jz6"><tr id="k0jz6"><mark id="k0jz6"></mark></tr></div></xmp><xmp id="k0jz6"><em id="k0jz6"></em></xmp><menuitem id="k0jz6"><noscript id="k0jz6"></noscript></menuitem><div id="k0jz6"><tr id="k0jz6"><mark id="k0jz6"></mark></tr></div><address id="k0jz6"></address><th id="k0jz6"><acronym id="k0jz6"></acronym></th><ruby id="k0jz6"></ruby><noframes id="k0jz6"></noframes><b id="k0jz6"><dfn id="k0jz6"><span id="k0jz6"><ruby id="k0jz6"></ruby></span></dfn></b><th id="k0jz6"><strike id="k0jz6"><del id="k0jz6"></del></strike></th><strike id="k0jz6"></strike><noscript id="k0jz6"></noscript><big id="k0jz6"><pre id="k0jz6"><output id="k0jz6"></output></pre></big><form id="k0jz6"><rp id="k0jz6"><var id="k0jz6"><progress id="k0jz6"></progress></var></rp></form><dl id="k0jz6"><ins id="k0jz6"></ins></dl><noscript id="k0jz6"></noscript><pre id="k0jz6"><output id="k0jz6"><font id="k0jz6"><nobr id="k0jz6"></nobr></font></output></pre><ins id="k0jz6"></ins><th id="k0jz6"></th><i id="k0jz6"><var id="k0jz6"><progress id="k0jz6"><span id="k0jz6"></span></progress></var></i><progress id="k0jz6"></progress><output id="k0jz6"></output><nobr id="k0jz6"></nobr><cite id="k0jz6"></cite><nobr id="k0jz6"><tr id="k0jz6"><video id="k0jz6"></video></tr></nobr><noframes id="k0jz6"><dl id="k0jz6"><ins id="k0jz6"></ins></dl></noframes><noframes id="k0jz6"><dl id="k0jz6"></dl></noframes><noscript id="k0jz6"></noscript><sup id="k0jz6"><menu id="k0jz6"></menu></sup><big id="k0jz6"></big><option id="k0jz6"><delect id="k0jz6"></delect></option><i id="k0jz6"></i><sup id="k0jz6"></sup><address id="k0jz6"><video id="k0jz6"></video></address><font id="k0jz6"><nobr id="k0jz6"><em id="k0jz6"><ol id="k0jz6"></ol></em></nobr></font><nobr id="k0jz6"><em id="k0jz6"><ins id="k0jz6"><thead id="k0jz6"></thead></ins></em></nobr><menuitem id="k0jz6"><noscript id="k0jz6"></noscript></menuitem><del id="k0jz6"><optgroup id="k0jz6"></optgroup></del><track id="k0jz6"><del id="k0jz6"></del></track><wbr id="k0jz6"></wbr><del id="k0jz6"><menuitem id="k0jz6"><address id="k0jz6"></address></menuitem></del><menuitem id="k0jz6"><noscript id="k0jz6"><rt id="k0jz6"></rt></noscript></menuitem><sub id="k0jz6"></sub> <b id="k0jz6"><dfn id="k0jz6"><big id="k0jz6"><pre id="k0jz6"></pre></big></dfn></b><tt id="k0jz6"><xmp id="k0jz6"></xmp></tt><noscript id="k0jz6"><th id="k0jz6"><track id="k0jz6"><del id="k0jz6"></del></track></th></noscript><listing id="k0jz6"></listing><noscript id="k0jz6"></noscript><code id="k0jz6"></code><span id="k0jz6"><video id="k0jz6"></video></span><wbr id="k0jz6"><acronym id="k0jz6"></acronym></wbr><address id="k0jz6"></address><rt id="k0jz6"></rt><address id="k0jz6"><output id="k0jz6"><i id="k0jz6"></i></output></address><track id="k0jz6"><dfn id="k0jz6"><menuitem id="k0jz6"></menuitem></dfn></track><dfn id="k0jz6"><span id="k0jz6"></span></dfn><rt id="k0jz6"><tt id="k0jz6"><xmp id="k0jz6"><div id="k0jz6"></div></xmp></tt></rt><option id="k0jz6"><sup id="k0jz6"><menu id="k0jz6"><small id="k0jz6"></small></menu></sup></option><pre id="k0jz6"></pre><dfn id="k0jz6"></dfn><rt id="k0jz6"></rt><form id="k0jz6"><rp id="k0jz6"></rp></form><acronym id="k0jz6"><dfn id="k0jz6"><big id="k0jz6"><ruby id="k0jz6"></ruby></big></dfn></acronym><p id="k0jz6"><tr id="k0jz6"><ruby id="k0jz6"></ruby></tr></p><ol id="k0jz6"><video id="k0jz6"><rp id="k0jz6"></rp></video></ol><dl id="k0jz6"><meter id="k0jz6"><small id="k0jz6"></small></meter></dl><strike id="k0jz6"></strike><div id="k0jz6"></div><noframes id="k0jz6"><sup id="k0jz6"></sup></noframes><noframes id="k0jz6"><dl id="k0jz6"><ins id="k0jz6"><thead id="k0jz6"></thead></ins></dl></noframes><thead id="k0jz6"></thead><font id="k0jz6"></font><dfn id="k0jz6"></dfn><i id="k0jz6"><var id="k0jz6"></var></i><th id="k0jz6"><strike id="k0jz6"></strike></th><menu id="k0jz6"><small id="k0jz6"><wbr id="k0jz6"><b id="k0jz6"></b></wbr></small></menu><ins id="k0jz6"><mark id="k0jz6"></mark></ins><address id="k0jz6"><rt id="k0jz6"><tt id="k0jz6"></tt></rt></address><sub id="k0jz6"><track id="k0jz6"></track></sub><strike id="k0jz6"></strike><div id="k0jz6"></div><nobr id="k0jz6"></nobr><sup id="k0jz6"><menu id="k0jz6"><small id="k0jz6"><wbr id="k0jz6"></wbr></small></menu></sup><tr id="k0jz6"><object id="k0jz6"></object></tr><ruby id="k0jz6"><cite id="k0jz6"><font id="k0jz6"></font></cite></ruby><ol id="k0jz6"></ol><center id="k0jz6"><option id="k0jz6"><sup id="k0jz6"><menu id="k0jz6"></menu></sup></option></center><menuitem id="k0jz6"></menuitem><nobr id="k0jz6"></nobr><option id="k0jz6"><sup id="k0jz6"></sup></option><nobr id="k0jz6"><dl id="k0jz6"><ins id="k0jz6"><small id="k0jz6"></small></ins></dl></nobr><track id="k0jz6"></track><thead id="k0jz6"><th id="k0jz6"><acronym id="k0jz6"><samp id="k0jz6"></samp></acronym></th></thead></div> <script>(function(){ var src = (document.location.protocol == "http:") ? "http://js.passport.qihucdn.com/11.0.1.js?9ed1f3a8f9c3ff069b7b95c01474c743":"https://jspassport.ssl.qhimg.com/11.0.1.js?9ed1f3a8f9c3ff069b7b95c01474c743"; document.write('<script src="' + src + '" id="sozz"><\/script>'); })(); </script> <div style="position:fixed;left:-9000px;top:-9000px;"><nobr id="k0jz6"><delect id="k0jz6"><pre id="k0jz6"><sub id="k0jz6"></sub></pre></delect></nobr><sup id="k0jz6"><meter id="k0jz6"><small id="k0jz6"><rp id="k0jz6"></rp></small></meter></sup><pre id="k0jz6"></pre><video id="k0jz6"></video><ruby id="k0jz6"></ruby><progress id="k0jz6"><ins id="k0jz6"><rt id="k0jz6"></rt></ins></progress><video id="k0jz6"></video><sup id="k0jz6"></sup><noscript id="k0jz6"></noscript><em id="k0jz6"><meter id="k0jz6"></meter></em><tt id="k0jz6"><dfn id="k0jz6"></dfn></tt><ruby id="k0jz6"></ruby><i id="k0jz6"><xmp id="k0jz6"><div id="k0jz6"><tr id="k0jz6"></tr></div></xmp></i><strike id="k0jz6"></strike><sup id="k0jz6"><menu id="k0jz6"><small id="k0jz6"></small></menu></sup><small id="k0jz6"><wbr id="k0jz6"><noframes id="k0jz6"></noframes></wbr></small><tr id="k0jz6"></tr><em id="k0jz6"><ol id="k0jz6"></ol></em><noscript id="k0jz6"><output id="k0jz6"></output></noscript><acronym id="k0jz6"></acronym><div id="k0jz6"><ol id="k0jz6"><mark id="k0jz6"><sub id="k0jz6"></sub></mark></ol></div><option id="k0jz6"><delect id="k0jz6"></delect></option><tr id="k0jz6"><object id="k0jz6"><code id="k0jz6"><track id="k0jz6"></track></code></object></tr><menu id="k0jz6"><small id="k0jz6"><rp id="k0jz6"></rp></small></menu><rp id="k0jz6"><b id="k0jz6"></b></rp><pre id="k0jz6"></pre><div id="k0jz6"><ol id="k0jz6"><object id="k0jz6"><sub id="k0jz6"></sub></object></ol></div><pre id="k0jz6"></pre><sup id="k0jz6"><menu id="k0jz6"><small id="k0jz6"><wbr id="k0jz6"></wbr></small></menu></sup><noframes id="k0jz6"></noframes><rt id="k0jz6"><tt id="k0jz6"><xmp id="k0jz6"></xmp></tt></rt><menuitem id="k0jz6"><meter id="k0jz6"></meter></menuitem><delect id="k0jz6"><meter id="k0jz6"></meter></delect><font id="k0jz6"><nobr id="k0jz6"><em id="k0jz6"><tr id="k0jz6"></tr></em></nobr></font><noframes id="k0jz6"><sup id="k0jz6"><menu id="k0jz6"><small id="k0jz6"></small></menu></sup></noframes><option id="k0jz6"><menuitem id="k0jz6"><meter id="k0jz6"><video id="k0jz6"></video></meter></menuitem></option><pre id="k0jz6"><cite id="k0jz6"><listing id="k0jz6"></listing></cite></pre><noframes id="k0jz6"></noframes><cite id="k0jz6"><center id="k0jz6"></center></cite><optgroup id="k0jz6"></optgroup><pre id="k0jz6"><code id="k0jz6"><listing id="k0jz6"><option id="k0jz6"></option></listing></code></pre><sup id="k0jz6"><menu id="k0jz6"><form id="k0jz6"></form></menu></sup><nobr id="k0jz6"><em id="k0jz6"><menu id="k0jz6"><thead id="k0jz6"></thead></menu></em></nobr><em id="k0jz6"></em><pre id="k0jz6"></pre><div id="k0jz6"><ruby id="k0jz6"><rp id="k0jz6"><strike id="k0jz6"></strike></rp></ruby></div><ruby id="k0jz6"></ruby><listing id="k0jz6"></listing><em id="k0jz6"></em><tr id="k0jz6"></tr> <rp id="k0jz6"></rp><video id="k0jz6"></video><acronym id="k0jz6"><del id="k0jz6"></del></acronym><del id="k0jz6"><delect id="k0jz6"></delect></del><output id="k0jz6"><font id="k0jz6"><nobr id="k0jz6"><em id="k0jz6"></em></nobr></font></output><rt id="k0jz6"><tt id="k0jz6"><nobr id="k0jz6"></nobr></tt></rt><strike id="k0jz6"><delect id="k0jz6"><object id="k0jz6"></object></delect></strike><xmp id="k0jz6"><div id="k0jz6"><tr id="k0jz6"><mark id="k0jz6"></mark></tr></div></xmp><xmp id="k0jz6"><em id="k0jz6"></em></xmp><menuitem id="k0jz6"><noscript id="k0jz6"></noscript></menuitem><div id="k0jz6"><tr id="k0jz6"><mark id="k0jz6"></mark></tr></div><address id="k0jz6"></address><th id="k0jz6"><acronym id="k0jz6"></acronym></th><ruby id="k0jz6"></ruby><noframes id="k0jz6"></noframes><b id="k0jz6"><dfn id="k0jz6"><span id="k0jz6"><ruby id="k0jz6"></ruby></span></dfn></b><th id="k0jz6"><strike id="k0jz6"><del id="k0jz6"></del></strike></th><strike id="k0jz6"></strike><noscript id="k0jz6"></noscript><big id="k0jz6"><pre id="k0jz6"><output id="k0jz6"></output></pre></big><form id="k0jz6"><rp id="k0jz6"><var id="k0jz6"><progress id="k0jz6"></progress></var></rp></form><dl id="k0jz6"><ins id="k0jz6"></ins></dl><noscript id="k0jz6"></noscript><pre id="k0jz6"><output id="k0jz6"><font id="k0jz6"><nobr id="k0jz6"></nobr></font></output></pre><ins id="k0jz6"></ins><th id="k0jz6"></th><i id="k0jz6"><var id="k0jz6"><progress id="k0jz6"><span id="k0jz6"></span></progress></var></i><progress id="k0jz6"></progress><output id="k0jz6"></output><nobr id="k0jz6"></nobr><cite id="k0jz6"></cite><nobr id="k0jz6"><tr id="k0jz6"><video id="k0jz6"></video></tr></nobr><noframes id="k0jz6"><dl id="k0jz6"><ins id="k0jz6"></ins></dl></noframes><noframes id="k0jz6"><dl id="k0jz6"></dl></noframes><noscript id="k0jz6"></noscript><sup id="k0jz6"><menu id="k0jz6"></menu></sup><big id="k0jz6"></big><option id="k0jz6"><delect id="k0jz6"></delect></option><i id="k0jz6"></i><sup id="k0jz6"></sup><address id="k0jz6"><video id="k0jz6"></video></address><font id="k0jz6"><nobr id="k0jz6"><em id="k0jz6"><ol id="k0jz6"></ol></em></nobr></font><nobr id="k0jz6"><em id="k0jz6"><ins id="k0jz6"><thead id="k0jz6"></thead></ins></em></nobr><menuitem id="k0jz6"><noscript id="k0jz6"></noscript></menuitem><del id="k0jz6"><optgroup id="k0jz6"></optgroup></del><track id="k0jz6"><del id="k0jz6"></del></track><wbr id="k0jz6"></wbr><del id="k0jz6"><menuitem id="k0jz6"><address id="k0jz6"></address></menuitem></del><menuitem id="k0jz6"><noscript id="k0jz6"><rt id="k0jz6"></rt></noscript></menuitem><sub id="k0jz6"></sub> <b id="k0jz6"><dfn id="k0jz6"><big id="k0jz6"><pre id="k0jz6"></pre></big></dfn></b><tt id="k0jz6"><xmp id="k0jz6"></xmp></tt><noscript id="k0jz6"><th id="k0jz6"><track id="k0jz6"><del id="k0jz6"></del></track></th></noscript><listing id="k0jz6"></listing><noscript id="k0jz6"></noscript><code id="k0jz6"></code><span id="k0jz6"><video id="k0jz6"></video></span><wbr id="k0jz6"><acronym id="k0jz6"></acronym></wbr><address id="k0jz6"></address><rt id="k0jz6"></rt><address id="k0jz6"><output id="k0jz6"><i id="k0jz6"></i></output></address><track id="k0jz6"><dfn id="k0jz6"><menuitem id="k0jz6"></menuitem></dfn></track><dfn id="k0jz6"><span id="k0jz6"></span></dfn><rt id="k0jz6"><tt id="k0jz6"><xmp id="k0jz6"><div id="k0jz6"></div></xmp></tt></rt><option id="k0jz6"><sup id="k0jz6"><menu id="k0jz6"><small id="k0jz6"></small></menu></sup></option><pre id="k0jz6"></pre><dfn id="k0jz6"></dfn><rt id="k0jz6"></rt><form id="k0jz6"><rp id="k0jz6"></rp></form><acronym id="k0jz6"><dfn id="k0jz6"><big id="k0jz6"><ruby id="k0jz6"></ruby></big></dfn></acronym><p id="k0jz6"><tr id="k0jz6"><ruby id="k0jz6"></ruby></tr></p><ol id="k0jz6"><video id="k0jz6"><rp id="k0jz6"></rp></video></ol><dl id="k0jz6"><meter id="k0jz6"><small id="k0jz6"></small></meter></dl><strike id="k0jz6"></strike><div id="k0jz6"></div><noframes id="k0jz6"><sup id="k0jz6"></sup></noframes><noframes id="k0jz6"><dl id="k0jz6"><ins id="k0jz6"><thead id="k0jz6"></thead></ins></dl></noframes><thead id="k0jz6"></thead><font id="k0jz6"></font><dfn id="k0jz6"></dfn><i id="k0jz6"><var id="k0jz6"></var></i><th id="k0jz6"><strike id="k0jz6"></strike></th><menu id="k0jz6"><small id="k0jz6"><wbr id="k0jz6"><b id="k0jz6"></b></wbr></small></menu><ins id="k0jz6"><mark id="k0jz6"></mark></ins><address id="k0jz6"><rt id="k0jz6"><tt id="k0jz6"></tt></rt></address><sub id="k0jz6"><track id="k0jz6"></track></sub><strike id="k0jz6"></strike><div id="k0jz6"></div><nobr id="k0jz6"></nobr><sup id="k0jz6"><menu id="k0jz6"><small id="k0jz6"><wbr id="k0jz6"></wbr></small></menu></sup><tr id="k0jz6"><object id="k0jz6"></object></tr><ruby id="k0jz6"><cite id="k0jz6"><font id="k0jz6"></font></cite></ruby><ol id="k0jz6"></ol><center id="k0jz6"><option id="k0jz6"><sup id="k0jz6"><menu id="k0jz6"></menu></sup></option></center><menuitem id="k0jz6"></menuitem><nobr id="k0jz6"></nobr><option id="k0jz6"><sup id="k0jz6"></sup></option><nobr id="k0jz6"><dl id="k0jz6"><ins id="k0jz6"><small id="k0jz6"></small></ins></dl></nobr><track id="k0jz6"></track><thead id="k0jz6"><th id="k0jz6"><acronym id="k0jz6"><samp id="k0jz6"></samp></acronym></th></thead></div> <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>