{"id":220733,"date":"2020-11-20T11:40:34","date_gmt":"2020-11-20T03:40:34","guid":{"rendered":"http:\/\/4563.org\/?p=220733"},"modified":"2020-11-20T11:40:34","modified_gmt":"2020-11-20T03:40:34","slug":"go-%e8%af%ad%e8%a8%80%e7%9a%84-mpg-%e6%a8%a1%e5%9e%8b%e6%98%af%e4%b8%8d%e6%98%af%e6%84%8f%e5%91%b3%e7%9d%80%e6%97%a0%e8%ae%ba%e6%88%91%e5%bc%80%e5%a4%9a%e5%b0%91%e4%b8%aa-goroutine%ef%bc%8c%e6%9c%80","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=220733","title":{"rendered":"Go \u8bed\u8a00\u7684 MPG \u6a21\u578b\u662f\u4e0d\u662f\u610f\u5473\u7740\u65e0\u8bba\u6211\u5f00\u591a\u5c11\u4e2a Goroutine\uff0c\u6700\u540e\u90fd\u662f\u7531\u6838\u5fc3\u6570\u4e2a\u5185\u6838\u8fdb\u7a0b\u53bb\u6267\u884c\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Go \u8bed\u8a00\u7684 MPG \u6a21\u578b\u662f\u4e0d\u662f\u610f\u5473\u7740\u65e0\u8bba\u6211\u5f00\u591a\u5c11\u4e2a Goroutine\uff0c\u6700\u540e\u90fd\u662f\u7531\u6838\u5fc3\u6570\u4e2a\u5185\u6838\u8fdb\u7a0b\u53bb\u6267\u884c\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : b00tyhunt3r <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4ece\u800c\u4e0d\u9700\u8981\u50cf C\/C++\u90a3\u6837\u624b\u52a8\u53d6\u5f97 CPU \u6570 X\uff0c \u518d\u5f00 X \u4e2a\u7ebf\u7a0b\u53bb\u6267\u884c\u4efb\u52a1\uff1f<\/p>\n<p>\u6362\u53e5\u8bdd\u8bf4\uff0c\u8fd9\u6837\u7684\u4ee3\u7801\u5728 Go \u4e2d\u662f\u4e0d\u662f\u5b8c\u5168\u65e0\u610f\u4e49\uff1f<\/p>\n<pre><code>CORE_NUM := runtime.NumCPU()   \/\/\u53d6\u5f97 CPU \u6570  for i := 0; i &lt; CORE_NUM-1; i++ {   \/\/\u5f00 CPU-1 \u4e2a Goroutine  go func() {      dojob()     } }      dojob() \/\/main \u81ea\u5df1\u7684 Goroutine <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>20<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4446901\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zmqiang <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Goroutine \u4f1a\u88ab\u5206\u914d\u5230\u82e5\u5e72\u7684\u7ebf\u7a0b\u91cc\u8fd0\u884c\uff0c\u7ebf\u7a0b\u7684\u6570\u91cf\u548c\u8fd0\u884c\u7684\u6838\u5fc3\u90fd\u662f\u4e0d\u80fd\u63a7\u5236\u7684\u3002\u4e0a\u9762\u7684\u4ee3\u7801\u786e\u5b9e\u662f\u6ca1\u6709\u610f\u4e49\u7684\uff0cGoroutine \u662f\u5f88\u8f7b\u91cf\u7ea7\u7684\uff0c\u8fd0\u884c\u6210\u5343\u4e0a\u4e07\u4e2a\u90fd\u662f\u53ef\u4ee5\u7684\uff0c\u6ca1\u6709\u5fc5\u8981\u548c\u5185\u6838\u6570\u91cf\u5173\u8054\u8d77\u6765\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446902\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : b00tyhunt3r <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zmqiang <br \/>\u4f46\u662f\u6bd4\u5982\u6211\u9700\u8981\u505a 10 \u4e07\u6761\u8ba1\u7b97\uff0c \u6211\u4e0d\u53ef\u80fd\u5f00 10 \u4e07\u4e2a Goroutine \u5427<br \/>\u8fd9\u65f6\u5019\u600e\u4e48\u51b3\u5b9a\u6211\u9700\u8981\u5f00\u591a\u5c11\u4e2a Goroutine \u5462\uff08 and, \u6bcf\u4e2a Goroutine \u5206\u62c5\u591a\u5c11\u6761\u8ba1\u7b97\uff09                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446903\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lithium4010 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @b00tyhunt3r \u597d\u50cf\u53ef\u4ee5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446904\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : bruce0 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @b00tyhunt3r \u6211\u7406\u89e3\u7684,\u4e00\u4e2a goroutine \u9ed8\u8ba4\u5360\u7528 4K, \u90a3 10 \u4e07\u4e2a\u5360\u7528\u5185\u5b58\u4e0d\u5230\u534a\u4e2a G,\u5e94\u8be5\u662f\u6ca1\u5565\u95ee\u9898\u7684\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446905\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : b00tyhunt3r <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lithium4010 <br \/>@bruce0 <br \/>\u5373\u4f7f 10 \u4e07\u53ef\u4ee5 \u90a3 100 \u4e07\uff0c1000 \u4e07, 1 billion \u5462\uff1f<br \/>\u5e0c\u671b\u4ece\u539f\u7406\u4e0a\u66f4\u597d\u7684\u7406\u89e3\u8fd9\u4e2a\u95ee\u9898                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446906\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : axex <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             cpu \u5bc6\u96c6\u578b\uff1f\u4e0a worker pool\uff0c\u8d77\u51e0\u767e\u4e0a\u5343\u90fd\u884c<br \/>io \u5bc6\u96c6\u578b\uff1f\u53c2\u8003 net\/http \u548c grpc-go\uff0c\u4e00\u4e2a connection \u4e00\u4e2a\u6216\u8005\u4e24\u4e2a goroutine                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446907\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sujin190 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @b00tyhunt3r #2 go \u8bbe\u8ba1 Goroutine \u5c31\u662f\u4e3a\u4e86\u53ef\u4ee5\u5f00\u8d85\u591a\u91cf\u800c\u8bbe\u8ba1\u7684\uff0c\u522b\u8bf4 10 \u4e07\u4e2a\uff0c\u767e\u4e07\u4e2a\u5343\u4e07\u4e2a\u9875\u6ca1\u5565\u95ee\u9898\uff0c\u5355\u4e2a\u7684\u5185\u5b58\u6d88\u8017\u5f88\u4f4e\uff0c\u4f46\u662f\u5427\u6bcf\u4e2a cpu \u6838\u5fc3\u540c\u65f6\u523b\u53ea\u80fd\u6267\u884c\u4e00\u4e2a\u8ba1\u7b97\uff0c\u800c\u4e14 Goroutine \u53ef\u80fd\u4e0d\u662f\u62a2\u65ad\u5f0f\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446908\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sujin190 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @b00tyhunt3r #5 \u7ebf\u7a0b\u4e0d\u80fd\u5f00\u8d85\u591a\u7684\u95ee\u9898\u5728\u4e8e\u6bcf\u4e2a\u65b0\u7ebf\u7a0b\u81f3\u5c11\u9700\u8981 1M \u7684\u6808\uff0c\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u7684\u5185\u5b58\u6d88\u8017\uff0c\u53d7\u9650\u5185\u5b58\u9650\u5236\u6240\u4ee5\u4e0d\u80fd\u5f00\u5f88\u591a\uff0c\u800c\u4e14\u7ebf\u7a0b\u662f\u7cfb\u7edf\u5207\u6362\u8c03\u5ea6\u7684\uff0c\u8d85\u8fc7\u6267\u884c\u65f6\u95f4\u5c31\u8981\u5207\u6362\u8c03\u5ea6\uff0c\u9891\u7e41\u5524\u9192\u5207\u6362\u53ef\u80fd\u9700\u8981\u6d88\u8017\u975e\u5e38\u591a\u7684 cpu \u65f6\u95f4\uff0cgo \u7684 Goroutine \u5355\u4e2a\u5185\u5b58\u6d88\u8017\u548c\u5207\u6362\u8c03\u5ea6\u6d88\u8017\u90fd\u4f4e\u975e\u5e38\u591a\uff0c\u6240\u4ee5\u53ef\u4ee5\u5f00\u975e\u5e38\u975e\u5e38\u591a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446909\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zmqiang <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @b00tyhunt3r <\/p>\n<p>\u5728\u4f7f\u7528\u7ebf\u7a0b\u5b9e\u73b0\u5e76\u53d1\u7684\u8bed\u8a00\u91cc\uff0c\u50cf\u4f60\u95ee\u9898\u91cc\u63d0\u5230\u6309\u7167\u5185\u6838\u8bbe\u7f6e\u7ebf\u7a0b\u6570\uff0c\u76ee\u7684\u662f\u671f\u671b\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u8dd1\u5728\u4e00\u4e2a\u72ec\u7acb\u5185\u6838\u4e0a\uff0c\u51cf\u5c11\u4e0d\u505c\u8fdb\u884c\u4e0a\u4e0b\u6587\u5207\u6362\u5bfc\u81f4\u7684\u989d\u5916\u5f00\u9500\u3002\u800c goroutine \u662f go \u7684 runtime \u81ea\u5df1\u8c03\u5ea6\u7684\uff0c\u5e76\u4e14\u6bd4\u7ebf\u7a0b\u8f7b\u91cf\u7ea7\uff0c\u5e26\u6765\u4e24\u4e2a\u597d\u5904\uff1a\u8c03\u5ea6\u5f00\u9500\u5c0f\u548c\u9ed8\u8ba4\u5185\u5b58\u5c0f\u3002\u6240\u4ee5 goroutine \u4e0d\u518d\u6709\u4e4b\u524d\u7ebf\u7a0b\u51fa\u4e8e\u6027\u80fd\u8003\u8651\u800c\u5e26\u6765\u7684\u6570\u91cf\u9650\u5236\uff0c\u6240\u4ee5\u7406\u8bba\u4e0a\u53ea\u8981\u5185\u5b58\u548c cpu \u591f\u5f3a\uff0c\u5f00\u591a\u5c11\u90fd\u884c\u3002<\/p>\n<p>\u603b\u7684\u6765\u8bf4\uff0c\u542f\u52a8\u7ebf\u7a0b\u8003\u8651\u6570\u91cf\u548c\u5185\u6838\u7684\u5173\u7cfb\uff0c\u662f\u56e0\u4e3a\u53ef\u80fd\u5b58\u5728\u7684\u6027\u80fd\u95ee\u9898\u5e26\u6765\u7684\u9650\u5236\u3002\u800c goroutine \u53bb\u6389\u4e86\u8fd9\u4e2a\u9650\u5236\u3002\u4f60\u7684\u95ee\u9898\u50cf\u662f\u4e00\u4e2a\u4e4b\u524d\u88ab\u7ea6\u675f\u7684\u4eba\uff0c\u6709\u4e86\u81ea\u7531\u540e\u7a81\u7136\u4e4b\u95f4\u65e0\u6240\u9002\u4ece\u4e86\u3002<\/p>\n<p>\u5982\u679c\u4f60\u5f00\u59cb\u7528 go \u4e86\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4e60\u60ef\u4ece\u4e1a\u52a1\u548c\u7cfb\u7edf\u7684\u603b\u4f53\u8ba1\u7b97\u529b\u91cc\u6765\u8003\u8651\u5e76\u53d1\u6570\u91cf\uff0c\u4e0d\u7528\u518d\u628a\u6570\u91cf\u5e26\u6765\u7684\u4e0a\u4e0b\u6587\u4ea4\u6362\u5e26\u6765\u7684\u6d88\u8017\u548c\u5185\u5b58\u5360\u7528\u653e\u5728\u8003\u8651\u8303\u56f4\u5185\u4e86\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446910\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wangritian <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             go \u7684\u4f18\u79c0\u4e4b\u5904\u5c31\u662f\u968f\u610f\u5f00 goroutine \u4e86\uff0c\u800c\u4e14\u81ea\u5e26\u7ebf\u7a0b\u8c03\u5ea6\uff0c\u5199\u5e76\u53d1\u7a0b\u5e8f\u7684\u5fc3\u667a\u8d1f\u62c5\u964d\u5230\u6700\u4f4e<br \/>goroutine \u8fd0\u884c\u5b8c\u6210\u4f1a\u56de\u6536\u7684\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u9879\u76ee\u8981\u5f00\u5230\u4e0a\u4ebf\u4e14\u4e0d\u91ca\u653e\uff0c\u4ed6\u5e94\u8be5\u8003\u8651\u5206\u5e03\u5f0f\u8ba1\u7b97                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446911\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : b00tyhunt3r <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @axex <br \/>\u4e00\u4e2a CPU connection \u4e00\u4e2a\u6216\u8005\u4e24\u4e2a goroutine? \u4e3a\u4ec0\u4e48\uff1f<\/p>\n<p>@sujin190 <br \/>\u770b\u4e0b\u8fd9\u4e2a\u7b80\u5355\u7684 worker pool<br \/>&#8221;&#8217;<br \/>package main<\/p>\n<p>import (<br \/> &#8220;fmt&#8221;<br \/> &#8220;time&#8221;<br \/>)<br \/>\/\/\u7761 1 \u79d2\uff0c\u7136\u540e\u628a\u6536\u5230\u7684\u6570\u636e\u4e58 2 \u8fd4\u56de<br \/>func worker(id int, job &lt;-chan int, ret chan&lt;- int) {<br \/> for j := range job {<br \/> time.Sleep(time.Second)<br \/> ret &lt;- j * 2 <br \/> } <br \/>}<\/p>\n<p>func main() {<br \/>\/\/1000 \u4e2a\u5de5\u4f5c<br \/> const JOBNUM = 1000 <br \/> jobchan := make(chan int, JOBNUM)<br \/> retchan := make(chan int, JOBNUM)<\/p>\n<p>\/\/\u5f00 1000 \u4e2a goroutine<br \/> for w := 1; w &lt;= 1000; w++ {<br \/> go worker(w, jobchan, retchan)<br \/> } <\/p>\n<p>\/\/\u5206\u53d1 1000 \u4e2a\u5de5\u4f5c<br \/> for j := 1; j &lt;= JOBNUM; j++ {<br \/> jobchan &lt;- j<br \/> } <br \/> close(jobchan)<\/p>\n<p>\/\/\u63a5\u53d7\u7ed3\u679c<br \/>for r := 1; r &lt;= JOBNUM; r++ {<br \/> &lt;-retchan<br \/> }<br \/>}<br \/>&#8221;&#8217;<br \/>\u5982\u679c\u8bf4&#8221;\u6bcf\u4e2a cpu \u6838\u5fc3\u540c\u65f6\u523b\u53ea\u80fd\u6267\u884c\u4e00\u4e2a\u8ba1\u7b97&#8221;<br \/>\u6211\u7684\u7535\u8111\u6709 12 \u6838\u5fc3\u3002\u90a3\u4e48\u6309\u7406\u8bf4\u6211\u540c\u65f6\u53ea\u80fd\u5904\u7406 12 \u4e2a goroutine\uff0c\u5373 12 \u4e2a worker \u4e0d\u662f\u5417<br \/>\u53ef\u5b9e\u9645\u4e0a\u8fd9 1000 \u4e2a goroutine \u5904\u7406 1000 \u4e2a\u5de5\u4f5c\uff08\u7761 1 \u79d2\uff09\uff0c<br \/>\u603b\u5171\u53ea\u7528\u4e86 1 \u79d2\uff0c \u8bf4\u660e\u8fd9 1000 \u4e2a goroutine \u662f\u540c\u65f6\u5e76\u884c\u6267\u884c\u7684<br \/>\u800c\u4e0d\u662f\u6bcf\u6b21\u5e76\u884c\u5904\u7406 12 \u4e2a\uff0c\u4e00\u5171\u8981\u7761\uff08 1000\/12 \uff09= 83 \u79d2<\/p>\n<p>\u80af\u5b9a\u662f\u6211\u54ea\u91cc\u7406\u89e3\u4e0d\u5bf9 \u671b\u6307\u70b9                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446912\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : codehz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             sleep \u4e0d\u9700\u8981\u5b9e\u9645\u4e0a\u963b\u585e\u7b49\u5f85\u90a3\u4e00\u6bb5\u65f6\u95f4\uff0c\u53ef\u4ee5\u8ba9\u8c03\u5ea6\u5668\u5728\u7ed9\u5b9a\u65f6\u95f4\u540e\u8c03\u5ea6\u5c31\u597d\u4e86<br \/>\u7136\u540e\u8c03\u5ea6\u5668\u53d1\u73b0\u6240\u6709 goroutine \u90fd\u5728 sleep \u7684\u65f6\u5019\u624d\u4f1a sleep                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446913\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xgfan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @b00tyhunt3r <br \/>\u6bcf\u6b21\u5e76\u884c\u5904\u7406 12 \u4e2a!=\u6bcf\u79d2\u5e76\u884c 12 \u4e2a\u3002<br \/>sleep \u7684\u65f6\u5019\uff0cGo \u662f\u4f1a\u8ba9\u51fa\u8d44\u6e90\u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446914\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sujin190 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @b00tyhunt3r #11 \u8fd9\u4e2a sleep \u548c\u666e\u901a c \u7528\u7684 sleep \u4e0d\u662f\u540c\u4e00\u4e2a\uff0c\u8fd9\u4e2a sleep \u662f\u5b9e\u73b0\u5728 go \u7684 goroutine \u8c03\u5ea6\u5668\u91cc\u7684\uff0c\u4e0d\u662f\u963b\u585e\u7684\uff0c\u8c03\u7528 sleep \u7684\u65f6\u5019\u4f1a\u8fdb\u884c goroutine \u8c03\u5ea6\uff0c\u5207\u6362\u5230\u5176\u4ed6 goroutine \u8fd0\u884c\uff0c\u65f6\u95f4\u5230\u4e86\u518d\u8fdb\u5165\u8c03\u5ea6\u518d\u8fd0\u884c\uff0c\u7ebf\u7a0b\u8c03\u7528 sleep \u4e0d\u4e5f\u4e0d\u4f1a\u963b\u585e cpu \u8fd0\u884c\u554a\uff0c\u8fd9\u548c\u7ebf\u7a0b\u662f\u4e00\u6837\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446915\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : unixeno <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @b00tyhunt3r \u4f60\u7535\u8111\u53c8\u4e0d\u662f\u5355\u7ebf\u7a0b\u7684\uff0c\u4e00\u4e2a\u548c\u6838\u5fc3\u4e5f\u53ef\u4ee5\u8c03\u5ea6\u8fd0\u884c\u591a\u4e2a\u7ebf\u7a0b\u5440<br \/>\u4f60\u6d4b\u8bd5\u7684\u4ee3\u7801\u8bf4\u660e\u4e0d\u4e86\u5565\uff0c\u4f60\u5f00 1000 \u4e2a\u7ebf\u7a0b\u4e5f\u662f\u4e00\u6837\u7684\u6548\u679c<br \/>\u4f60\u8fd9\u91cc\u7528\u7684 sleep\uff0ccpu \u5e76\u4e0d\u9700\u8981\u50bb\u7b49\uff0c\u76f4\u63a5\u8c03\u5ea6\u6267\u884c\u522b\u7684\u7ebf\u7a0b\u5c31\u884c<br \/>goroutine \u7684\u5b9e\u9645\u8fd0\u884c\u9700\u8981\u4f9d\u9644\u4e8e\u4e00\u4e2a\u5177\u4f53\u7684\u7ebf\u7a0b\uff0c\u4e5f\u5c31\u662f gmp \u91cc\u9762\u7684 M<br \/>\u51b3\u5b9a\u540c\u65f6\u6709\u591a\u5c11\u4e2a goroutine \u53ef\u4ee5\u6267\u884c\u662f P \u7684\u6570\u91cf\u51b3\u5b9a\u7684<br \/>\u4f60\u53ef\u4ee5\u770b\u6210 go \u7ed9\u4f60\u62bd\u8c61\u51fa\u6765\u4e86\u4e00\u4e2a\u6709 P \u4e2a\u6838\u5fc3\u7684\u673a\u5668\uff0cP \u5728\u8c03\u5ea6\u8fd0\u884c goroutine \u7684\u65f6\u5019\uff0c\u4f1a\u628a goroutine \u9644\u52a0\u5230\u4e00\u4e2a\u5b9e\u9645\u7684 M \u4e0a<br \/>\u5982\u679c goroutine \u53d1\u751f\u7cfb\u7edf\u8c03\u7528\u9677\u5165\u5185\u6838\u6001\u4e86\uff0c\u8fd9\u4e2a\u65f6\u5019 M \u5c31\u91ca\u653e\u4e0d\u4e86\uff0cP \u4e5f\u4f1a\u81ea\u5df1\u521b\u5efa\u4e00\u4e2a\u65b0\u7ebf\u7a0b\u6765\u8c03\u5ea6\u522b\u7684 G \u6765\u6267\u884c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446916\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : rrfeng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5b9e\u9645\u4e0a\u8fd8\u662f\u6709\u7528\u7684\u54e6\uff0c\u5982\u679c goroutine \u91cc\u6709\u963b\u585e\u64cd\u4f5c\uff0c\u90a3\u4e48 M \u88ab\u5360\u7528\u5b8c\u4e86\uff0c\u6ca1\u5f97\u8c03\u5ea6\u4e4b\u540e\u4f1a\u65b0\u5f00 M\uff0c\u4e5f\u5c31\u662f\u65b0\u7684 OS \u7ebf\u7a0b\u3002<\/p>\n<p>\u4f1a\u5bfc\u81f4\u5927\u91cf\u7ebf\u7a0b\u51fa\u73b0\uff0c\u5f71\u54cd\u6548\u7387\u3002\u6240\u4ee5\u6709\u4e9b\u60c5\u51b5\u4f60\u5f97\u9650\u5236\u4f60\u7684 goroutine \u6570\u91cf\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446917\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : guonaihong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5927\u90e8\u5206\u60c5\u51b5\u662f\u8fd9\u6837\uff0c\u7279\u4f8b\u6709 cgo\uff0c\u5982\u679c\u5728 go \u91cc\u9762\u8c03\u7528\u4e86 c \u7684\u4ee3\u7801\uff0c\u4f7f\u7528 ps -eLf \u89c2\u5bdf\u4f1a\u53d1\u73b0\u5f88\u591a\u5185\u6838\u7ebf\u7a0b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446918\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : joesonw <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u662f\u957f\u65f6\u95f4\u7eaf\u6570\u636e\u5904\u7406\u7684\u7a0b\u5e8f, \u53ef\u4ee5\u5f00 CPU \u4e2a routine. \u8fd9\u6837\u6bcf\u4e2a\u6838\u62a2\u5230\u4e00\u4e2a routine. \u7136\u540e\u7528 channel \u6765\u585e\u6570\u636e. \u51cf\u5c11\u4e86 routine \u5207\u6362\u7684\u6027\u80fd\u5f71\u54cd.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446919\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : icexin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             goroutine \u8fdb\u884c\u963b\u585e\u8c03\u7528\u6bd4\u5982 sleep \u6216\u8005 socket \u8bfb\u53d6\u5e76\u4e0d\u56de\u963b\u585e\u5bf9\u5e94\u7684 cpu \u6838\u5fc3\uff0cgo \u7684 runtime \u4f1a\u628a\u963b\u585e\u7684 goroutine \u5207\u6362\u8d70\u7f6e\u4e8e\u4f11\u7720\u6001\uff0c\u4e00\u65e6\u89e3\u9664\u963b\u585e\u7684\u6761\u4ef6\u8fbe\u6210\uff0c\u5982 sleep \u65f6\u95f4\u5230\u6216\u8005 socket \u6709\u53ef\u8bfb\u6570\u636e\uff0c\u5219\u4f1a\u5524\u9192\u76f8\u5e94\u7684 goroutine\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u8ddf\u64cd\u4f5c\u7cfb\u7edf\u8c03\u5ea6\u8fdb\u7a0b\u5f88\u50cf\uff0c\u6240\u4ee5\u53ef\u4ee5\u8ba4\u4e3a goroutine \u5c31\u662f\u4e00\u4e2a\u7528\u6237\u6001\u7ebf\u7a0b\u5b9e\u73b0\u3002\u56de\u5230\u4f60\u7684\u95ee\u9898\uff0c\u7b54\u6848\u662f\uff1acpu \u6709\u591a\u5c11\u4e2a\u6838\u5fc3\u8ddf\u542f\u52a8\u591a\u5c11\u4e2a goroutine \u6ca1\u5173\u7cfb\uff0c\u56e0\u4e3a go \u7684 runtime \u4f1a\u81ea\u52a8\u5207\u6362\u8d70\u5904\u4e8e\u963b\u585e\u7684 goroutine\uff0c\u4ece\u800c\u6765\u5145\u5206\u5229\u7528 cpu \u8d44\u6e90\u3002\u4f46\u662f\u6709\u4e00\u4e2a\u539f\u5219\u662f\u901a\u7528\u7684\uff0ccpu \u5bc6\u96c6\u578b\u7684\u4efb\u52a1\u5c3d\u91cf\u542f\u7528\u8ddf cpu \u6838\u6570\u5dee\u4e0d\u591a\u7684 worker\uff0c\u56e0\u4e3a\u5728 cpu \u5bc6\u96c6\u578b\u4efb\u52a1\u91cc\u9762 cpu \u4e00\u76f4\u5904\u4e8e\u9971\u548c\u8ba1\u7b97\u72b6\u6001\uff0c\u65e0\u8c13\u7684\u4e0a\u4e0b\u6587\u5207\u6362\u53cd\u800c\u5f71\u54cd\u6548\u7387\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4446920\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : songjiaxin2008 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5b9e\u9645\u662f\u6709\u7528\u7684 https:\/\/github.com\/uber-go\/automaxprocs \u8fd9\u4e2a\u5305\u4e13\u95e8\u4e3a\u5bb9\u5668\u5185\u7684\u5e94\u7528\u8bbe\u8ba1 \u5c31\u662f\u4e3a\u4e86\u9632\u6b62 runtime \u83b7\u53d6\u5230\u9519\u8bef\u7684\u6838\u5fc3\u6570\uff0c\u5f00\u592a\u591a\u7684 P                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Go \u8bed\u8a00\u7684 MPG \u6a21\u578b\u662f\u4e0d\u662f\u610f&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/220733"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=220733"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/220733\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=220733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=220733"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=220733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}