测试一下golang协程资源占有率

来源:转载

GO版本:go version go1.4.2 linux/amd64

测试环境:

[[email protected] mpro]# more /proc/cpuinfo | grep "model name"model name : Intel(R) Core(TM) i5-4590 CPU @ 3.30GHzmodel name : Intel(R) Core(TM) i5-4590 CPU @ 3.30GHzmodel name : Intel(R) Core(TM) i5-4590 CPU @ 3.30GHzmodel name : Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz[[email protected] mpro]# [[email protected] mpro]# grep MemTotal /proc/meminfoMemTotal: 3868776 kB[[email protected] mpro]# getconf LONG_BIT64[[email protected] mpro]# more /etc/redhat-releaseCentOS Linux release 7.1.1503 (Core)

测试用例:

package mainimport ("time")func main() {for i := 0; i < 200000; i++ {go func() {time.Sleep(5 * time.Second)}()}time.Sleep(10 * time.Second)}

执行程序前:

top - 18:53:19 up 19 min, 3 users, load average: 0.00, 0.04, 0.11Tasks: 522 total, 1 running, 521 sleeping, 0 stopped, 0 zombie%Cpu(s): 0.1 us, 0.2 sy, 0.0 ni, 99.6 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 stKiB Mem : 3868776 total, 3327732 free, 235764 used, 305280 buff/cacheKiB Swap: 2097148 total, 2097148 free, 0 used. 3397344 avail Mem

执行程序后:

top - 18:53:37 up 19 min, 3 users, load average: 0.00, 0.04, 0.11Tasks: 524 total, 1 running, 523 sleeping, 0 stopped, 0 zombie%Cpu(s): 1.2 us, 10.6 sy, 0.0 ni, 88.2 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 stKiB Mem : 3868776 total, 2793732 free, 752512 used, 322532 buff/cacheKiB Swap: 2097148 total, 2097148 free, 0 used. 2880016 avail Mem

总结:20万个协程占用了500M内存 50万KB

平均一个协程占用2.5KB



分享给朋友:
您可能感兴趣的文章:
随机阅读: