package main

import (
        "fmt"
        "time"

       )

func foo() {
        str := ""
         for i := 0; i < 1000; i++ {
             str += "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
         }
}
func main() {

    for i := 0; i < 200; i++ {
        go func() {
            for {
                foo()
                    time.Sleep(10 * time.Millisecond)
            }
        }()
    }

    for {
        fmt.Printf("ticker>>>\n")
            time.Sleep(3 * time.Second)
    }
}



above is my worse example code
1. GOMAXPROCS=1 GODEBUG=gctrace=1 go run worse.go
...
gc 1276 @1.700s 58%: 0.001+0.75+0.005 ms clock, 0.001+0/0.75/0+0.005 ms 
cpu, 7->7->3 MB, 8 MB goal, 1 P
gc 1277 @1.702s 58%: 0.001+0.92+0.005 ms clock, 0.001+0/0.91/0+0.005 ms 
cpu, 7->7->3 MB, 8 MB goal, 1 P
gc 1278 @1.703s 58%: 0+0.76+0.005 ms clock, 0+0/0.76/0+0.005 ms cpu, 
7->7->3 MB, 8 MB goal, 1 P
gc 1279 @1.704s 58%: 0+0.75+0.005 ms clock, 0+0/0.75/0+0.005 ms cpu, 
7->7->3 MB, 8 MB goal, 1 P
gc 1280 @1.706s 58%: 0.001+0.73+0.005 ms clock, 0.001+0/0.72/0+0.005 ms 
cpu, 7->7->3 MB, 8 MB goal, 1 P
gc 1281 @1.707s 58%: 0+0.74+0.008 ms clock, 0+0/0.74/0+0.008 ms cpu, 
7->7->3 MB, 8 MB goal, 1 P
gc 1282 @1.708s 58%: 0.001+0.76+0.005 ms clock, 0.001+0/0.76/0+0.005 ms 
cpu, 7->7->3 MB, 8 MB goal, 1 P
gc 1283 @1.709s 58%: 0+0.76+0.005 ms clock, 0+0/0.76/0+0.005 ms cpu, 
7->7->3 MB, 8 MB goal, 1 P
gc 1284 @1.710s 58%: 0.001+0.77+0.005 ms clock, 0.001+0/0.76/0+0.005 ms 
cpu, 7->7->3 MB, 8 MB goal, 1 P
gc 1285 @1.712s 58%: 0.001+0.72+0.005 ms clock, 0.001+0/0.72/0+0.005 ms 
cpu, 7->7->3 MB, 8 MB goal, 1 P
gc 1286 @1.713s 58%: 0.001+0.75+0.005 ms clock, 0.001+0/0.74/0+0.005 ms 
cpu, 7->7->3 MB, 8 MB goal, 1 P
gc 1287 @1.714s 58%: 0+0.75+0.005 ms clock, 0+0/0.74/0+0.005 ms cpu, 
7->7->3 MB, 8 MB goal, 1 P
gc 1288 @1.715s 58%: 0+0.78+0.005 ms clock, 0+0/0.77/0+0.005 ms cpu, 
7->7->3 MB, 8 MB goal, 1 P

2.  GOMAXPROCS=4 GODEBUG=gctrace=1 go run worse.go
...
gc 1446 @1.457s 26%: 0.012+0.55+0.076 ms clock, 0.038+0.088/0.54/0.40+0.22 
ms cpu, 5->8->4 MB, 8 MB goal, 4 P
gc 1447 @1.458s 26%: 0.011+0.50+0.074 ms clock, 0.035+0.077/0.49/0.44+0.22 
ms cpu, 5->9->3 MB, 8 MB goal, 4 P
gc 1448 @1.459s 26%: 0.012+0.50+0.062 ms clock, 0.036+0.080/0.48/0.43+0.18 
ms cpu, 5->9->3 MB, 7 MB goal, 4 P
gc 1449 @1.460s 26%: 0.011+0.51+0.064 ms clock, 0.035+0.078/0.47/0.45+0.19 
ms cpu, 5->8->4 MB, 7 MB goal, 4 P
gc 1450 @1.460s 26%: 0.013+0.51+0.064 ms clock, 0.039+0.078/0.50/0.40+0.19 
ms cpu, 5->9->3 MB, 8 MB goal, 4 P
gc 1451 @1.461s 26%: 0.007+0.54+0.060 ms clock, 0.030+0.077/0.54/0.38+0.24 
ms cpu, 5->9->3 MB, 7 MB goal, 4 P
gc 1452 @1.462s 26%: 0.011+0.50+0.063 ms clock, 0.035+0.078/0.46/0.45+0.19 
ms cpu, 5->8->3 MB, 7 MB goal, 4 P
gc 1453 @1.463s 26%: 0.010+0.48+0.055 ms clock, 0.032+0.078/0.47/0.45+0.16 
ms cpu, 5->8->3 MB, 7 MB goal, 4 P
gc 1454 @1.464s 26%: 0.014+0.50+0.059 ms clock, 0.042+0.082/0.50/0.43+0.17 
ms cpu, 4->9->3 MB, 7 MB goal, 4 P
gc 1455 @1.464s 26%: 0.013+0.50+0.060 ms clock, 0.039+0.077/0.49/0.46+0.18 
ms cpu, 5->9->4 MB, 7 MB goal, 4 P
gc 1456 @1.465s 26%: 0.014+0.51+0.060 ms clock, 0.044+0.077/0.51/0.37+0.18 
ms cpu, 5->9->3 MB, 8 MB goal, 4 P
gc 1457 @1.466s 26%: 0.015+0.52+0.058 ms clock, 0.047+0.078/0.51/0.47+0.17 
ms cpu, 4->8->3 MB, 7 MB goal, 4 P
gc 1458 @1.467s 26%: 0.012+0.55+0.061 ms clock, 0.038+0.078/0.53/0.59+0.18 
ms cpu, 5->9->3 MB, 7 MB goal, 4 P


