{"id":184648,"date":"2023-08-31T06:15:44","date_gmt":"2023-08-30T22:15:44","guid":{"rendered":"http:\/\/www.idc.net\/help\/184648\/"},"modified":"2023-08-31T06:15:44","modified_gmt":"2023-08-30T22:15:44","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91go%e6%95%99%e7%a8%8bgo%e8%af%ad%e8%a8%80gomaxprocs%ef%bc%88%e8%b0%83%e6%95%b4%e5%b9%b6%e5%8f%91%e7%9a%84%e8%bf%90%e8%a1%8c%e6%80%a7%e8%83%bd%ef%bc%89","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/184648\/","title":{"rendered":"\u540e\u6d6a\u4e91GO\u6559\u7a0b:Go\u8bed\u8a00GOMAXPROCS\uff08\u8c03\u6574\u5e76\u53d1\u7684\u8fd0\u884c\u6027\u80fd\uff09"},"content":{"rendered":"<p>\u5728 Go\u8bed\u8a00\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff08runtime\uff09\u5b9e\u73b0\u4e86\u4e00\u4e2a\u5c0f\u578b\u7684\u4efb\u52a1\u8c03\u5ea6\u5668\u3002\u8fd9\u5957\u8c03\u5ea6\u5668\u7684\u5de5\u4f5c\u539f\u7406\u7c7b\u4f3c\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u8c03\u5ea6\u7ebf\u7a0b\uff0cGo \u7a0b\u5e8f\u8c03\u5ea6\u5668\u53ef\u4ee5\u9ad8\u6548\u5730\u5c06 CPU \u8d44\u6e90\u5206\u914d\u7ed9\u6bcf\u4e00\u4e2a\u4efb\u52a1\u3002\u4f20\u7edf\u903b\u8f91\u4e2d\uff0c\u5f00\u53d1\u8005\u9700\u8981\u7ef4\u62a4\u7ebf\u7a0b\u6c60\u4e2d\u7ebf\u7a0b\u4e0e CPU \u6838\u5fc3\u6570\u91cf\u7684\u5bf9\u5e94\u5173\u7cfb\u3002\u540c\u6837\u7684\uff0cGo \u5730\u4e2d\u4e5f\u53ef\u4ee5\u901a\u8fc7 runtime.GOMAXPROCS() \u51fd\u6570\u505a\u5230\uff0c\u683c\u5f0f\u4e3a\uff1a <\/p>\n<p> runtime.GOMAXPROCS(\u903b\u8f91CPU\u6570\u91cf)<\/p>\n<p> \u8fd9\u91cc\u7684\u903b\u8f91CPU\u6570\u91cf\u53ef\u4ee5\u6709\u5982\u4e0b\u51e0\u79cd\u6570\u503c\uff1a <\/p>\n<ul>\n<li> &lt;1\uff1a\u4e0d\u4fee\u6539\u4efb\u4f55\u6570\u503c\u3002<\/li>\n<li> =1\uff1a\u5355\u6838\u5fc3\u6267\u884c\u3002<\/li>\n<li> &gt;1\uff1a\u591a\u6838\u5e76\u53d1\u6267\u884c\u3002<\/li>\n<\/ul>\n<p> \u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528 runtime.NumCPU() \u67e5\u8be2 CPU \u6570\u91cf\uff0c\u5e76\u4f7f\u7528 runtime.GOMAXPROCS() \u51fd\u6570\u8fdb\u884c\u8bbe\u7f6e\uff0c\u4f8b\u5982\uff1a <\/p>\n<pre>\r\nruntime.GOMAXPROCS(runtime.NumCPU())<\/pre>\n<p> Go 1.5 \u7248\u672c\u4e4b\u524d\uff0c\u9ed8\u8ba4\u4f7f\u7528\u7684\u662f\u5355\u6838\u5fc3\u6267\u884c\u3002\u4ece Go 1.5 \u7248\u672c\u5f00\u59cb\uff0c\u9ed8\u8ba4\u6267\u884c\u4e0a\u9762\u8bed\u53e5\u4ee5\u4fbf\u8ba9\u4ee3\u7801\u5e76\u53d1\u6267\u884c\uff0c\u6700\u5927\u6548\u7387\u5730\u5229\u7528 CPU\u3002 <\/p>\n<p> GOMAXPROCS \u540c\u65f6\u4e5f\u662f\u4e00\u4e2a\u73af\u5883\u53d8\u91cf\uff0c\u5728\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u524d\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u4e5f\u53ef\u4ee5\u8d77\u5230\u76f8\u540c\u7684\u4f5c\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Go\u8bed\u8a00\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff08runtime\uff09\u5b9e\u73b0\u4e86\u4e00\u4e2a\u5c0f\u578b\u7684\u4efb\u52a1\u8c03\u5ea6\u5668\u3002\u8fd9\u5957\u8c03\u5ea6\u5668\u7684\u5de5\u4f5c\u539f\u7406\u7c7b\u4f3c\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u8c03\u5ea6\u7ebf\u7a0b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182396],"tags":[],"class_list":["post-184648","post","type-post","status-publish","format-standard","hentry","category-go"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/184648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=184648"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/184648\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=184648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=184648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=184648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}