{
    "componentChunkName": "component---src-templates-issues-tsx",
    "path": "/issues/206",
    "result": {"data":{"issuesJson":{"id":"9bf90262-72ce-58c9-93b2-b317b254594c","title":"link1st/go-stress-testing: Golang 实现的压测工具","number":206,"bodyHTML":"<div align=\"center\" dir=\"auto\">\n<p dir=\"auto\"><a target=\"_blank\" rel=\"noopener noreferrer nofollow\" href=\"https://camo.githubusercontent.com/a15b413168923d02e21292705ceaf86b92675f98e250c5c896a02ba7504a6eae/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f657279616a662f7475406d61696e2f696d672f696d6167655f32303234303432305f3231343430382e676966\"><img src=\"https://camo.githubusercontent.com/a15b413168923d02e21292705ceaf86b92675f98e250c5c896a02ba7504a6eae/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f657279616a662f7475406d61696e2f696d672f696d6167655f32303234303432305f3231343430382e676966\" width=\"100%\" height=\"3\" data-animated-image=\"\" data-canonical-src=\"https://cdn.jsdelivr.net/gh/eryajf/tu@main/img/image_20240420_214408.gif\" style=\"max-width: 100%; height: auto; max-height: 3px;\"></a><br><br></p>\n<markdown-accessiblity-table><table role=\"table\">\n<thead>\n<tr>\n<th align=\"right\">Repos</th>\n<th align=\"left\"><a href=\"https://github.com/link1st/go-stress-testing\">link1st/go-stress-testing</a></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"right\"><strong>Views</strong></td>\n<td align=\"left\"><a href=\"https://github.com/opsre/awesome-ops\"><img src=\"https://camo.githubusercontent.com/8f8d709c7a325da659daaa1b94fba2399958a552a3468eff5c5cf46a76150d5c/68747470733a2f2f76696577732e77686174696c656172656e65642e746f6461792f76696577732f6769746875622f6c696e6b3173742f676f2d7374726573732d74657374696e672e737667\" alt=\"views\" data-canonical-src=\"https://views.whatilearened.today/views/github/link1st/go-stress-testing.svg\" style=\"max-width: 100%;\"></a></td>\n</tr>\n<tr>\n<td align=\"right\"><strong>Stars</strong></td>\n<td align=\"left\"><a href=\"https://github.com/opsre/awesome-ops\"><img src=\"https://camo.githubusercontent.com/74249d7c9826728a222122ea8688a43048206b41c9069f0fc33e98d98b7c03a7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6c696e6b3173742f676f2d7374726573732d74657374696e673f636f6c6f723d663266303864266c6f676f3d556e64657274616c65266c6f676f436f6c6f723d656234363330\" alt=\"stars\" data-canonical-src=\"https://img.shields.io/github/stars/link1st/go-stress-testing?color=f2f08d&amp;logo=Undertale&amp;logoColor=eb4630\" style=\"max-width: 100%;\"></a></td>\n</tr>\n<tr>\n<td align=\"right\"><strong>Forks</strong></td>\n<td align=\"left\"><a href=\"https://github.com/opsre/awesome-ops\"><img src=\"https://camo.githubusercontent.com/4b2d8f693e51ffe1de53bee1fc9856c8da4e0ae19acdbe72bfb03b3682d0aed4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6c696e6b3173742f676f2d7374726573732d74657374696e673f636f6c6f723d626138366562266c6f676f3d48616e647368616b65266c6f676f436f6c6f723d656136616136\" alt=\"forks\" data-canonical-src=\"https://img.shields.io/github/forks/link1st/go-stress-testing?color=ba86eb&amp;logo=Handshake&amp;logoColor=ea6aa6\" style=\"max-width: 100%;\"></a></td>\n</tr>\n<tr>\n<td align=\"right\"><strong>License</strong></td>\n<td align=\"left\"><a href=\"https://github.com/opsre/awesome-ops\"><img src=\"https://camo.githubusercontent.com/0c93ca71e73bb599dbfbd81eb5bbb82f63a427dc55ced5d8a7de2d4025f1f1c5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c2d4e4f4e452d626c75653f6c6f676f3d756e6c6963656e7365\" alt=\"license\" data-canonical-src=\"https://img.shields.io/badge/L-NONE-blue?logo=unlicense\" style=\"max-width: 100%;\"></a></td>\n</tr>\n<tr>\n<td align=\"right\"><strong>UpdatedAt</strong></td>\n<td align=\"left\"><a href=\"https://github.com/opsre/awesome-ops\"><img src=\"https://camo.githubusercontent.com/41a02a93e7b739dca2eb8b70b69f3fd2603bb29753d982e126577c449077e5fc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f6c696e6b3173742f676f2d7374726573732d74657374696e673f646973706c61795f74696d657374616d703d636f6d6d6974746572266c6f676f3d64617461253341696d616765253246706e672533426261736536342532436956424f5277304b47676f414141414e5355684555674141414234414141416543415941414141374d4b3669414141414358424957584d41414173544141414c457745416d7077594141414648556c45515652346e4c5658375539615678776d3236646c582532466468627825324232253246516e626b7655627264554151674a4a496655444e574454546d4f76314651554661504a346b7573725630314a7431734e70637453327533626f745a746d786439744a5346536f714b71494635625944464c436f76436c656673747a4a387758524c445a4c7a6e6b634f343535376e3364332532466e655a3472454f515a74315771462532423858467234253242664f4c4565326a6f59307a776638546f795a50766a45676b4c592532426b306d6d72584f36644b696e787a476b30666a5430782532425279723055716e6359637a4d317263347451253242497270324c4758646f344e4334567657715453373277716c632532427231334f527269364b6458646e624f484c6c776c7a4a70524b6e3657342532424b36706f4f434e6e494166486a253246253242776168495a4234764b6e715a6630714a704e49716c2532467638545530634e6c3572627963337730516e54703379324c54614a374d314e617844723266526e315370504736476961323174664533345463614f617931694d55564f5146624659714957536f31573854694156616e43306576584f4542375770313448466232327a453566714c4f433545524c515769644e614e49347545636339693768634a6c644868324e57725135674464624f6c7061756d49754c62326174415144506e7a3062384e6257636d785656524a33486d7870536377777a4f4a6d4b44524765384c6c435a444c4739673754496e5631516c376462586256316533675430574b697243466f6d6b5079767758466c5a474a4f6a563625324253743634757564445a4f55354555636f782532464d455144567674364d62634e3237593341797a687633737061557242365a3971724a534f3139657a6a387032704c426b4a792532426343484a7857493567573574636652527a31645531394766476b6f7539505a4f34736d52396a4746777065783444793362766e6d4b79706f74625531335669646a71595a68726a343972764d457425324625324659714c7a396430304e6a57253246637a67796f394f35317a7336614e6c6f354644747530445a675146686c47584a30644241446f4e6864367576703657686f617967374e394c564748386d443462253246486e667455516f4e4734764c51306769784d716c5725324234714f6a744e48446733723166365969525347785279375576714c62395534716b716e78504f4e7661356c447048723125324279794b524e4b57425a793565644d554842326d3572792532422532424551772532427a6766347a6f39253246306f634e3357527a4c4277344a2532424a7950574372716d4967475974554f735744346f785a46516f50556a4770564871493425324661666b51504336665a5165654d31253242764c7549516e6a754257514444437363726d485039656f4e5041744271664f6e5875614b25324268364a45624772732532427076764d6d78654962683836336162565065597953456f39464a48704e4d464a59253242503563575a6b6667374f3174537759436553514c54593345385130392532464256504a556c78516a7368543142736343593032723955445542667643484236367063665041336c794165336e6772332532463437584467614a7a736c7937787741364e5a746c555550437541487161536a5549502532427375653842525741432532464e6651374a5a505a35397330476a3756747049537a34685125324243706658474d4b685a63764c70554b7866574d386f68766637702532464f446a4842666356463849736b383267314648796b63564645253242555a414158343761452532464d6c34504f3530506e75683025324678346e6d637957507364774468427836436d6b4c562532466746446a594b784f4a4f4674623077517949684c39527943774b33414f664947703159464542686e4d4a634c525745624b644b516f55366e63545a6b494544696341792532463831645675454d3552775066657934784f7830496b25324649324e6e466b692532425761664f6f464959466367595a43797864376543556a626334416d46363566742532466b4d686b336f25324235686337734d4a79716a4a45477659466151464972375930775077384246415925324236253242766d6b3377367a7a5275444d6d5a5652736668385274413075455453443775434254364459514e36697665553066706b594c6a453671725672744f78654e4b553954484c5a4a396b4255324a427342685635416976422532466f4b61514e4b675043427744596149665a4334616454684f71463457454e56694c4a77566f586f62664c424b56773637414f6154734c6336355461564b32317651344c613939654b6359673576627873624f627a5451394e37554b4467554f3177446a6944494942736868357a746733396e514d4c535a4248344f7a424f55444551586d323036643366634c67737762585141345068634b336e6873775531427a3877765130395248472532466f597933656a6677424e6d746f59714c4130586741414141424a52553545726b4a676767253344253344266c6162656c3d557064617465644174\" alt=\"last-commit\" data-canonical-src=\"https://img.shields.io/github/last-commit/link1st/go-stress-testing?display_timestamp=committer&amp;logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAACXBIWXMAAAsTAAALEwEAmpwYAAAFHUlEQVR4nLVX7U9aVxwm26dlX%2Fdhbx%2B2%2FQnbkvUbrdUAQgJJIfUDNWDTTmOv1FQUFaPJ4kusrV01Jt1sNpctS2u3botZtmxd9tJSFSoqKqIF5bYDFLCovClefstzJ8wXRLDZLznkcO4557n3d3%2FneZ4rEOQZt1WqF%2B8XFr4%2BfOLEe2joY0zwf8ToyZPvjEgkLY%2Bk0mmrXO6dKinxzGk0fjT0x%2BRyr0UqncYczM1rc4tQ%2BIrp2LGXdo4NC4VvWqTS72wqlc%2Br13ORri6KdXdnbOHLlwlzJpRKn6W4%2BK6poOCNnIAfHj%2F%2BwahIZB4vKnqZf0qJpNIql%2Fv8TU0cNl5rbyc3w0QnTp3y2LTaJ7M1NaxDr2fRn1SpPG6Gia21tfE34TcaOay1iMUVOQFbFYqIWSo1W8TiAVanC0evXOEB7Wp14HFb22zE5fqLOC5ERLQWidNaNI4uEcc9i7hcJldHh2NWrQ5gDdbOlpaumIuLb2atAQDPnz0b8NbWcmxVVRJ3HmxpScwwzOJmKDRGe8LlCZDLG9g7TInV1Ql7dbXbV1e3gT0WKirCFomkPyvwXFlZGJOjV6%2BSt64uudDZOU5EUcox%2FMEQDVvt6MbcN27Y3Ayzhv3spaUrB6Z9qrJSO19ezj8p2pLBkJy%2BcCHJxWI5gW5tcfRRz1dU19GfGkou9PZO4smR9jGFwpex4Dy3bvnmKypotbU13VidjqYZhrj49rvMEt%2F%2FYqLz9d00NjW%2Fczgyo9O51zs6aNlo5FDtu0DZgQFhlGXJ0dBADoNhd6uvp6Whoayg7N9LVGH8mD4b%2FHnftUQoNG4vLQ0gixMqlW%2B4qOjtNHDg3r1f6YiRSGxRy7UvqLb9U4qkqnxPONva5lDpHr1%2ByyKRNKWBZy5edMUHB2m5ry%2B%2BEQw%2Bzgf4zo9%2F0ocN3WRzLBw4J%2BJyPWCrqmIgGYtUOsWD4oxZFQoPUjGpVHqI4%2FafkQPC6fZQeeM1%2BvLuIQnjuBWQDDCscrmHP9eoNPAtBqfOnXuaK%2Bh6JEbGrs%2BpvvMmxeIbh863abVPeYySEo9FJHpNMFJY%2BP5cWZkfg7O1tSwYCeSQLTY3E8Q09%2FBVPJUlxQjshT1BscCY02r9UDUBfvCHB66pcfPA3lyAe3ngr3%2F47XDgaJzsly7xwA6NZtlUUPCuAHqaSjUIP%2Bsue8BRWAC%2FNfQ7JZPZ59s0Gj7VtpISz4hQ%2BCpfXGMKhZcvLpUKxfWM8ohvf7p%2FODjHBfcVF8Isk82g1FHykcVFE%2BUZAAX47aE%2FMl4PO50Pnuh0%2Fx4nmcyWPsdwDhBx6CmkLV%2FgFDjYKxOJOFtb0wQyIhL9RyCwK3AOfIGp1YFEBhnMJcLRWEbKdKQoU6ncTZkIEDicAy%2F81dVuEM5RwPfey4xOx0Ik%2FI2NnFki%2BWafOoFIYFcgYZCyxd7eCUjbc4AmF65ft%2FkMhk3o%2B5hc7sMJyqjJEGvYFaQFIr7Y0wPw8BFAY%2B6%2Bvmk3w6zzRuDMmZVRsfh8RtA0uETSD7uCBT6DYQN6iveU0fpkYLjE6qrVrtOxeNKU9THLZJ9kBU2JBsBhV5AivB%2FoKaQNKgPCBwDYaIfZC4adThOqF4WENViLJwVoXobfLBKVw67AOaTsLc65TaVK21vQ4La99eKcYg5vbxsbObzTQ9N7UKDgUO1wDjiDIIBshh5ztg39nQMLSZBH4OzBOUDEQXm206d3fcLgswbXQA4PhcK3nhswU1Bz8wvQ09RHG%2FoYy3ejfwBNmtoYqLA0XgAAAABJRU5ErkJggg%3D%3D&amp;label=UpdatedAt\" style=\"max-width: 100%;\"></a></td>\n</tr>\n<tr>\n<td align=\"right\"><strong>CreatedAt</strong></td>\n<td align=\"left\"><a href=\"https://github.com/opsre/awesome-ops\"><img src=\"https://camo.githubusercontent.com/566f590eab2b6518376598e9cfde93ab8ff8dd4b25954a07532ff74a3492d47a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f637265617465642d61742f6c696e6b3173742f676f2d7374726573732d74657374696e673f6c6f676f3d64617461253341696d616765253246706e672533426261736536342532436956424f5277304b47676f414141414e5355684555674141414234414141416543415941414141374d4b3669414141414358424957584d41414173544141414c457745416d7077594141414648556c45515652346e4c5658375539615678776d3236646c582532466468627825324232253246516e626b7655627264554151674a4a496655444e574454546d4f76314651554661504a346b7573725630314a7431734e70637453327533626f745a746d786439744a5346536f714b71494635625944464c436f76436c656673747a4a387758524c445a4c7a6e6b634f343535376e3364332532466e655a3472454f515a74315771462532423858467234253242664f4c4565326a6f59307a776638546f795a50766a45676b4c592532426b306d6d72584f36644b696e787a476b30666a5430782532425279723055716e6359637a4d317263347451253242497270324c4758646f344e4334567657715453373277716c632532427231334f527269364b6458646e624f484c6c776c7a4a70524b6e3657342532424b36706f4f434e6e494166486a253246253242776168495a4234764b6e715a6630714a704e49716c2532467638545530634e6c3572627963337730516e54703379324c54614a374d314e617844723266526e315370504736476961323174664533345463614f617931694d55564f5146624659714957536f31573854694156616e43306576584f4542375770313448466232327a453566714c4f433545524c515769644e614e49347545636339693768634a6c644868324e57725135674464624f6c7061756d49754c62326174415144506e7a3062384e6257636d785656524a33486d7870536377777a4f4a6d4b44524765384c6c435a444c4739673754496e5631516c376462586256316533675430574b697243466f6d6b5079767758466c5a474a4f6a563625324253743634757564445a4f55354555636f782532464d455144567674364d62634e3237593341797a687633737061557242365a3971724a534f3139657a6a387032704c426b4a792532426343484a7857493567573574636652527a31645531394766476b6f7539505a4f34736d52396a4746777065783444793362766e6d4b79706f74625531335669646a71595a68726a343972764d457425324625324659714c7a396430304e6a57253246637a67796f394f35317a7336614e6c6f354644747530445a675146686c47584a30644241446f4e6864367576703657686f617967374e394c564748386d443462253246486e667455516f4e4734764c51306769784d716c5725324234714f6a744e48446733723166365969525347785279375576714c62395534716b716e78504f4e7661356c447048723125324279794b524e4b57425a793565644d554842326d3572792532422532424551772532427a6766347a6f39253246306f634e3357527a4c4277344a2532424a7950574372716d4967475974554f735744346f785a46516f50556a4770564871493425324661666b51504336665a5165654d31253242764c7549516e6a754257514444437363726d485039656f4e5041744271664f6e5875614b25324268364a45624772732532427076764d6d78654962683836336162565065597953456f39464a48704e4d464a59253242503563575a6b6667374f3174537759436553514c54593345385130392532464256504a556c78516a7368543142736343593032723955445542667643484236367063665041336c794165336e6772332532463437584467614a7a736c7937787741364e5a746c555550437541487161536a5549502532427375653842525741432532464e6651374a5a505a35397330476a3756747049537a34685125324243706658474d4b685a63764c70554b7866574d386f68766637702532464f446a4842666356463849736b383267314648796b63564645253242555a414158343761452532464d6c34504f3530506e75683025324678346e6d637957507364774468427836436d6b4c562532466746446a594b784f4a4f4674623077517949684c39527943774b33414f664947703159464542686e4d4a634c525745624b644b516f55366e63545a6b494544696341792532463831645675454d3552775066657934784f7830496b25324649324e6e466b692532425761664f6f464959466367595a43797864376543556a626334416d46363566742532466b4d686b336f25324235686337734d4a79716a4a45477659466151464972375930775077384246415925324236253242766d6b3377367a7a5275444d6d5a5652736668385274413075455453443775434254364459514e36697665553066706b594c6a453671725672744f78654e4b553954484c5a4a396b4255324a427342685635416976422532466f4b61514e4b675043427744596149665a4334616454684f71463457454e56694c4a77566f586f62664c424b56773637414f6154734c6336355461564b32317651344c613939654b6359673576627873624f627a5451394e37554b4467554f3177446a6944494942736868357a746733396e514d4c535a4248344f7a424f55444551586d323036643366634c67737762585141345068634b336e6873775531427a3877765130395248472532466f597933656a6677424e6d746f59714c4130586741414141424a52553545726b4a676767253344253344266c6162656c3d437265617465644174\" alt=\"create-at\" data-canonical-src=\"https://img.shields.io/github/created-at/link1st/go-stress-testing?logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAACXBIWXMAAAsTAAALEwEAmpwYAAAFHUlEQVR4nLVX7U9aVxwm26dlX%2Fdhbx%2B2%2FQnbkvUbrdUAQgJJIfUDNWDTTmOv1FQUFaPJ4kusrV01Jt1sNpctS2u3botZtmxd9tJSFSoqKqIF5bYDFLCovClefstzJ8wXRLDZLznkcO4557n3d3%2FneZ4rEOQZt1WqF%2B8XFr4%2BfOLEe2joY0zwf8ToyZPvjEgkLY%2Bk0mmrXO6dKinxzGk0fjT0x%2BRyr0UqncYczM1rc4tQ%2BIrp2LGXdo4NC4VvWqTS72wqlc%2Br13ORri6KdXdnbOHLlwlzJpRKn6W4%2BK6poOCNnIAfHj%2F%2BwahIZB4vKnqZf0qJpNIql%2Fv8TU0cNl5rbyc3w0QnTp3y2LTaJ7M1NaxDr2fRn1SpPG6Gia21tfE34TcaOay1iMUVOQFbFYqIWSo1W8TiAVanC0evXOEB7Wp14HFb22zE5fqLOC5ERLQWidNaNI4uEcc9i7hcJldHh2NWrQ5gDdbOlpaumIuLb2atAQDPnz0b8NbWcmxVVRJ3HmxpScwwzOJmKDRGe8LlCZDLG9g7TInV1Ql7dbXbV1e3gT0WKirCFomkPyvwXFlZGJOjV6%2BSt64uudDZOU5EUcox%2FMEQDVvt6MbcN27Y3Ayzhv3spaUrB6Z9qrJSO19ezj8p2pLBkJy%2BcCHJxWI5gW5tcfRRz1dU19GfGkou9PZO4smR9jGFwpex4Dy3bvnmKypotbU13VidjqYZhrj49rvMEt%2F%2FYqLz9d00NjW%2Fczgyo9O51zs6aNlo5FDtu0DZgQFhlGXJ0dBADoNhd6uvp6Whoayg7N9LVGH8mD4b%2FHnftUQoNG4vLQ0gixMqlW%2B4qOjtNHDg3r1f6YiRSGxRy7UvqLb9U4qkqnxPONva5lDpHr1%2ByyKRNKWBZy5edMUHB2m5ry%2B%2BEQw%2Bzgf4zo9%2F0ocN3WRzLBw4J%2BJyPWCrqmIgGYtUOsWD4oxZFQoPUjGpVHqI4%2FafkQPC6fZQeeM1%2BvLuIQnjuBWQDDCscrmHP9eoNPAtBqfOnXuaK%2Bh6JEbGrs%2BpvvMmxeIbh863abVPeYySEo9FJHpNMFJY%2BP5cWZkfg7O1tSwYCeSQLTY3E8Q09%2FBVPJUlxQjshT1BscCY02r9UDUBfvCHB66pcfPA3lyAe3ngr3%2F47XDgaJzsly7xwA6NZtlUUPCuAHqaSjUIP%2Bsue8BRWAC%2FNfQ7JZPZ59s0Gj7VtpISz4hQ%2BCpfXGMKhZcvLpUKxfWM8ohvf7p%2FODjHBfcVF8Isk82g1FHykcVFE%2BUZAAX47aE%2FMl4PO50Pnuh0%2Fx4nmcyWPsdwDhBx6CmkLV%2FgFDjYKxOJOFtb0wQyIhL9RyCwK3AOfIGp1YFEBhnMJcLRWEbKdKQoU6ncTZkIEDicAy%2F81dVuEM5RwPfey4xOx0Ik%2FI2NnFki%2BWafOoFIYFcgYZCyxd7eCUjbc4AmF65ft%2FkMhk3o%2B5hc7sMJyqjJEGvYFaQFIr7Y0wPw8BFAY%2B6%2Bvmk3w6zzRuDMmZVRsfh8RtA0uETSD7uCBT6DYQN6iveU0fpkYLjE6qrVrtOxeNKU9THLZJ9kBU2JBsBhV5AivB%2FoKaQNKgPCBwDYaIfZC4adThOqF4WENViLJwVoXobfLBKVw67AOaTsLc65TaVK21vQ4La99eKcYg5vbxsbObzTQ9N7UKDgUO1wDjiDIIBshh5ztg39nQMLSZBH4OzBOUDEQXm206d3fcLgswbXQA4PhcK3nhswU1Bz8wvQ09RHG%2FoYy3ejfwBNmtoYqLA0XgAAAABJRU5ErkJggg%3D%3D&amp;label=CreatedAt\" style=\"max-width: 100%;\"></a></td>\n</tr>\n</tbody>\n</table></markdown-accessiblity-table>\n<a href=\"https://github.com/opsre/awesome-ops\">\n</a><p dir=\"auto\"><a href=\"https://github.com/opsre/awesome-ops\"><img src=\"https://camo.githubusercontent.com/b964a36ea4078c39f603d46a29436371c7541a2f26e0228d7b21b9d9805b43d3/68747470733a2f2f736f6369616c6966792e6769742e63692f6f707372652f617765736f6d652d6f70732f696d6167653f6465736372697074696f6e3d3126666f6e743d42697474657226666f726b733d31266973737565733d31266c616e67756167653d31266c6f676f3d6874747073253341253246253246617661746172732e67697468756275736572636f6e74656e742e636f6d25324675253246313838353638303230266e616d653d31266f776e65723d31267061747465726e3d436972637569742b426f6172642670756c6c733d31267374617267617a6572733d31267468656d653d4c69676874\" alt=\"\" data-canonical-src=\"https://socialify.git.ci/opsre/awesome-ops/image?description=1&amp;font=Bitter&amp;forks=1&amp;issues=1&amp;language=1&amp;logo=https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F188568020&amp;name=1&amp;owner=1&amp;pattern=Circuit+Board&amp;pulls=1&amp;stargazers=1&amp;theme=Light\" style=\"max-width: 100%;\"></a></p>\n<a target=\"_blank\" rel=\"noopener noreferrer nofollow\" href=\"https://camo.githubusercontent.com/a15b413168923d02e21292705ceaf86b92675f98e250c5c896a02ba7504a6eae/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f657279616a662f7475406d61696e2f696d672f696d6167655f32303234303432305f3231343430382e676966\"><img src=\"https://camo.githubusercontent.com/a15b413168923d02e21292705ceaf86b92675f98e250c5c896a02ba7504a6eae/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f657279616a662f7475406d61696e2f696d672f696d6167655f32303234303432305f3231343430382e676966\" width=\"100%\" height=\"3\" data-animated-image=\"\" data-canonical-src=\"https://cdn.jsdelivr.net/gh/eryajf/tu@main/img/image_20240420_214408.gif\" style=\"max-width: 100%; height: auto; max-height: 3px;\"></a>\n</div>\n<h1 dir=\"auto\">go实现的压测工具【单台机器100w连接压测实战】</h1>\n<p dir=\"auto\"><a href=\"https://pkg.go.dev/github.com/link1st/go-stress-testing\" rel=\"nofollow\"><img src=\"https://camo.githubusercontent.com/5c3856dc84fcf48069a388fc86e95f20ede45d9e8768091b10e281e1d658258c/68747470733a2f2f706b672e676f2e6465762f62616467652f6769746875622e636f6d2f6c696e6b3173742f676f2d7374726573732d74657374696e67\" alt=\"PkgGoDev\" data-canonical-src=\"https://pkg.go.dev/badge/github.com/link1st/go-stress-testing\" style=\"max-width: 100%;\"></a><br>\n<a href=\"https://github.com/link1st/go-stress-testing/releases\"><img src=\"https://camo.githubusercontent.com/c8da2b04c8fe888fdeac229007dd5eca9bdc0dadf18cd205d0ff6817e69d2891/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6c696e6b3173742f676f2d7374726573732d74657374696e67\" alt=\"Release\" data-canonical-src=\"https://img.shields.io/github/v/release/link1st/go-stress-testing\" style=\"max-width: 100%;\"></a><br>\n<a href=\"https://goreportcard.com/report/github.com/link1st/go-stress-testing\" rel=\"nofollow\"><img src=\"https://camo.githubusercontent.com/8c02c404c9983b190106f50f32ff122aecc65b698644f57c8fd675ee8fceaf09/68747470733a2f2f676f7265706f7274636172642e636f6d2f62616467652f6769746875622e636f6d2f6c696e6b3173742f676f2d7374726573732d74657374696e67\" alt=\"Go Report Card\" data-canonical-src=\"https://goreportcard.com/badge/github.com/link1st/go-stress-testing\" style=\"max-width: 100%;\"></a><br>\n<a href=\"https://github.com/link1st/go-stress-testing/issues\"><img src=\"https://camo.githubusercontent.com/be9ff31bb1324b2ed1131e373a210f735849ff97c6f090cfd264a4ece5400247/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6c696e6b3173742f676f2d7374726573732d74657374696e67\" alt=\"OpenIssue\" data-canonical-src=\"https://img.shields.io/github/issues/link1st/go-stress-testing\" style=\"max-width: 100%;\"></a><br>\n<a href=\"https://github.com/link1st/go-stress-testing/issues?q=is%3Aissue+is%3Aclosed\"><img src=\"https://camo.githubusercontent.com/00feaa4481ac3d4d12fe5ec3d117395d76b5cf20b93b8d7297d3a1bb2e56c129/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d636c6f7365642f6c696e6b3173742f676f2d7374726573732d74657374696e67\" alt=\"ClosedIssue\" data-canonical-src=\"https://img.shields.io/github/issues-closed/link1st/go-stress-testing\" style=\"max-width: 100%;\"></a><br>\n<a target=\"_blank\" rel=\"noopener noreferrer nofollow\" href=\"https://camo.githubusercontent.com/26295a64c801a3e500e34b3c833eed5437968cd37204c38d890bb6d2edb66073/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6c696e6b3173742f676f2d7374726573732d74657374696e67\"><img src=\"https://camo.githubusercontent.com/26295a64c801a3e500e34b3c833eed5437968cd37204c38d890bb6d2edb66073/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6c696e6b3173742f676f2d7374726573732d74657374696e67\" alt=\"Stars\" data-canonical-src=\"https://img.shields.io/github/stars/link1st/go-stress-testing\" style=\"max-width: 100%;\"></a><br>\n<a target=\"_blank\" rel=\"noopener noreferrer nofollow\" href=\"https://camo.githubusercontent.com/8d9b89fcec2180787aedec499c4b9f552c621a2163406ef55411ff75e08c91ba/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6c696e6b3173742f676f2d7374726573732d74657374696e67\"><img src=\"https://camo.githubusercontent.com/8d9b89fcec2180787aedec499c4b9f552c621a2163406ef55411ff75e08c91ba/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f6c696e6b3173742f676f2d7374726573732d74657374696e67\" alt=\"Forks\" data-canonical-src=\"https://img.shields.io/github/forks/link1st/go-stress-testing\" style=\"max-width: 100%;\"></a><br>\n<a href=\"https://starchart.cc/link1st/go-stress-testing\" rel=\"nofollow\"><img src=\"https://camo.githubusercontent.com/e8dc9042470c355cf82c804eadafd9baecc5d3caa22d9dca06f8615b7b2e40e7/68747470733a2f2f7374617263686172742e63632f6c696e6b3173742f676f2d7374726573732d74657374696e672e7376673f76617269616e743d6164617074697665\" alt=\"Stargazers over time\" data-canonical-src=\"https://starchart.cc/link1st/go-stress-testing.svg?variant=adaptive\" style=\"max-width: 100%;\"></a></p>\n<p dir=\"auto\">本文介绍压测是什么，解释压测的专属名词，教大家如何压测。介绍市面上的常见压测工具(ab、locust、Jmeter、go实现的压测工具、云压测)，对比这些压测工具，教大家如何选择一款适合自己的压测工具，本文还有两个压测实战项目：</p>\n<ul dir=\"auto\">\n<li>单台机器对 HTTP 短连接 QPS 1W+ 的压测实战</li>\n<li>单台机器 100W 长连接的压测实战</li>\n<li>对 grpc 接口进行压测</li>\n<li>支持 http1.1 和 2.0 长连接</li>\n</ul>\n<blockquote>\n<p dir=\"auto\">简单扩展即可支持 私有协议</p>\n</blockquote>\n<h2 dir=\"auto\">目录</h2>\n<ul dir=\"auto\">\n<li><a href=\"#1%E9%A1%B9%E7%9B%AE%E8%AF%B4%E6%98%8E\">1、项目说明</a>\n<ul dir=\"auto\">\n<li><a href=\"#11-go-stress-testing\">1.1 go-stress-testing</a></li>\n<li><a href=\"#12-%E9%A1%B9%E7%9B%AE%E4%BD%93%E9%AA%8C\">1.2 项目体验</a></li>\n</ul>\n</li>\n<li><a href=\"#2%E5%8E%8B%E6%B5%8B\">2、压测</a>\n<ul dir=\"auto\">\n<li><a href=\"#21-%E5%8E%8B%E6%B5%8B%E6%98%AF%E4%BB%80%E4%B9%88\">2.1 压测是什么</a></li>\n<li><a href=\"#22-%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E5%8E%8B%E6%B5%8B\">2.2 为什么要压测</a></li>\n<li><a href=\"#23-%E5%8E%8B%E6%B5%8B%E5%90%8D%E8%AF%8D%E8%A7%A3%E9%87%8A\">2.3 压测名词解释</a>\n<ul dir=\"auto\">\n<li><a href=\"#231-%E5%8E%8B%E6%B5%8B%E7%B1%BB%E5%9E%8B%E8%A7%A3%E9%87%8A\">2.3.1 压测类型解释</a></li>\n<li><a href=\"#232-%E5%8E%8B%E6%B5%8B%E5%90%8D%E8%AF%8D%E8%A7%A3%E9%87%8A\">2.3.2 压测名词解释</a></li>\n<li><a href=\"#233-%E6%9C%BA%E5%99%A8%E6%80%A7%E8%83%BD%E6%8C%87%E6%A0%87%E8%A7%A3%E9%87%8A\">2.3.3 机器性能指标解释</a></li>\n<li><a href=\"#234-%E8%AE%BF%E9%97%AE%E6%8C%87%E6%A0%87%E8%A7%A3%E9%87%8A\">2.3.4 访问指标解释</a></li>\n</ul>\n</li>\n<li><a href=\"#24-%E5%A6%82%E4%BD%95%E8%AE%A1%E7%AE%97%E5%8E%8B%E6%B5%8B%E6%8C%87%E6%A0%87\">3.4 如何计算压测指标</a></li>\n</ul>\n</li>\n<li><a href=\"#3%E5%B8%B8%E8%A7%81%E7%9A%84%E5%8E%8B%E6%B5%8B%E5%B7%A5%E5%85%B7\">3、常见的压测工具</a>\n<ul dir=\"auto\">\n<li><a href=\"#31-ab\">3.1 ab</a></li>\n<li><a href=\"#32-locust\">3.2 locust</a></li>\n<li><a href=\"#33-JMeter\">3.3 JMeter</a></li>\n<li><a href=\"#34-%E4%BA%91%E5%8E%8B%E6%B5%8B\">3.4 云压测</a>\n<ul dir=\"auto\">\n<li><a href=\"#341-%E4%BA%91%E5%8E%8B%E6%B5%8B%E4%BB%8B%E7%BB%8D\">3.4.1 云压测介绍</a></li>\n<li><a href=\"#342-%E9%98%BF%E9%87%8C%E4%BA%91-%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95-PTS\">3.4.2 阿里云 性能测试 PTS</a></li>\n<li><a href=\"#343-%E8%85%BE%E8%AE%AF%E4%BA%91-%E5%8E%8B%E6%B5%8B%E5%A4%A7%E5%B8%88-LM\">3.4.3 腾讯云 压测大师 LM</a></li>\n</ul>\n</li>\n</ul>\n</li>\n<li><a href=\"#4go-stress-testing-go%E8%AF%AD%E8%A8%80%E5%AE%9E%E7%8E%B0%E7%9A%84%E5%8E%8B%E6%B5%8B%E5%B7%A5%E5%85%B7\">4、go-stress-testing go语言实现的压测工具</a>\n<ul dir=\"auto\">\n<li><a href=\"#41-%E4%BB%8B%E7%BB%8D\">4.1 介绍</a></li>\n<li><a href=\"#42-%E7%94%A8%E6%B3%95\">4.2 用法</a></li>\n<li><a href=\"#43-%E5%AE%9E%E7%8E%B0\">4.3 实现</a></li>\n<li><a href=\"#44-go-stress-testing-%E5%AF%B9-golang-web-%E5%8E%8B%E6%B5%8B\">4.4 go-stress-testing 对 Golang web 压测</a></li>\n<li><a href=\"#45-grpc%E5%8E%8B%E6%B5%8B\">4.5 grpc压测</a></li>\n</ul>\n</li>\n<li><a href=\"#5%E5%8E%8B%E6%B5%8B%E5%B7%A5%E5%85%B7%E7%9A%84%E6%AF%94%E8%BE%83\">5、压测工具的比较</a>\n<ul dir=\"auto\">\n<li><a href=\"#51-%E6%AF%94%E8%BE%83\">5.1 比较</a></li>\n<li><a href=\"#52-%E5%A6%82%E4%BD%95%E9%80%89%E6%8B%A9%E5%8E%8B%E6%B5%8B%E5%B7%A5%E5%85%B7\">5.2 如何选择压测工具</a></li>\n</ul>\n</li>\n<li><a href=\"#6%E5%8D%95%E5%8F%B0%E6%9C%BA%E5%99%A8100w%E8%BF%9E%E6%8E%A5%E5%8E%8B%E6%B5%8B%E5%AE%9E%E6%88%98\">6、单台机器100w连接压测实战</a>\n<ul dir=\"auto\">\n<li><a href=\"#61-%E8%AF%B4%E6%98%8E\">6.1 说明</a></li>\n<li><a href=\"#62-%E5%86%85%E6%A0%B8%E4%BC%98%E5%8C%96\">6.2 内核优化</a></li>\n<li><a href=\"#63-%E5%AE%A2%E6%88%B7%E7%AB%AF%E9%85%8D%E7%BD%AE\">6.3 客户端配置</a></li>\n<li><a href=\"#64-%E5%87%86%E5%A4%87\">6.4 准备</a></li>\n<li><a href=\"#65-%E5%8E%8B%E6%B5%8B%E6%95%B0%E6%8D%AE\">6.5 压测数据</a></li>\n</ul>\n</li>\n<li><a href=\"#7%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98\">7、常见问题</a></li>\n<li><a href=\"#8%E6%80%BB%E7%BB%93\">8、总结</a></li>\n<li><a href=\"#9%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE\">9、参考文献</a></li>\n</ul>\n<h2 dir=\"auto\">1、项目说明</h2>\n<h3 dir=\"auto\">1.1 go-stress-testing</h3>\n<p dir=\"auto\">go 实现的压测工具，每个用户用一个协程的方式模拟，最大限度的利用 CPU 资源</p>\n<h3 dir=\"auto\">1.2 项目体验</h3>\n<ul dir=\"auto\">\n<li>可以在 mac/linux/windows 不同平台下执行的命令</li>\n</ul>\n<blockquote>\n<p dir=\"auto\"><a href=\"https://github.com/link1st/go-stress-testing/releases\">go-stress-testing</a> 压测工具下载地址<br>\n查看帮助信息 <code class=\"notranslate\">go-stress-testing-mac --help</code></p>\n</blockquote>\n<ul dir=\"auto\">\n<li>有 go 环境安装</li>\n</ul>\n<blockquote>\n<p dir=\"auto\">安装最新版本 <code class=\"notranslate\">go install github.com/link1st/go-stress-testing@latest</code><br>\n安装路径在 <code class=\"notranslate\">echo $GOBIN</code> 目录下，配置了 <code class=\"notranslate\">export PATH=$PATH:$GOROOT/bin:$GOBIN</code> 可以在任意目录下执行<br>\n查看帮助信息 <code class=\"notranslate\">go-stress-testing --help</code></p>\n</blockquote>\n<p dir=\"auto\">参数说明:</p>\n<p dir=\"auto\"><code class=\"notranslate\">-c</code> 表示并发数</p>\n<p dir=\"auto\"><code class=\"notranslate\">-n</code> 每个并发执行请求的次数，总请求的次数 = 并发数 <code class=\"notranslate\">*</code> 每个并发执行请求的次数</p>\n<p dir=\"auto\"><code class=\"notranslate\">-u</code> 需要压测的地址</p>\n<div class=\"highlight highlight-source-shell notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"\n# 运行以 mac 为示例\n./go-stress-testing-mac -c 1 -n 100 -u https://www.baidu.com/\n\"><pre class=\"notranslate\"><span class=\"pl-c\"><span class=\"pl-c\">#</span> 运行以 mac 为示例</span>\n./go-stress-testing-mac -c 1 -n 100 -u https://www.baidu.com/\n</pre></div>\n<ul dir=\"auto\">\n<li>压测结果展示</li>\n</ul>\n<p dir=\"auto\">执行以后，终端每秒钟都会输出一次结果，压测完成以后输出执行的压测结果</p>\n<p dir=\"auto\">压测结果展示:</p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"\n─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────\n 耗时│ 并发数 │ 成功数│ 失败数 │   qps  │最长耗时 │最短耗时│平均耗时 │ 错误码\n─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────\n   1s│      1│      8│      0│    8.09│  133.16│  110.98│  123.56│200:8\n   2s│      1│     15│      0│    8.02│  138.74│  110.98│  124.61│200:15\n   3s│      1│     23│      0│    7.80│  220.43│  110.98│  128.18│200:23\n   4s│      1│     31│      0│    7.83│  220.43│  110.23│  127.67│200:31\n   5s│      1│     39│      0│    7.81│  220.43│  110.23│  128.03│200:39\n   6s│      1│     46│      0│    7.72│  220.43│  110.23│  129.59│200:46\n   7s│      1│     54│      0│    7.79│  220.43│  110.23│  128.42│200:54\n   8s│      1│     62│      0│    7.81│  220.43│  110.23│  128.09│200:62\n   9s│      1│     70│      0│    7.79│  220.43│  110.23│  128.33│200:70\n  10s│      1│     78│      0│    7.82│  220.43│  106.47│  127.85│200:78\n  11s│      1│     84│      0│    7.64│  371.02│  106.47│  130.96│200:84\n  12s│      1│     91│      0│    7.63│  371.02│  106.47│  131.02│200:91\n  13s│      1│     99│      0│    7.66│  371.02│  106.47│  130.54│200:99\n  13s│      1│    100│      0│    7.66│  371.02│  106.47│  130.52│200:100\n\n\n*************************  结果 stat  ****************************\n处理协程数量: 1\n请求总数: 100 总请求时间: 13.055 秒 successNum: 100 failureNum: 0\n*************************  结果 end   ****************************\n\"><pre class=\"notranslate\"><code class=\"notranslate\">\n─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────\n 耗时│ 并发数 │ 成功数│ 失败数 │   qps  │最长耗时 │最短耗时│平均耗时 │ 错误码\n─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────\n   1s│      1│      8│      0│    8.09│  133.16│  110.98│  123.56│200:8\n   2s│      1│     15│      0│    8.02│  138.74│  110.98│  124.61│200:15\n   3s│      1│     23│      0│    7.80│  220.43│  110.98│  128.18│200:23\n   4s│      1│     31│      0│    7.83│  220.43│  110.23│  127.67│200:31\n   5s│      1│     39│      0│    7.81│  220.43│  110.23│  128.03│200:39\n   6s│      1│     46│      0│    7.72│  220.43│  110.23│  129.59│200:46\n   7s│      1│     54│      0│    7.79│  220.43│  110.23│  128.42│200:54\n   8s│      1│     62│      0│    7.81│  220.43│  110.23│  128.09│200:62\n   9s│      1│     70│      0│    7.79│  220.43│  110.23│  128.33│200:70\n  10s│      1│     78│      0│    7.82│  220.43│  106.47│  127.85│200:78\n  11s│      1│     84│      0│    7.64│  371.02│  106.47│  130.96│200:84\n  12s│      1│     91│      0│    7.63│  371.02│  106.47│  131.02│200:91\n  13s│      1│     99│      0│    7.66│  371.02│  106.47│  130.54│200:99\n  13s│      1│    100│      0│    7.66│  371.02│  106.47│  130.52│200:100\n\n\n*************************  结果 stat  ****************************\n处理协程数量: 1\n请求总数: 100 总请求时间: 13.055 秒 successNum: 100 failureNum: 0\n*************************  结果 end   ****************************\n\n</code></pre></div>\n<p dir=\"auto\">参数解释:</p>\n<p dir=\"auto\"><strong>耗时</strong>: 程序运行耗时。程序每秒钟输出一次压测结果</p>\n<p dir=\"auto\"><strong>并发数</strong>: 并发数，启动的协程数</p>\n<p dir=\"auto\"><strong>成功数</strong>: 压测中，请求成功的数量</p>\n<p dir=\"auto\"><strong>失败数</strong>: 压测中，请求失败的数量</p>\n<p dir=\"auto\"><strong>qps</strong>: 当前压测的 QPS (每秒钟处理请求数量)</p>\n<p dir=\"auto\"><strong>最长耗时</strong>: 压测中，单个请求最长的响应时长</p>\n<p dir=\"auto\"><strong>最短耗时</strong>: 压测中，单个请求最短的响应时长</p>\n<p dir=\"auto\"><strong>平均耗时</strong>: 压测中，单个请求平均的响应时长</p>\n<p dir=\"auto\"><strong>错误码</strong>: 压测中，接口返回的 code 码:返回次数的集合</p>\n<h2 dir=\"auto\">2、压测</h2>\n<h3 dir=\"auto\">2.1 压测是什么</h3>\n<p dir=\"auto\">压测，即压力测试，是确立系统稳定性的一种测试方法，通常在系统正常运作范围之外进行，以考察其功能极限和隐患。</p>\n<p dir=\"auto\">主要检测服务器的承受能力，包括用户承受能力（多少用户同时玩基本不影响质量）、流量承受等。</p>\n<h3 dir=\"auto\">2.2 为什么要压测</h3>\n<ul dir=\"auto\">\n<li>压测的目的就是通过压测(模拟真实用户的行为)，测算出机器的性能(单台机器的 QPS)，从而推算出系统在承受指定用户数(100W)时，需要多少机器能支撑得住</li>\n<li>压测是在上线前为了应对未来可能达到的用户数量的一次预估(提前演练)，压测以后通过优化程序的性能或准备充足的机器，来保证用户的体验。</li>\n</ul>\n<h3 dir=\"auto\">2.3 压测名词解释</h3>\n<h4 dir=\"auto\">2.3.1 压测类型解释</h4>\n<markdown-accessiblity-table><table role=\"table\">\n<thead>\n<tr>\n<th align=\"left\">压测类型</th>\n<th align=\"left\">解释</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"left\">压力测试(Stress Testing)</td>\n<td align=\"left\">也称之为强度测试，测试一个系统的最大抗压能力，在强负载(大数据、高并发)的情况下，测试系统所能承受的最大压力，预估系统的瓶颈</td>\n</tr>\n<tr>\n<td align=\"left\">并发测试(Concurrency Testing)</td>\n<td align=\"left\">通过模拟很多用户同一时刻访问系统或对系统某一个功能进行操作，来测试系统的性能，从中发现问题(并发读写、线程控制、资源争抢)</td>\n</tr>\n<tr>\n<td align=\"left\">耐久性测试(Configuration Testing)</td>\n<td align=\"left\">通过对系统在大负荷的条件下长时间运行，测试系统、机器的长时间运行下的状况，从中发现问题(内存泄漏、数据库连接池不释放、资源不回收)</td>\n</tr>\n</tbody>\n</table></markdown-accessiblity-table>\n<h4 dir=\"auto\">2.3.2 压测名词解释</h4>\n<markdown-accessiblity-table><table role=\"table\">\n<thead>\n<tr>\n<th align=\"left\">压测名词</th>\n<th align=\"left\">解释</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"left\">并发(Concurrency)</td>\n<td align=\"left\">指一个处理器同时处理多个任务的能力(逻辑上处理的能力)</td>\n</tr>\n<tr>\n<td align=\"left\">并行(Parallel)</td>\n<td align=\"left\">多个处理器或者是多核的处理器同时处理多个不同的任务(物理上同时执行)</td>\n</tr>\n<tr>\n<td align=\"left\">QPS(每秒钟查询数量 Queries Per Second)</td>\n<td align=\"left\">服务器每秒钟处理请求数量 (req/sec  请求数/秒  一段时间内总请求数/请求时间)</td>\n</tr>\n<tr>\n<td align=\"left\">事务(Transactions)</td>\n<td align=\"left\">是用户一次或者是几次请求的集合</td>\n</tr>\n<tr>\n<td align=\"left\">TPS(每秒钟处理事务数量 Transaction Per Second)</td>\n<td align=\"left\">服务器每秒钟处理事务数量(一个事务可能包括多个请求)</td>\n</tr>\n<tr>\n<td align=\"left\">请求成功数(Request Success Number)</td>\n<td align=\"left\">在一次压测中，请求成功的数量</td>\n</tr>\n<tr>\n<td align=\"left\">请求失败数(Request Failures Number)</td>\n<td align=\"left\">在一次压测中，请求失败的数量</td>\n</tr>\n<tr>\n<td align=\"left\">错误率(Error Rate)</td>\n<td align=\"left\">在压测中，请求成功的数量与请求失败数量的比率</td>\n</tr>\n<tr>\n<td align=\"left\">最大响应时间(Max Response Time)</td>\n<td align=\"left\">在一次压测中，从发出请求或指令系统做出的反映(响应)的最大时间</td>\n</tr>\n<tr>\n<td align=\"left\">最少响应时间(Mininum Response Time)</td>\n<td align=\"left\">在一次压测中，从发出请求或指令系统做出的反映(响应)的最少时间</td>\n</tr>\n<tr>\n<td align=\"left\">平均响应时间(Average Response Time)</td>\n<td align=\"left\">在一次压测中，从发出请求或指令系统做出的反映(响应)的平均时间</td>\n</tr>\n</tbody>\n</table></markdown-accessiblity-table>\n<h4 dir=\"auto\">2.3.3 机器性能指标解释</h4>\n<markdown-accessiblity-table><table role=\"table\">\n<thead>\n<tr>\n<th align=\"left\">机器性能</th>\n<th align=\"left\">解释</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"left\">CPU利用率(CPU Usage)</td>\n<td align=\"left\">CPU 利用率分用户态、系统态和空闲态，CPU 利用率是指：CPU 执行非系统空闲进程的时间与 CPU 总执行时间的比率</td>\n</tr>\n<tr>\n<td align=\"left\">内存使用率(Memory usage)</td>\n<td align=\"left\">内存使用率指的是此进程所开销的内存</td>\n</tr>\n<tr>\n<td align=\"left\">IO(Disk input/ output)</td>\n<td align=\"left\">磁盘的读写包速率</td>\n</tr>\n<tr>\n<td align=\"left\">网卡负载(Network Load)</td>\n<td align=\"left\">网卡的进出带宽，包量</td>\n</tr>\n</tbody>\n</table></markdown-accessiblity-table>\n<h4 dir=\"auto\">2.3.4 访问指标解释</h4>\n<markdown-accessiblity-table><table role=\"table\">\n<thead>\n<tr>\n<th align=\"left\">访问</th>\n<th align=\"left\">解释</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"left\">PV(页面浏览量 Page Views)</td>\n<td align=\"left\">一定时间范围内（时间范围可以是一天、一个月等自定义的时间段），用户每打开 1 个网站页面，记录 1 个 PV。用户多次打开同一页面，PV 值累计多次</td>\n</tr>\n<tr>\n<td align=\"left\">UV(网站独立访客 Unique Visitors)</td>\n<td align=\"left\">一定时间范围内（时间范围可以是一天、一个月等自定义的时间段），通过互联网访问、流量网站的自然人。相同访客多次访问网站，只计算为 1 个独立访客</td>\n</tr>\n</tbody>\n</table></markdown-accessiblity-table>\n<h3 dir=\"auto\">2.4 如何计算压测指标</h3>\n<ul dir=\"auto\">\n<li>\n<p dir=\"auto\">压测我们需要有目的性的压测，这次压测我们需要达到什么目标(如：单台机器的性能为 100 QPS ？网站能同时满足 100W 人同时在线)</p>\n</li>\n<li>\n<p dir=\"auto\">可以通过以下计算方法来进行计算：</p>\n</li>\n<li>\n<p dir=\"auto\">压测原则：每天 80% 的访问量集中在20%的时间里，这 20% 的时间就叫做峰值</p>\n</li>\n<li>\n<p dir=\"auto\">公式：( 总PV数<code class=\"notranslate\">*</code>80% ) / ( 每天的秒数<code class=\"notranslate\">*</code>20% ) = 峰值时间每秒钟请求数(QPS)</p>\n</li>\n<li>\n<p dir=\"auto\">机器：峰值时间每秒钟请求数(QPS) / 单台机器的QPS = 需要的机器的数量</p>\n</li>\n<li>\n<p dir=\"auto\">假设：网站每天的用户数(100W)，每天的用户的访问量约为 3000W PV，这台机器的需要多少 QPS ？</p>\n</li>\n</ul>\n<blockquote>\n<p dir=\"auto\">( 30000000*0.8 ) / (86400 * 0.2) ≈ 1389 (QPS)</p>\n</blockquote>\n<ul dir=\"auto\">\n<li>假设：单台机器的的 QPS 是 69，需要需要多少台机器来支撑？</li>\n</ul>\n<blockquote>\n<p dir=\"auto\">1389 / 69 ≈ 20</p>\n</blockquote>\n<h2 dir=\"auto\">3、常见的压测工具</h2>\n<h3 dir=\"auto\">3.1 ab</h3>\n<ul dir=\"auto\">\n<li>简介</li>\n</ul>\n<p dir=\"auto\">ApacheBench 是 Apache 服务器自带的一个web压力测试工具，简称 ab。ab 又是一个命令行工具，对发起负载的本机要求很低，根据 ab 命令可以创建很多的并发访问线程，模拟多个访问者同时对某一 URL 地址进行访问，因此可以用来测试目标服务器的负载压力。总的来说 ab 工具小巧简单，上手学习较快，可以提供需要的基本性能指标，但是没有图形化结果，不能监控。</p>\n<p dir=\"auto\">ab 属于一个轻量级的压测工具，结果不会特别准确，可以用作参考。</p>\n<ul dir=\"auto\">\n<li>安装</li>\n</ul>\n<div class=\"highlight highlight-source-shell notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"# 在linux环境安装\nsudo yum -y install httpd\"><pre class=\"notranslate\"><span class=\"pl-c\"><span class=\"pl-c\">#</span> 在linux环境安装</span>\nsudo yum -y install httpd</pre></div>\n<ul dir=\"auto\">\n<li>用法</li>\n</ul>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"Usage: ab [options] [http[s]://]hostname[:port]/path\n用法：ab [选项] 地址\n\n选项：\nOptions are:\n    -n requests      #执行的请求数，即一共发起多少请求。\n    -c concurrency   #请求并发数。\n    -s timeout       #指定每个请求的超时时间，默认是30秒。\n    -k               #启用HTTP KeepAlive功能，即在一个HTTP会话中执行多个请求。默认时，不启用KeepAlive功能。\"><pre class=\"notranslate\"><code class=\"notranslate\">Usage: ab [options] [http[s]://]hostname[:port]/path\n用法：ab [选项] 地址\n\n选项：\nOptions are:\n    -n requests      #执行的请求数，即一共发起多少请求。\n    -c concurrency   #请求并发数。\n    -s timeout       #指定每个请求的超时时间，默认是30秒。\n    -k               #启用HTTP KeepAlive功能，即在一个HTTP会话中执行多个请求。默认时，不启用KeepAlive功能。\n</code></pre></div>\n<ul dir=\"auto\">\n<li>压测命令</li>\n</ul>\n<div class=\"highlight highlight-source-shell notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"# 使用ab压测工具，对百度的链接 请求100次，并发数1\nab -n 100 -c 1 https://www.baidu.com/\"><pre class=\"notranslate\"><span class=\"pl-c\"><span class=\"pl-c\">#</span> 使用ab压测工具，对百度的链接 请求100次，并发数1</span>\nab -n 100 -c 1 https://www.baidu.com/</pre></div>\n<p dir=\"auto\">压测结果</p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"~ &gt;ab -n 100 -c 1 https://www.baidu.com/\nThis is ApacheBench, Version 2.3 &lt;$Revision: 1430300 $&gt;\nCopyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\nLicensed to The Apache Software Foundation, http://www.apache.org/\n\nBenchmarking www.baidu.com (be patient).....done\n\n\nServer Software:        BWS/1.1\nServer Hostname:        www.baidu.com\nServer Port:            443\nSSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128\n\nDocument Path:          /\nDocument Length:        227 bytes\n\nConcurrency Level:      1\nTime taken for tests:   9.430 seconds\nComplete requests:      100\nFailed requests:        0\nWrite errors:           0\nTotal transferred:      89300 bytes\nHTML transferred:       22700 bytes\nRequests per second:    10.60 [#/sec] (mean)\nTime per request:       94.301 [ms] (mean)\nTime per request:       94.301 [ms] (mean, across all concurrent requests)\nTransfer rate:          9.25 [Kbytes/sec] received\n\nConnection Times (ms)\n              min  mean[+/-sd] median   max\nConnect:       54   70  16.5     69     180\nProcessing:    18   24  12.0     23     140\nWaiting:       18   24  12.0     23     139\nTotal:         72   94  20.5     93     203\n\nPercentage of the requests served within a certain time (ms)\n  50%     93\n  66%     99\n  75%    101\n  80%    102\n  90%    108\n  95%    122\n  98%    196\n  99%    203\n 100%    203 (longest request)\"><pre class=\"notranslate\"><code class=\"notranslate\">~ &gt;ab -n 100 -c 1 https://www.baidu.com/\nThis is ApacheBench, Version 2.3 &lt;$Revision: 1430300 $&gt;\nCopyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\nLicensed to The Apache Software Foundation, http://www.apache.org/\n\nBenchmarking www.baidu.com (be patient).....done\n\n\nServer Software:        BWS/1.1\nServer Hostname:        www.baidu.com\nServer Port:            443\nSSL/TLS Protocol:       TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128\n\nDocument Path:          /\nDocument Length:        227 bytes\n\nConcurrency Level:      1\nTime taken for tests:   9.430 seconds\nComplete requests:      100\nFailed requests:        0\nWrite errors:           0\nTotal transferred:      89300 bytes\nHTML transferred:       22700 bytes\nRequests per second:    10.60 [#/sec] (mean)\nTime per request:       94.301 [ms] (mean)\nTime per request:       94.301 [ms] (mean, across all concurrent requests)\nTransfer rate:          9.25 [Kbytes/sec] received\n\nConnection Times (ms)\n              min  mean[+/-sd] median   max\nConnect:       54   70  16.5     69     180\nProcessing:    18   24  12.0     23     140\nWaiting:       18   24  12.0     23     139\nTotal:         72   94  20.5     93     203\n\nPercentage of the requests served within a certain time (ms)\n  50%     93\n  66%     99\n  75%    101\n  80%    102\n  90%    108\n  95%    122\n  98%    196\n  99%    203\n 100%    203 (longest request)\n</code></pre></div>\n<ul dir=\"auto\">\n<li>\n<p dir=\"auto\">主要关注的测试指标</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Concurrency Level</code> 并发请求数</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Time taken for tests</code> 整个测试时间</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Complete requests</code> 完成请求个数</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Failed requests</code> 失败个数</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Requests per second</code> 吞吐量，指的是某个并发用户下单位时间内处理的请求数。等效于 QPS，其实可以看作同一个统计方式，只是叫法不同而已。</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Time per request</code> 用户平均请求等待时间</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Time per request</code> 服务器处理时间</p>\n</li>\n</ul>\n<h3 dir=\"auto\">3.2 Locust</h3>\n<ul dir=\"auto\">\n<li>简介</li>\n</ul>\n<p dir=\"auto\">是非常简单易用、分布式、python 开发的压力测试工具。有图形化界面，支持将压测数据导出。</p>\n<ul dir=\"auto\">\n<li>安装</li>\n</ul>\n<div class=\"highlight highlight-source-shell notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"# pip3 安装locust\npip3  install locust\n# 查看是否安装成功\nlocust -h\n# 运行 Locust 分布在多个进程/机器库\npip3 install pyzmq\n# webSocket 压测库\npip3 install websocket-client\"><pre class=\"notranslate\"><span class=\"pl-c\"><span class=\"pl-c\">#</span> pip3 安装locust</span>\npip3  install locust\n<span class=\"pl-c\"><span class=\"pl-c\">#</span> 查看是否安装成功</span>\nlocust -h\n<span class=\"pl-c\"><span class=\"pl-c\">#</span> 运行 Locust 分布在多个进程/机器库</span>\npip3 install pyzmq\n<span class=\"pl-c\"><span class=\"pl-c\">#</span> webSocket 压测库</span>\npip3 install websocket-client</pre></div>\n<ul dir=\"auto\">\n<li>用法</li>\n</ul>\n<p dir=\"auto\">编写压测脚本 <strong>test.py</strong></p>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"from locust import HttpUser, TaskSet, task\n\n# 定义用户行为\nclass UserBehavior(TaskSet):\n\n    @task\n    def baidu_index(self):\n        self.client.get(&quot;/&quot;)\n\nclass WebsiteUser(HttpUser):\n    task = [UserBehavior] # 指向一个定义的用户行为类\n    min_wait = 3000 # 执行事务之间用户等待时间的下界（单位：毫秒）\n    max_wait = 6000 # 执行事务之间用户等待时间的上界（单位：毫秒）\"><pre class=\"notranslate\"><span class=\"pl-k\">from</span> <span class=\"pl-s1\">locust</span> <span class=\"pl-k\">import</span> <span class=\"pl-v\">HttpUser</span>, <span class=\"pl-v\">TaskSet</span>, <span class=\"pl-s1\">task</span>\n\n<span class=\"pl-c\"># 定义用户行为</span>\n<span class=\"pl-k\">class</span> <span class=\"pl-v\">UserBehavior</span>(<span class=\"pl-v\">TaskSet</span>):\n\n    <span class=\"pl-en\">@<span class=\"pl-s1\">task</span></span>\n    <span class=\"pl-k\">def</span> <span class=\"pl-en\">baidu_index</span>(<span class=\"pl-s1\">self</span>):\n        <span class=\"pl-s1\">self</span>.<span class=\"pl-c1\">client</span>.<span class=\"pl-c1\">get</span>(<span class=\"pl-s\">\"/\"</span>)\n\n<span class=\"pl-k\">class</span> <span class=\"pl-v\">WebsiteUser</span>(<span class=\"pl-v\">HttpUser</span>):\n    <span class=\"pl-s1\">task</span> <span class=\"pl-c1\">=</span> [<span class=\"pl-v\">UserBehavior</span>] <span class=\"pl-c\"># 指向一个定义的用户行为类</span>\n    <span class=\"pl-s1\">min_wait</span> <span class=\"pl-c1\">=</span> <span class=\"pl-c1\">3000</span> <span class=\"pl-c\"># 执行事务之间用户等待时间的下界（单位：毫秒）</span>\n    <span class=\"pl-s1\">max_wait</span> <span class=\"pl-c1\">=</span> <span class=\"pl-c1\">6000</span> <span class=\"pl-c\"># 执行事务之间用户等待时间的上界（单位：毫秒）</span></pre></div>\n<ul dir=\"auto\">\n<li>启动压测</li>\n</ul>\n<div class=\"highlight highlight-source-shell notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"locust -f  test.py --host=https://www.baidu.com\"><pre class=\"notranslate\">locust -f  test.py --host=https://www.baidu.com</pre></div>\n<p dir=\"auto\">访问 <a href=\"http://localhost:8089\" rel=\"nofollow\">http://localhost:8089</a> 进入压测首页</p>\n<p dir=\"auto\">Number of users to simulate 模拟用户数</p>\n<p dir=\"auto\">Hatch rate (users spawned/second) 每秒钟增加用户数</p>\n<p dir=\"auto\">点击 \"Start swarming\" 进入压测页面</p>\n<p dir=\"auto\"><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"img/locust%20%E9%A6%96%E9%A1%B5.png\"><img src=\"img/locust%20%E9%A6%96%E9%A1%B5.png\" alt=\"locust 首页\" style=\"max-width: 100%;\"></a></p>\n<p dir=\"auto\">压测界面右上角有:被压测的地址、当前状态、RPS、失败率、开始或重启按钮</p>\n<p dir=\"auto\">性能测试参数</p>\n<ul dir=\"auto\">\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Type</code> 请求的类型，例如GET/POST</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Name</code> 请求的路径</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Request</code> 当前请求的数量</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Fails</code> 当前请求失败的数量</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Median</code> 中间值，单位毫秒，请求响应时间的中间值</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Average</code> 平均值，单位毫秒，请求的平均响应时间</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Min</code> 请求的最小服务器响应时间，单位毫秒</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Max</code> 请求的最大服务器响应时间，单位毫秒</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Average size</code> 单个请求的大小，单位字节</p>\n</li>\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">Current RPS</code> 代表吞吐量(Requests Per Second的缩写)，指的是某个并发用户数下单位时间内处理的请求数。等效于QPS，其实可以看作同一个统计方式，只是叫法不同而已。</p>\n</li>\n</ul>\n<p dir=\"auto\"><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"img/locust%20%E5%8E%8B%E6%B5%8B%E9%A1%B5%E9%9D%A2.png\"><img src=\"img/locust%20%E5%8E%8B%E6%B5%8B%E9%A1%B5%E9%9D%A2.png\" alt=\"locust 压测页面\" style=\"max-width: 100%;\"></a></p>\n<h3 dir=\"auto\">3.3 JMeter</h3>\n<ul dir=\"auto\">\n<li>简介</li>\n</ul>\n<p dir=\"auto\">Apache JMeter是Apache组织开发的基于Java的压力测试工具。用于对软件做压力测试，它最初被设计用于Web应用测试，但后来扩展到其他测试领域。<br>\nJMeter能够对应用程序做功能/回归测试，通过创建带有断言的脚本来验证你的程序返回了你期望的结果。</p>\n<ul dir=\"auto\">\n<li>安装</li>\n</ul>\n<p dir=\"auto\">访问 <a href=\"https://jmeter-plugins.org/install/Install/\" rel=\"nofollow\">https://jmeter-plugins.org/install/Install/</a> 下载解压以后即可使用</p>\n<ul dir=\"auto\">\n<li>用法</li>\n</ul>\n<p dir=\"auto\">JMeter的功能过于强大，这里暂时不介绍用法，可以查询相关文档使用(参考文献中有推荐的教程文档)</p>\n<h3 dir=\"auto\">3.4 云压测</h3>\n<h4 dir=\"auto\">3.4.1 云压测介绍</h4>\n<p dir=\"auto\">顾名思义就是将压测脚本部署在云端，通过云端对对我们的应用进行全方位压测，只需要配置压测的参数，无需准备实体机，云端自动给我们分配需要压测的云主机，对被压测目标进行压测。</p>\n<p dir=\"auto\">云压测的优势:</p>\n<ol dir=\"auto\">\n<li>轻易的实现分布式部署</li>\n<li>能够模拟海量用户的访问</li>\n<li>流量可以从全国各地发起，更加真实的反映用户的体验</li>\n<li>全方位的监控压测指标</li>\n<li>文档比较完善</li>\n</ol>\n<p dir=\"auto\">当然了云压测是一款商业产品，在使用的时候自然还是需要收费的，而且价格还是比较昂贵的~</p>\n<h4 dir=\"auto\">3.4.2 阿里云 性能测试 PTS</h4>\n<p dir=\"auto\">PTS（Performance Testing Service）是面向所有技术背景人员的云化测试工具。有别于传统工具的繁复，PTS以互联网化的交互，提供性能测试、API调试和监测等多种能力。自研和适配开源的功能都可以轻松模拟任意体量的用户访问业务的场景，任务随时发起，免去繁琐的搭建和维护成本。更是紧密结合监控、流控等兄弟产品提供一站式高可用能力，高效检验和管理业务性能。</p>\n<p dir=\"auto\">阿里云同样还是支持渗透测试，通过模拟黑客对业务系统进行全面深入的安全测试。</p>\n<h4 dir=\"auto\">3.4.3 腾讯云 压测大师 LM</h4>\n<p dir=\"auto\">通过创建虚拟机器人模拟多用户的并发场景，提供一整套完整的服务器压测解决方案</p>\n<h2 dir=\"auto\">4、go-stress-testing go语言实现的压测工具</h2>\n<h3 dir=\"auto\">4.1 介绍</h3>\n<ul dir=\"auto\">\n<li>\n<p dir=\"auto\">go-stress-testing 是go语言实现的简单压测工具，源码开源、支持二次开发，可以压测http、webSocket请求、私有rpc调用，使用协程模拟单个用户，可以更高效的利用CPU资源。</p>\n</li>\n<li>\n<p dir=\"auto\">项目地址 <a href=\"https://github.com/link1st/go-stress-testing\">https://github.com/link1st/go-stress-testing</a></p>\n</li>\n</ul>\n<h3 dir=\"auto\">4.2 用法</h3>\n<ul dir=\"auto\">\n<li><a href=\"https://github.com/link1st/go-stress-testing/releases\">go-stress-testing</a> 下载地址</li>\n<li>clone 项目源码运行的时候，需要将项目 clone 到 <strong>$GOPATH</strong> 目录下</li>\n<li>支持参数:</li>\n</ul>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"Usage of ./go-stress-testing-mac:\n  -c uint\n      并发数 (default 1)\n  -n uint\n      请求数(单个并发/协程) (default 1)\n  -u string\n      压测地址\n  -d string\n      调试模式 (default &quot;false&quot;)\n  -http2\n    \t是否开http2.0\n  -k\t是否开启长连接\n  -m int\n    \t单个host最大连接数 (default 1)\n  -H value\n      自定义头信息传递给服务器 示例:-H 'Content-Type: application/json'\n  -data string\n      HTTP POST方式传送数据\n  -v string\n      验证方法 http 支持:statusCode、json webSocket支持:json\n  -p string\n      curl文件路径\"><pre class=\"notranslate\"><code class=\"notranslate\">Usage of ./go-stress-testing-mac:\n  -c uint\n      并发数 (default 1)\n  -n uint\n      请求数(单个并发/协程) (default 1)\n  -u string\n      压测地址\n  -d string\n      调试模式 (default \"false\")\n  -http2\n    \t是否开http2.0\n  -k\t是否开启长连接\n  -m int\n    \t单个host最大连接数 (default 1)\n  -H value\n      自定义头信息传递给服务器 示例:-H 'Content-Type: application/json'\n  -data string\n      HTTP POST方式传送数据\n  -v string\n      验证方法 http 支持:statusCode、json webSocket支持:json\n  -p string\n      curl文件路径\n</code></pre></div>\n<ul dir=\"auto\">\n<li>\n<p dir=\"auto\"><code class=\"notranslate\">-n</code> 是单个用户请求的次数，请求总次数 = <code class=\"notranslate\">-c</code>* <code class=\"notranslate\">-n</code>， 这里考虑的是模拟用户行为，所以这个是每个用户请求的次数</p>\n</li>\n<li>\n<p dir=\"auto\">下载以后执行下面命令即可压测</p>\n</li>\n<li>\n<p dir=\"auto\">使用示例:</p>\n</li>\n</ul>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"# 查看用法\n./go-stress-testing-mac\n\n# 使用请求百度页面\n./go-stress-testing-mac -c 1 -n 100 -u https://www.baidu.com/\n\n# 使用debug模式请求百度页面\n./go-stress-testing-mac -c 1 -n 1 -d true -u https://www.baidu.com/\n\n# 使用 curl文件(文件在curl目录下) 的方式请求\n./go-stress-testing-mac -c 1 -n 1 -p curl/baidu.curl.txt\n\n# 压测webSocket连接\n./go-stress-testing-mac -c 10 -n 10 -u ws://127.0.0.1:8089/acc\"><pre class=\"notranslate\"><code class=\"notranslate\"># 查看用法\n./go-stress-testing-mac\n\n# 使用请求百度页面\n./go-stress-testing-mac -c 1 -n 100 -u https://www.baidu.com/\n\n# 使用debug模式请求百度页面\n./go-stress-testing-mac -c 1 -n 1 -d true -u https://www.baidu.com/\n\n# 使用 curl文件(文件在curl目录下) 的方式请求\n./go-stress-testing-mac -c 1 -n 1 -p curl/baidu.curl.txt\n\n# 压测webSocket连接\n./go-stress-testing-mac -c 10 -n 10 -u ws://127.0.0.1:8089/acc\n</code></pre></div>\n<ul dir=\"auto\">\n<li>完整压测命令示例</li>\n</ul>\n<div class=\"highlight highlight-source-shell notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"# 更多参数 支持 header、post body\ngo run main.go -c 1 -n 1 -d true -u 'https://page.aliyun.com/delivery/plan/list' \\\n  -H 'authority: page.aliyun.com' \\\n  -H 'accept: application/json, text/plain, */*' \\\n  -H 'content-type: application/x-www-form-urlencoded' \\\n  -H 'origin: https://cn.aliyun.com' \\\n  -H 'sec-fetch-site: same-site' \\\n  -H 'sec-fetch-mode: cors' \\\n  -H 'sec-fetch-dest: empty' \\\n  -H 'referer: https://cn.aliyun.com/' \\\n  -H 'accept-language: zh-CN,zh;q=0.9' \\\n  -H 'cookie: aliyun_choice=CN; JSESSIONID=J8866281-CKCFJ4BUZ7GDO9V89YBW1-KJ3J5V9K-GYUW7; maliyun_temporary_console0=1AbLByOMHeZe3G41KYd5WWZvrM%2BGErkaLcWfBbgveKA9ifboArprPASvFUUfhwHtt44qsDwVqMk8Wkdr1F5LccYk2mPCZJiXb0q%2Bllj5u3SQGQurtyPqnG489y%2FkoA%2FEvOwsXJTvXTFQPK%2BGJD4FJg%3D%3D; cna=L3Q5F8cHDGgCAXL3r8fEZtdU; isg=BFNThsmSCcgX-sUcc5Jo2s2T4tF9COfKYi8g9wVwr3KphHMmjdh3GrHFvPTqJD_C; l=eBaceXLnQGBjstRJBOfwPurza77OSIRAguPzaNbMiT5POw1B5WAlWZbqyNY6C3GVh6lwR37EODnaBeYBc3K-nxvOu9eFfGMmn' \\\n  -data 'adPlanQueryParam=%7B%22adZone%22%3A%7B%22positionList%22%3A%5B%7B%22positionId%22%3A83%7D%5D%7D%2C%22requestId%22%3A%2217958651-f205-44c7-ad5d-f8af92a6217a%22%7D'\"><pre class=\"notranslate\"><span class=\"pl-c\"><span class=\"pl-c\">#</span> 更多参数 支持 header、post body</span>\ngo run main.go -c 1 -n 1 -d <span class=\"pl-c1\">true</span> -u <span class=\"pl-s\"><span class=\"pl-pds\">'</span>https://page.aliyun.com/delivery/plan/list<span class=\"pl-pds\">'</span></span> \\\n  -H <span class=\"pl-s\"><span class=\"pl-pds\">'</span>authority: page.aliyun.com<span class=\"pl-pds\">'</span></span> \\\n  -H <span class=\"pl-s\"><span class=\"pl-pds\">'</span>accept: application/json, text/plain, */*<span class=\"pl-pds\">'</span></span> \\\n  -H <span class=\"pl-s\"><span class=\"pl-pds\">'</span>content-type: application/x-www-form-urlencoded<span class=\"pl-pds\">'</span></span> \\\n  -H <span class=\"pl-s\"><span class=\"pl-pds\">'</span>origin: https://cn.aliyun.com<span class=\"pl-pds\">'</span></span> \\\n  -H <span class=\"pl-s\"><span class=\"pl-pds\">'</span>sec-fetch-site: same-site<span class=\"pl-pds\">'</span></span> \\\n  -H <span class=\"pl-s\"><span class=\"pl-pds\">'</span>sec-fetch-mode: cors<span class=\"pl-pds\">'</span></span> \\\n  -H <span class=\"pl-s\"><span class=\"pl-pds\">'</span>sec-fetch-dest: empty<span class=\"pl-pds\">'</span></span> \\\n  -H <span class=\"pl-s\"><span class=\"pl-pds\">'</span>referer: https://cn.aliyun.com/<span class=\"pl-pds\">'</span></span> \\\n  -H <span class=\"pl-s\"><span class=\"pl-pds\">'</span>accept-language: zh-CN,zh;q=0.9<span class=\"pl-pds\">'</span></span> \\\n  -H <span class=\"pl-s\"><span class=\"pl-pds\">'</span>cookie: aliyun_choice=CN; JSESSIONID=J8866281-CKCFJ4BUZ7GDO9V89YBW1-KJ3J5V9K-GYUW7; maliyun_temporary_console0=1AbLByOMHeZe3G41KYd5WWZvrM%2BGErkaLcWfBbgveKA9ifboArprPASvFUUfhwHtt44qsDwVqMk8Wkdr1F5LccYk2mPCZJiXb0q%2Bllj5u3SQGQurtyPqnG489y%2FkoA%2FEvOwsXJTvXTFQPK%2BGJD4FJg%3D%3D; cna=L3Q5F8cHDGgCAXL3r8fEZtdU; isg=BFNThsmSCcgX-sUcc5Jo2s2T4tF9COfKYi8g9wVwr3KphHMmjdh3GrHFvPTqJD_C; l=eBaceXLnQGBjstRJBOfwPurza77OSIRAguPzaNbMiT5POw1B5WAlWZbqyNY6C3GVh6lwR37EODnaBeYBc3K-nxvOu9eFfGMmn<span class=\"pl-pds\">'</span></span> \\\n  -data <span class=\"pl-s\"><span class=\"pl-pds\">'</span>adPlanQueryParam=%7B%22adZone%22%3A%7B%22positionList%22%3A%5B%7B%22positionId%22%3A83%7D%5D%7D%2C%22requestId%22%3A%2217958651-f205-44c7-ad5d-f8af92a6217a%22%7D<span class=\"pl-pds\">'</span></span></pre></div>\n<ul dir=\"auto\">\n<li>使用 curl文件进行压测</li>\n</ul>\n<p dir=\"auto\">curl是Linux在命令行下的工作的文件传输工具，是一款很强大的http命令行工具。</p>\n<p dir=\"auto\">使用curl文件可以压测使用非GET的请求，支持设置http请求的 method、cookies、header、body等参数</p>\n<p dir=\"auto\"><strong>I:</strong> chrome 浏览器生成 curl文件，打开开发者模式(快捷键F12)，如图所示，生成 curl 在终端执行命令<br>\n<a target=\"_blank\" rel=\"noopener noreferrer\" href=\"img/copy%20cURL.png\"><img src=\"img/copy%20cURL.png\" alt=\"chrome cURL\" style=\"max-width: 100%;\"></a></p>\n<p dir=\"auto\"><strong>II:</strong> postman 生成 curl 命令<br>\n<a target=\"_blank\" rel=\"noopener noreferrer\" href=\"img/postman%20cURL.png\"><img src=\"img/postman%20cURL.png\" alt=\"postman cURL\" style=\"max-width: 100%;\"></a></p>\n<p dir=\"auto\">生成内容粘贴到项目目录下的<strong>curl/baidu.curl.txt</strong>文件中，执行下面命令就可以从curl.txt文件中读取需要压测的内容进行压测了</p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"# 使用 curl文件(文件在curl目录下) 的方式请求\ngo run main.go -c 1 -n 1 -p curl/baidu.curl.txt\"><pre class=\"notranslate\"><code class=\"notranslate\"># 使用 curl文件(文件在curl目录下) 的方式请求\ngo run main.go -c 1 -n 1 -p curl/baidu.curl.txt\n</code></pre></div>\n<h3 dir=\"auto\">4.3 实现</h3>\n<ul dir=\"auto\">\n<li>\n<p dir=\"auto\">具体需求可以查看项目源码</p>\n</li>\n<li>\n<p dir=\"auto\">项目目录结构</p>\n</li>\n</ul>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"|____main.go                      // main函数，获取命令行参数\n|____server                       // 处理程序目录\n| |____dispose.go                 // 压测启动，注册验证器、启动统计函数、启动协程进行压测\n| |____statistics                 // 统计目录\n| | |____statistics.go            // 接收压测统计结果并处理\n| |____golink                     // 建立连接目录\n| | |____http_link.go             // http建立连接\n| | |____websocket_link.go        // webSocket建立连接\n| |____client                     // 请求数据客户端目录\n| | |____http_client.go           // http客户端\n| | |____websocket_client.go      // webSocket客户端\n| |____verify                     // 对返回数据校验目录\n| | |____http_verify.go           // http返回数据校验\n| | |____websokcet_verify.go      // webSocket返回数据校验\n|____heper                        // 通用函数目录\n| |____heper.go                   // 通用函数\n|____model                        // 模型目录\n| |____request_model.go           // 请求数据模型\n| |____curl_model.go              // curl文件解析\n|____vendor                       // 项目依赖目录\"><pre class=\"notranslate\"><code class=\"notranslate\">|____main.go                      // main函数，获取命令行参数\n|____server                       // 处理程序目录\n| |____dispose.go                 // 压测启动，注册验证器、启动统计函数、启动协程进行压测\n| |____statistics                 // 统计目录\n| | |____statistics.go            // 接收压测统计结果并处理\n| |____golink                     // 建立连接目录\n| | |____http_link.go             // http建立连接\n| | |____websocket_link.go        // webSocket建立连接\n| |____client                     // 请求数据客户端目录\n| | |____http_client.go           // http客户端\n| | |____websocket_client.go      // webSocket客户端\n| |____verify                     // 对返回数据校验目录\n| | |____http_verify.go           // http返回数据校验\n| | |____websokcet_verify.go      // webSocket返回数据校验\n|____heper                        // 通用函数目录\n| |____heper.go                   // 通用函数\n|____model                        // 模型目录\n| |____request_model.go           // 请求数据模型\n| |____curl_model.go              // curl文件解析\n|____vendor                       // 项目依赖目录\n</code></pre></div>\n<h3 dir=\"auto\">4.4 go-stress-testing 对 Golang web 压测</h3>\n<p dir=\"auto\">这里使用go-stress-testing对go server进行压测(部署在同一台机器上)，并统计压测结果</p>\n<ul dir=\"auto\">\n<li>申请的服务器配置</li>\n</ul>\n<p dir=\"auto\">CPU: 4核 (Intel Xeon(Cascade Lake) Platinum 8269  2.5 GHz/3.2 GHz)</p>\n<p dir=\"auto\">内存: 16G<br>\n硬盘: 20G SSD<br>\n系统: CentOS 7.6</p>\n<p dir=\"auto\">go version: go1.12.9 linux/amd64</p>\n<p dir=\"auto\"><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"img/go-stress-testing01.png\"><img src=\"img/go-stress-testing01.png\" alt=\"go-stress-testing01\" style=\"max-width: 100%;\"></a></p>\n<ul dir=\"auto\">\n<li>go server</li>\n</ul>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"\nimport (\n    &quot;log&quot;\n    &quot;net/http&quot;\n    &quot;runtime&quot;\n)\n\nconst (\n    httpPort = &quot;8088&quot;\n)\n\nfunc main() {\n\n    runtime.GOMAXPROCS(runtime.NumCPU() - 1)\n\n    hello := func(w http.ResponseWriter, req *http.Request) {\n        data := &quot;Hello, go-stress-testing! \\n&quot;\n\n        w.Header().Add(&quot;Server&quot;, &quot;golang&quot;)\n        w.Write([]byte(data))\n\n        return\n    }\n\n    http.HandleFunc(&quot;/&quot;, hello)\n    err := http.ListenAndServe(&quot;:&quot;+httpPort, nil)\n\n    if err != nil {\n        log.Fatal(&quot;ListenAndServe: &quot;, err)\n    }\n}\n\"><pre lang=\"golangpackage\" class=\"notranslate\"><code class=\"notranslate\">\nimport (\n    \"log\"\n    \"net/http\"\n    \"runtime\"\n)\n\nconst (\n    httpPort = \"8088\"\n)\n\nfunc main() {\n\n    runtime.GOMAXPROCS(runtime.NumCPU() - 1)\n\n    hello := func(w http.ResponseWriter, req *http.Request) {\n        data := \"Hello, go-stress-testing! \\n\"\n\n        w.Header().Add(\"Server\", \"golang\")\n        w.Write([]byte(data))\n\n        return\n    }\n\n    http.HandleFunc(\"/\", hello)\n    err := http.ListenAndServe(\":\"+httpPort, nil)\n\n    if err != nil {\n        log.Fatal(\"ListenAndServe: \", err)\n    }\n}\n\n</code></pre></div>\n<ul dir=\"auto\">\n<li>go_stress_testing 压测命令</li>\n</ul>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"./go-stress-testing-linux -c 100 -n 10000 -u http://127.0.0.1:8088/\"><pre class=\"notranslate\"><code class=\"notranslate\">./go-stress-testing-linux -c 100 -n 10000 -u http://127.0.0.1:8088/\n</code></pre></div>\n<ul dir=\"auto\">\n<li>压测结果</li>\n<li><a href=\"https://github.com/link1st/go-stress-testing/issues/32\" data-hovercard-type=\"issue\" data-hovercard-url=\"/link1st/go-stress-testing/issues/32/hovercard\">压测结果 示例</a></li>\n</ul>\n<markdown-accessiblity-table><table role=\"table\">\n<thead>\n<tr>\n<th align=\"center\">并发数</th>\n<th align=\"center\">go_stress_testing QPS</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"center\">1</td>\n<td align=\"center\">6394.86</td>\n</tr>\n<tr>\n<td align=\"center\">4</td>\n<td align=\"center\">16909.36</td>\n</tr>\n<tr>\n<td align=\"center\">10</td>\n<td align=\"center\">18456.81</td>\n</tr>\n<tr>\n<td align=\"center\">20</td>\n<td align=\"center\">19490.50</td>\n</tr>\n<tr>\n<td align=\"center\">30</td>\n<td align=\"center\">19947.47</td>\n</tr>\n<tr>\n<td align=\"center\">50</td>\n<td align=\"center\">19922.56</td>\n</tr>\n<tr>\n<td align=\"center\">80</td>\n<td align=\"center\">19155.33</td>\n</tr>\n<tr>\n<td align=\"center\">100</td>\n<td align=\"center\">18336.46</td>\n</tr>\n</tbody>\n</table></markdown-accessiblity-table>\n<p dir=\"auto\">从压测的结果上看：效果还不错，压测QPS有接近2W</p>\n<h3 dir=\"auto\">4.5 grpc压测</h3>\n<ul dir=\"auto\">\n<li>介绍如何压测 grpc 接口</li>\n</ul>\n<blockquote>\n<p dir=\"auto\"><a href=\"https://github.com/link1st/go-stress-testing/commit/2b4b14aaf026d08276531cf76f42de90efd3bc61\">添加对 grpc 接口压测 commit</a></p>\n</blockquote>\n<ul dir=\"auto\">\n<li>\n<ol dir=\"auto\">\n<li>启动Server</li>\n</ol>\n</li>\n</ul>\n<div class=\"highlight highlight-source-shell notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"# 进入 grpc server 目录\ncd tests/grpc\n\n# 启动 grpc server\ngo run main.go\"><pre class=\"notranslate\"><span class=\"pl-c\"><span class=\"pl-c\">#</span> 进入 grpc server 目录</span>\n<span class=\"pl-c1\">cd</span> tests/grpc\n\n<span class=\"pl-c\"><span class=\"pl-c\">#</span> 启动 grpc server</span>\ngo run main.go</pre></div>\n<ul dir=\"auto\">\n<li>\n<ol start=\"2\" dir=\"auto\">\n<li>对 grpc server 协议进行压测</li>\n</ol>\n</li>\n</ul>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"# 回到项目根目录\ngo run main.go -c 300 -n 1000 -u grpc://127.0.0.1:8099 -data world\n\n开始启动  并发数:300 请求数:1000 请求参数:\nrequest:\n form:grpc\n url:grpc://127.0.0.1:8099\n method:POST\n headers:map[Content-Type:application/x-www-form-urlencoded; charset=utf-8]\n data:world\n verify:\n timeout:30s\n debug:false\n\n─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────┬────────┬────────\n 耗时 │ 并发数 │ 成功数 │ 失败数 │   qps  │最长耗时  │最短耗时 │平均耗时  │下载字节 │字节每秒  │ 错误码\n─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────┼────────┼────────\n   1s│    186│  14086│      0│34177.69│   22.40│    0.63│    8.78│        │        │200:14086\n   2s│    265│  30408│      0│26005.09│   32.68│    0.63│   11.54│        │        │200:30408\n   3s│    300│  46747│      0│21890.46│   40.84│    0.63│   13.70│        │        │200:46747\n   4s│    300│  62837│      0│20057.06│   45.81│    0.63│   14.96│        │        │200:62837\n   5s│    300│  79119│      0│19134.52│   45.81│    0.63│   15.68│        │        │200:79119\"><pre class=\"notranslate\"><code class=\"notranslate\"># 回到项目根目录\ngo run main.go -c 300 -n 1000 -u grpc://127.0.0.1:8099 -data world\n\n开始启动  并发数:300 请求数:1000 请求参数:\nrequest:\n form:grpc\n url:grpc://127.0.0.1:8099\n method:POST\n headers:map[Content-Type:application/x-www-form-urlencoded; charset=utf-8]\n data:world\n verify:\n timeout:30s\n debug:false\n\n─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────┬────────┬────────\n 耗时 │ 并发数 │ 成功数 │ 失败数 │   qps  │最长耗时  │最短耗时 │平均耗时  │下载字节 │字节每秒  │ 错误码\n─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────┼────────┼────────\n   1s│    186│  14086│      0│34177.69│   22.40│    0.63│    8.78│        │        │200:14086\n   2s│    265│  30408│      0│26005.09│   32.68│    0.63│   11.54│        │        │200:30408\n   3s│    300│  46747│      0│21890.46│   40.84│    0.63│   13.70│        │        │200:46747\n   4s│    300│  62837│      0│20057.06│   45.81│    0.63│   14.96│        │        │200:62837\n   5s│    300│  79119│      0│19134.52│   45.81│    0.63│   15.68│        │        │200:79119\n</code></pre></div>\n<ul dir=\"auto\">\n<li>如何扩展其它私有协议</li>\n</ul>\n<blockquote>\n<p dir=\"auto\">由于私有协议、grpc 协议 都涉及到代码的书写，所以需要 编写go 的代码才能完成<br>\n参考 <a href=\"https://github.com/link1st/go-stress-testing/commit/2b4b14aaf026d08276531cf76f42de90efd3bc61\">添加对 grpc 接口压测 commit</a></p>\n</blockquote>\n<h2 dir=\"auto\">5、压测工具的比较</h2>\n<h3 dir=\"auto\">5.1 比较</h3>\n<markdown-accessiblity-table><table role=\"table\">\n<thead>\n<tr>\n<th align=\"left\">-</th>\n<th align=\"left\">ab</th>\n<th align=\"left\">locust</th>\n<th align=\"left\">Jmeter</th>\n<th align=\"left\">go-stress-testing</th>\n<th align=\"left\">云压测</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"left\">实现语言</td>\n<td align=\"left\">C</td>\n<td align=\"left\">Python</td>\n<td align=\"left\">Java</td>\n<td align=\"left\">Golang</td>\n<td align=\"left\">-</td>\n</tr>\n<tr>\n<td align=\"left\">UI界面</td>\n<td align=\"left\">无</td>\n<td align=\"left\">有</td>\n<td align=\"left\">有</td>\n<td align=\"left\">无</td>\n<td align=\"left\">无</td>\n</tr>\n<tr>\n<td align=\"left\">优势</td>\n<td align=\"left\">使用简单，上手简单</td>\n<td align=\"left\">支持分布式、压测数据支持导出</td>\n<td align=\"left\">插件丰富，支持生成HTML报告</td>\n<td align=\"left\">项目开源，使用简单，没有依赖，支持webSocket压测</td>\n<td align=\"left\">更加真实的模拟用户，支持更高的压测力度</td>\n</tr>\n</tbody>\n</table></markdown-accessiblity-table>\n<h3 dir=\"auto\">5.2 如何选择压测工具</h3>\n<p dir=\"auto\">这个世界上<strong>没有最好的，只有最适合的</strong>，工具千千万，选择一款适合你的才是最重要的</p>\n<p dir=\"auto\">在实际使用中有各种场景，选择工具的时候就需要考虑这些:</p>\n<ul dir=\"auto\">\n<li>\n<p dir=\"auto\">明确你的目的，需要做什么压测、压测的目标是什么？</p>\n</li>\n<li>\n<p dir=\"auto\">使用的工具你是否熟悉，你愿意花多大的成本了解它？</p>\n</li>\n<li>\n<p dir=\"auto\">你是为了测试还是想了解其中的原理？</p>\n</li>\n<li>\n<p dir=\"auto\">工具是否能支持你需要压测的场景</p>\n</li>\n</ul>\n<h2 dir=\"auto\">6、单台机器100w连接压测实战</h2>\n<h3 dir=\"auto\">6.1 说明</h3>\n<p dir=\"auto\">之前写了一篇文章，<a href=\"https://github.com/link1st/gowebsocket\">基于websocket单台机器支持百万连接分布式聊天(IM)系统</a>(不了解这个项目可以查看上一篇或搜索一下文章)，这里我们要实现单台机器支持100W连接的压测</p>\n<p dir=\"auto\">目标:</p>\n<ul dir=\"auto\">\n<li>单台机器能保持100W个长连接</li>\n<li>机器的CPU、内存、网络、I/O 状态都正常</li>\n</ul>\n<p dir=\"auto\">说明:</p>\n<p dir=\"auto\">gowebsocket 分布式聊天(IM)系统:</p>\n<ul dir=\"auto\">\n<li>之前用户连接以后有个全员广播，这里需要将用户连接、退出等事件关闭</li>\n</ul>\n<ul dir=\"auto\">\n<li>服务器准备:</li>\n</ul>\n<blockquote>\n<p dir=\"auto\">由于自己手上没有自己的服务器，所以需要临时购买的云服务器</p>\n</blockquote>\n<p dir=\"auto\">压测服务器:</p>\n<p dir=\"auto\">16台(稍后解释为什么需要16台机器)</p>\n<p dir=\"auto\">CPU: 2核<br>\n内存: 8G<br>\n硬盘: 20G<br>\n系统: CentOS 7.6</p>\n<p dir=\"auto\"><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"img/webSocket%E5%8E%8B%E6%B5%8B%E6%9C%8D%E5%8A%A1%E5%99%A8.png\"><img src=\"img/webSocket%E5%8E%8B%E6%B5%8B%E6%9C%8D%E5%8A%A1%E5%99%A8.png\" alt=\"webSocket压测服务器\" style=\"max-width: 100%;\"></a></p>\n<p dir=\"auto\">被压测服务:</p>\n<p dir=\"auto\">1台</p>\n<p dir=\"auto\">CPU: 4核<br>\n内存: 32G<br>\n硬盘: 20G SSD<br>\n系统: CentOS 7.6</p>\n<p dir=\"auto\"><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"img/webSocket%E8%A2%AB%E5%8E%8B%E6%B5%8B%E6%9C%8D%E5%8A%A1%E5%99%A8.png\"><img src=\"img/webSocket%E8%A2%AB%E5%8E%8B%E6%B5%8B%E6%9C%8D%E5%8A%A1%E5%99%A8.png\" alt=\"webSocket被压测服务器\" style=\"max-width: 100%;\"></a></p>\n<h3 dir=\"auto\">6.2 内核优化</h3>\n<ul dir=\"auto\">\n<li>修改程序最大打开文件数</li>\n</ul>\n<p dir=\"auto\">被压测服务器需要保持100W长连接，客户和服务器端是通过socket通讯的，每个连接需要建立一个socket，程序需要保持100W长连接就需要单个程序能打开100W个文件句柄</p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"# 查看系统默认的值\nulimit -n\n# 设置最大打开文件数\nulimit -n 1040000\"><pre class=\"notranslate\"><code class=\"notranslate\"># 查看系统默认的值\nulimit -n\n# 设置最大打开文件数\nulimit -n 1040000\n</code></pre></div>\n<p dir=\"auto\">这里设置的要超过100W，程序除了有100W连接还有其它资源连接(数据库、资源等连接)，这里设置为 104W</p>\n<p dir=\"auto\">centOS 7.6 上述设置不生效，需要手动修改配置文件</p>\n<p dir=\"auto\"><code class=\"notranslate\">vim /etc/security/limits.conf</code></p>\n<p dir=\"auto\">这里需要把硬限制和软限制、root用户和所有用户都设置为 1040000</p>\n<p dir=\"auto\">core 是限制内核文件的大小，这里设置为 unlimited</p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"# 添加以下参数\nroot soft nofile 1040000\nroot hard nofile 1040000\nroot soft nproc 1040000\nroot hard nproc 1040000\n\n* soft nofile 1040000\n* hard nofile 1040000\n* soft nproc 1040000\n* hard nproc 1040000\n\nroot soft core unlimited\nroot hard core unlimited\n\n* soft core unlimited\n* hard core unlimited\"><pre class=\"notranslate\"><code class=\"notranslate\"># 添加以下参数\nroot soft nofile 1040000\nroot hard nofile 1040000\nroot soft nproc 1040000\nroot hard nproc 1040000\n\n* soft nofile 1040000\n* hard nofile 1040000\n* soft nproc 1040000\n* hard nproc 1040000\n\nroot soft core unlimited\nroot hard core unlimited\n\n* soft core unlimited\n* hard core unlimited\n</code></pre></div>\n<p dir=\"auto\">注意:</p>\n<p dir=\"auto\"><code class=\"notranslate\">/proc/sys/fs/file-max</code> 表示系统级别的能够打开的文件句柄的数量，不能小于limits中设置的值</p>\n<p dir=\"auto\">如果file-max的值小于limits设置的值会导致系统重启以后无法登录</p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"# file-max 设置的值参考\ncat /proc/sys/fs/file-max\n12553500\"><pre class=\"notranslate\"><code class=\"notranslate\"># file-max 设置的值参考\ncat /proc/sys/fs/file-max\n12553500\n</code></pre></div>\n<p dir=\"auto\">修改以后重启服务器，<code class=\"notranslate\">ulimit -n</code> 查看配置是否生效</p>\n<h3 dir=\"auto\">6.3 客户端配置</h3>\n<p dir=\"auto\">由于linux端口的范围是 <code class=\"notranslate\">0~65535(2^16-1)</code>这个和操作系统无关，不管linux是32位的还是64位的</p>\n<p dir=\"auto\">这个数字是由于tcp协议决定的，tcp协议头部表示端口只有16位，所以最大值只有65535(如果每台机器多几个虚拟ip就能突破这个限制)</p>\n<p dir=\"auto\">1024以下是系统保留端口，所以能使用的1024到65535</p>\n<p dir=\"auto\">如果需要100W长连接，每台机器有 65535-1024 个端口， 100W / (65535-1024) ≈ 15.5，所以这里需要16台服务器</p>\n<ul dir=\"auto\">\n<li><code class=\"notranslate\">vim /etc/sysctl.conf</code> 在文件末尾添加</li>\n</ul>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"net.ipv4.ip_local_port_range = 1024 65000\nnet.ipv4.tcp_mem = 786432 2097152 3145728\nnet.ipv4.tcp_rmem = 4096 4096 16777216\nnet.ipv4.tcp_wmem = 4096 4096 16777216\"><pre class=\"notranslate\"><code class=\"notranslate\">net.ipv4.ip_local_port_range = 1024 65000\nnet.ipv4.tcp_mem = 786432 2097152 3145728\nnet.ipv4.tcp_rmem = 4096 4096 16777216\nnet.ipv4.tcp_wmem = 4096 4096 16777216\n</code></pre></div>\n<p dir=\"auto\"><code class=\"notranslate\">sysctl -p</code> 修改配置以后使得配置生效命令</p>\n<p dir=\"auto\">配置解释:</p>\n<ul dir=\"auto\">\n<li><code class=\"notranslate\">ip_local_port_range</code> 表示TCP/UDP协议允许使用的本地端口号 范围:1024~65000</li>\n<li><code class=\"notranslate\">tcp_mem</code> 确定TCP栈应该如何反映内存使用，每个值的单位都是内存页（通常是4KB）。第一个值是内存使用的下限；第二个值是内存压力模式开始对缓冲区使用应用压力的上限；第三个值是内存使用的上限。在这个层次上可以将报文丢弃，从而减少对内存的使用。对于较大的BDP可以增大这些值（注意，其单位是内存页而不是字节）</li>\n<li><code class=\"notranslate\">tcp_rmem</code> 为自动调优定义socket使用的内存。第一个值是为socket接收缓冲区分配的最少字节数；第二个值是默认值（该值会被rmem_default覆盖），缓冲区在系统负载不重的情况下可以增长到这个值；第三个值是接收缓冲区空间的最大字节数（该值会被rmem_max覆盖）。</li>\n<li><code class=\"notranslate\">tcp_wmem</code> 为自动调优定义socket使用的内存。第一个值是为socket发送缓冲区分配的最少字节数；第二个值是默认值（该值会被wmem_default覆盖），缓冲区在系统负载不重的情况下可以增长到这个值；第三个值是发送缓冲区空间的最大字节数（该值会被wmem_max覆盖）。</li>\n</ul>\n<h3 dir=\"auto\">6.4 准备</h3>\n<ol dir=\"auto\">\n<li>\n<p dir=\"auto\">在被压测服务器上启动Server服务(gowebsocket)</p>\n</li>\n<li>\n<p dir=\"auto\">查看被压测服务器的内网端口</p>\n</li>\n<li>\n<p dir=\"auto\">登录上16台压测服务器，这里我提前把需要优化的系统做成了镜像，申请机器的时候就可以直接使用这个镜像(参数已经调好)</p>\n</li>\n</ol>\n<p dir=\"auto\"><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"img/%E5%8E%8B%E6%B5%8B%E6%9C%8D%E5%8A%A1%E5%99%A816%E5%8F%B0%E5%87%86%E5%A4%87.png\"><img src=\"img/%E5%8E%8B%E6%B5%8B%E6%9C%8D%E5%8A%A1%E5%99%A816%E5%8F%B0%E5%87%86%E5%A4%87.png\" alt=\"压测服务器16台准备\" style=\"max-width: 100%;\"></a></p>\n<ol start=\"4\" dir=\"auto\">\n<li>启动压测</li>\n</ol>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\" ./go_stress_testing_linux -c 62500 -n 1  -u ws://192.168.0.74:443/acc\"><pre class=\"notranslate\"><code class=\"notranslate\"> ./go_stress_testing_linux -c 62500 -n 1  -u ws://192.168.0.74:443/acc\n</code></pre></div>\n<p dir=\"auto\"><code class=\"notranslate\">62500*16 = 100W </code>正好可以达到我们的要求</p>\n<p dir=\"auto\">建立连接以后，<code class=\"notranslate\">-n 1</code>发送一个<strong>ping</strong>的消息给服务器，收到响应以后保持连接不中断</p>\n<ol start=\"5\" dir=\"auto\">\n<li>\n<p dir=\"auto\">通过 gowebsocket服务器的http接口，实时查询连接数和项目启动的协程数</p>\n</li>\n<li>\n<p dir=\"auto\">压测过程中查看系统状态</p>\n</li>\n</ol>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"# linux 命令\nps      # 查看进程内存、CPU使用情况\niostat  # 查看系统IO情况\nnload   # 查看网络流量情况\n/proc/pid/status # 查看进程状态\"><pre class=\"notranslate\"><code class=\"notranslate\"># linux 命令\nps      # 查看进程内存、CPU使用情况\niostat  # 查看系统IO情况\nnload   # 查看网络流量情况\n/proc/pid/status # 查看进程状态\n</code></pre></div>\n<h3 dir=\"auto\">6.5 压测数据</h3>\n<ul dir=\"auto\">\n<li>\n<p dir=\"auto\">压测以后，查看连接数到100W，然后保持10分钟观察系统是否正常</p>\n</li>\n<li>\n<p dir=\"auto\">观察以后，系统运行正常、CPU、内存、I/O 都正常，打开页面都正常</p>\n</li>\n<li>\n<p dir=\"auto\">压测完成以后的数据</p>\n</li>\n</ul>\n<p dir=\"auto\">查看goWebSocket连接数统计，可以看到 <strong>clientsLen</strong>连接数为100W，<strong>goroutine</strong>数量2000008个，每个连接两个goroutine加上项目启动默认的8个。这里可以看到连接数满足了100W</p>\n<p dir=\"auto\"><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"img/%E6%9F%A5%E7%9C%8BgoWebSocket%E8%BF%9E%E6%8E%A5%E6%95%B0%E7%BB%9F%E8%AE%A1.png\"><img src=\"img/%E6%9F%A5%E7%9C%8BgoWebSocket%E8%BF%9E%E6%8E%A5%E6%95%B0%E7%BB%9F%E8%AE%A1.png\" alt=\"查看goWebSocket连接数统计\" style=\"max-width: 100%;\"></a></p>\n<p dir=\"auto\">从压测服务上查看连接数是否达到了要求，压测完成的统计数据并发数为62500，是每个客户端连接的数量,总连接数： <code class=\"notranslate\">62500*16=100W</code>，</p>\n<p dir=\"auto\"><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"img/%E5%8E%8B%E6%B5%8B%E6%9C%8D%E5%8A%A116%E5%8F%B0%20%E5%8E%8B%E6%B5%8B%E5%AE%8C%E6%88%90.png\"><img src=\"img/%E5%8E%8B%E6%B5%8B%E6%9C%8D%E5%8A%A116%E5%8F%B0%20%E5%8E%8B%E6%B5%8B%E5%AE%8C%E6%88%90.png\" alt=\"压测服务16台 压测完成\" style=\"max-width: 100%;\"></a></p>\n<ul dir=\"auto\">\n<li>记录内存使用情况，分别记录了1W到100W连接数内存使用情况</li>\n</ul>\n<markdown-accessiblity-table><table role=\"table\">\n<thead>\n<tr>\n<th align=\"center\">连接数</th>\n<th align=\"center\">内存</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"center\">10000</td>\n<td align=\"center\">281M</td>\n</tr>\n<tr>\n<td align=\"center\">100000</td>\n<td align=\"center\">2.7g</td>\n</tr>\n<tr>\n<td align=\"center\">200000</td>\n<td align=\"center\">5.4g</td>\n</tr>\n<tr>\n<td align=\"center\">500000</td>\n<td align=\"center\">13.1g</td>\n</tr>\n<tr>\n<td align=\"center\">1000000</td>\n<td align=\"center\">25.8g</td>\n</tr>\n</tbody>\n</table></markdown-accessiblity-table>\n<p dir=\"auto\">100W连接时的查看内存详细数据:</p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"cat /proc/pid/status\nVmSize: 27133804 kB\"><pre class=\"notranslate\"><code class=\"notranslate\">cat /proc/pid/status\nVmSize: 27133804 kB\n</code></pre></div>\n<p dir=\"auto\"><code class=\"notranslate\">27133804/1000000≈27.1</code> 100W连接，占用了25.8g的内存，粗略计算了一下，一个连接占用了27.1Kb的内存，由于goWebSocket项目每个用户连接起了两个协程处理用户的读写事件，所以内存占用稍微多一点</p>\n<p dir=\"auto\">如果需要如何减少内存使用可以参考 <strong>@Roy11568780</strong> 大佬给的解决方案</p>\n<blockquote>\n<p dir=\"auto\">传统的golang中是采用的一个goroutine循环read的方法对应每一个socket。实际百万链路场景中这是巨大的资源浪费，优化的原理也不是什么新东西，golang中一样也可以使用epoll的，把fd拿到epoll中，检测到事件然后在协程池里面去读就行了，看情况读写分别10-20的协程goroutine池应该就足够了</p>\n</blockquote>\n<p dir=\"auto\">至此，压测已经全部完成，单台机器支持100W连接已经满足~</p>\n<h2 dir=\"auto\">7.常见问题</h2>\n<ul dir=\"auto\">\n<li><strong>Q:</strong> 压测过程中会出现大量 <strong>TIME_WAIT</strong></li>\n</ul>\n<p dir=\"auto\">A: 参考TCP四次挥手原理，主动关闭连接的一方会出现 <strong>TIME_WAIT</strong> 状态，等待的时长为 2MSL(约1分钟左右)</p>\n<p dir=\"auto\">原因是：主动断开的一方回复 ACK 消息可能丢失，TCP 是可靠的传输协议，在没有收到 ACK 消息的另一端会重试，重新发送FIN消息，所以主动关闭的一方会等待 2MSL 时间，防止对方重试，这就出现了大量 <strong>TIME_WAIT</strong> 状态（参考: 四次挥手的最后两次）</p>\n<p dir=\"auto\">TCP 握手：<br>\n<a target=\"_blank\" rel=\"noopener noreferrer\" href=\"img/TCP%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B%E5%9B%9B%E6%AC%A1%E6%8C%A5%E6%89%8B.png\"><img border=\"0\" src=\"img/TCP%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B%E5%9B%9B%E6%AC%A1%E6%8C%A5%E6%89%8B.png\" width=\"830\" style=\"max-width: 100%;\"></a></p>\n<ul dir=\"auto\">\n<li><strong>Q:</strong> 没有go环境无法使用最新功能</li>\n</ul>\n<p dir=\"auto\">A： 可以使用Dockerfile构建一个容器镜像，假设容器镜像名称为gostress:1111，docker build -t gostress:1111 .<br>\n启动一个名称为go-stress的容器docker run -d --name=go-stress gostress:1111<br>\n开始压测 docker exec -it go-stress -c 10 -n 10 -u <a href=\"http://www.baidu.com\" rel=\"nofollow\">www.baidu.com</a></p>\n<h2 dir=\"auto\">8、总结</h2>\n<p dir=\"auto\">到这里压测总算完成，本次压测花费16元巨款。</p>\n<p dir=\"auto\">单台机器支持100W连接是实测是满足的，但是实际业务比较复杂，还是需要持续优化~</p>\n<p dir=\"auto\">本文通过介绍什么是压测，在什么情况下需要压测，通过单台机器100W长连接的压测实战了解Linux内核的参数的调优。如果觉得现有的压测工具不适用，可以自己实现或者是改造成属于自己的自己的工具。</p>\n<h2 dir=\"auto\">9、参考文献</h2>\n<p dir=\"auto\"><a href=\"https://testerhome.com/topics/17068\" rel=\"nofollow\">性能测试工具</a></p>\n<p dir=\"auto\"><a href=\"https://blog.csdn.net/r455678/article/details/53063989\" rel=\"nofollow\">性能测试常见名词解释</a></p>\n<p dir=\"auto\"><a href=\"https://codeigniter.org.cn/forums/blog-39678-2456.html\" rel=\"nofollow\">性能测试名词解释</a></p>\n<p dir=\"auto\"><a href=\"https://www.zhihu.com/question/21556347\" rel=\"nofollow\">PV、TPS、QPS是怎么计算出来的？</a></p>\n<p dir=\"auto\"><a href=\"https://www.jianshu.com/p/43d04d8baaf7\" rel=\"nofollow\">超实用压力测试工具－ab工具</a></p>\n<p dir=\"auto\"><a href=\"http://www.testclass.net/locust/introduce\" rel=\"nofollow\">Locust 介绍</a></p>\n<p dir=\"auto\"><a href=\"https://www.cnblogs.com/TankXiao/p/4045439.html\" rel=\"nofollow\">Jmeter性能测试 入门</a></p>\n<p dir=\"auto\"><a href=\"https://github.com/link1st/gowebsocket\">基于websocket单台机器支持百万连接分布式聊天(IM)系统</a></p>\n<p dir=\"auto\"><a href=\"https://github.com/link1st/go-stress-testing\">https://github.com/link1st/go-stress-testing</a></p>\n<p dir=\"auto\">github 搜:link1st 查看项目 go-stress-testing</p>\n<h3 dir=\"auto\">意见反馈</h3>\n<ul dir=\"auto\">\n<li>在项目中遇到问题可以直接在这里找找答案或者提问 <a href=\"https://github.com/link1st/go-stress-testing/issues\">issues</a></li>\n<li>也可以添加我的微信(申请信息填写:公司、姓名，我好备注下)，直接反馈给我<br>\n<br></li>\n</ul>\n<p align=\"center\" dir=\"auto\">\n     <a target=\"_blank\" rel=\"noopener noreferrer\" href=\"img/微信二维码.jpeg\"><img border=\"0\" src=\"img/微信二维码.jpeg\" alt=\"添加link1st的微信\" width=\"200\" style=\"max-width: 100%;\"></a>\n</p>\n<h3 dir=\"auto\">赞助商</h3>\n<ul dir=\"auto\">\n<li>感谢<a href=\"https://www.jetbrains.com/?from=gowebsocket\" rel=\"nofollow\">JetBrains</a>对本项目的支持！<br>\n<br></li>\n</ul>\n<p align=\"center\" dir=\"auto\">\n    <a href=\"https://www.jetbrains.com/?from=gowebsocket\" rel=\"nofollow\">\n        <img border=\"0\" src=\"img/jetbrains_logo.png\" width=\"200\" style=\"max-width: 100%;\">\n    </a>\n</p>","updatedAt":"2025-05-21T16:00:24Z","upvoteCount":null,"author":{"login":"eryajf","avatarUrl":"https://avatars.githubusercontent.com/u/33259379?u=e4a4090a38ac2473aaed4ef9945233636776c6c3&v=4","url":"https://github.com/eryajf"},"category":null,"labels":{"edges":[{"node":{"name":"更多","color":"25B472"}},{"node":{"name":"测试压测","color":"3fbd86"}},{"node":{"name":"link1st","color":"4c2299"}}]},"comments":{"edges":[]}}},"pageContext":{"number":206,"previous":{"title":"TNK-Studio/gortal: 一个使用 Go 语言开发的，超级轻量的跳板机服务。","number":205},"next":{"title":"go-gost/gost: GO语言实现的安全隧道","number":207}}},
    "staticQueryHashes": ["151096407","2861350382"]}