3.  GOMAXPROCS=8 GODEBUG=gctrace=1 go run worse.go
...
gc 2229 @1.659s 22%: 0.022+0.50+0.24 ms clock, 0.089+0.17/0.93/0.27+0.97 ms 
cpu, 11->19->9 MB, 19 MB goal, 8 P
gc 2230 @1.660s 22%: 0.018+0.43+0.071 ms clock, 0.075+0.14/0.81/0.34+0.28 
ms cpu, 10->18->9 MB, 18 MB goal, 8 P
gc 2231 @1.660s 22%: 0.019+0.38+0.23 ms clock, 0.078+0.16/0.71/0.28+0.95 ms 
cpu, 10->18->9 MB, 18 MB goal, 8 P
gc 2232 @1.661s 22%: 0.025+0.38+0.084 ms clock, 0.10+0.16/0.72/0.26+0.33 ms 
cpu, 10->18->9 MB, 19 MB goal, 8 P
gc 2233 @1.662s 22%: 0.023+0.38+0.083 ms clock, 0.095+0.12/0.71/0.30+0.33 
ms cpu, 10->18->9 MB, 19 MB goal, 8 P
gc 2234 @1.663s 22%: 0.018+0.39+0.23 ms clock, 0.074+0.11/0.72/0.34+0.95 ms 
cpu, 10->18->9 MB, 19 MB goal, 8 P
gc 2235 @1.664s 22%: 0.021+0.40+0.090 ms clock, 0.084+0.13/0.72/0.31+0.36 
ms cpu, 10->18->9 MB, 19 MB goal, 8 P
gc 2236 @1.664s 22%: 0.019+0.36+0.077 ms clock, 0.079+0.17/0.67/0.36+0.31 
ms cpu, 11->18->9 MB, 19 MB goal, 8 P
gc 2237 @1.665s 22%: 0.019+0.39+0.23 ms clock, 0.079+0.14/0.72/0.30+0.93 ms 
cpu, 10->18->10 MB, 18 MB goal, 8 P
gc 2238 @1.666s 22%: 0.022+0.39+0.076 ms clock, 0.091+0.15/0.71/0.28+0.30 
ms cpu, 11->19->9 MB, 20 MB goal, 8 P
gc 2239 @1.667s 22%: 0.020+0.40+0.11 ms clock, 0.081+0.18/0.75/0.42+0.44 ms 
cpu, 14->19->9 MB, 19 MB goal, 8 P
gc 2240 @1.667s 22%: 0.019+0.45+0.10 ms clock, 0.077+0.15/0.86/0.23+0.42 ms 
cpu, 10->18->10 MB, 18 MB goal, 8 P


4.GOMAXPROCS=48 GODEBUG=gctrace=1 go run worse.go
..
gc 658 @1.909s 5%: 1.3+1.1+0.46 ms clock, 5.2+3.1/4.6/0+1.8 ms cpu, 
22->43->22 MB, 39 MB goal, 48 P
gc 659 @1.913s 5%: 0.23+1.3+0.37 ms clock, 0.69+1.3/4.2/0+1.1 ms cpu, 
23->48->25 MB, 44 MB goal, 48 P
gc 660 @1.916s 5%: 0.23+0.80+0.44 ms clock, 0.92+2.3/4.4/0+1.7 ms cpu, 
27->45->19 MB, 51 MB goal, 48 P
gc 661 @1.919s 5%: 0.16+0.80+0.44 ms clock, 0.48+2.1/5.4/0+1.3 ms cpu, 
21->37->17 MB, 39 MB goal, 48 P
gc 662 @1.921s 5%: 0.18+0.78+0.43 ms clock, 0.72+3.4/5.2/0+1.7 ms cpu, 
19->34->17 MB, 35 MB goal, 48 P
gc 663 @1.923s 5%: 0.15+1.2+0.39 ms clock, 0.46+1.2/6.6/0+1.1 ms cpu, 
18->39->20 MB, 34 MB goal, 48 P
gc 664 @1.926s 5%: 0.20+0.85+4.5 ms clock, 0.61+1.1/4.6/0+13 ms cpu, 
22->39->18 MB, 41 MB goal, 48 P
gc 665 @1.932s 5%: 0.21+1.1+0.41 ms clock, 0.85+2.2/5.8/0+1.6 ms cpu, 
20->41->21 MB, 37 MB goal, 48 P
gc 666 @1.935s 5%: 0.19+1.3+0.43 ms clock, 0.58+1.3/6.8/0+1.3 ms cpu, 
23->45->22 MB, 43 MB goal, 48 P
gc 667 @1.938s 5%: 0.23+1.0+0.42 ms clock, 0.70+2.3/4.8/0+1.2 ms cpu, 
23->43->20 MB, 44 MB goal, 48 P
gc 668 @1.941s 5%: 0.19+1.1+0.37 ms clock, 0.58+1.3/6.5/0+1.1 ms cpu, 
21->42->22 MB, 40 MB goal, 48 P


I am curious if my application is set GOMAXPROCS=runtime.NumCPU()  (48 core)
How I estimate gc occupy 5% percent  cpu  time ??  it is worse? or not so 
bad ?

在 2017年3月28日星期二 UTC+8下午12:58:15,Dave Cheney写道:
>
> I suggest two things
>
> 1. Post the GODEBUG output here, someone will be able to confirm how much 
> time they GC is using. 
>
> 2. Use github.com/pkg/profile to generate an execution trace and analyse 
> it with go tool trace.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to