[go-nuts] Why constant is not addressable in golang?
I guess that const will be substitute literally at compile time for performance improvements. So there is not such variable in run time. Is it right? -- 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.
Re: [go-nuts] Why constant is not addressable in golang?
Thanks for your explaination, I was just curious about the language constraint details. 在 2017年8月21日星期一 UTC+8下午2:16:25,Axel Wagner写道: > > If a constant was addressable, you could do > > const x = 42 > x = 23 > fmt.Println(x) // 23 > > so a constant wouldn't be constant anymore. The minimum Go would need, to > make constants addressable would be some notion of const-pointers (that is, > pointers which don't allow modification of the pointee). > > May I ask why it would be interesting to take the address of a constant? > > On Mon, Aug 21, 2017 at 7:23 AM, chou > > wrote: > >> I guess that const will be substitute literally at compile time >> for performance improvements. So there is not such variable in >> run time. >> >> Is it right? >> >> -- >> 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...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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.
[go-nuts] Re: Dave Cheney's "Practical Go" book
I want to buy one, is it released out? 在 2017年9月5日星期二 UTC+8上午7:41:36,st ov写道: > > Any information on the contents and a release date? > > Couldn't find any details on O'reilly, Amazon or dave.cheney.net. > -- 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.
[go-nuts] How to set a callback for cgo ?
Hi everyone, I want to set a callback for atexit, but it seems doesn't work. This is my code. package main /* #include extern void AtExit(); static inline set_atexit() { atexit(AtExit); AtExit(); } */ import "C" import ( "fmt" "io/ioutil" "time" ) var n = 0 //export AtExit func AtExit() { ioutil.WriteFile(fmt.Sprintf("exit%d", n), []byte("yes, exit success\n"), 0644) n++ } func main() { C.set_atexit() fmt.Println("call set_atexit") } I get the file 'exit0', but didn't get the file 'exit1'. Best regards, Astone -- 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.
Re: [go-nuts] How to set a callback for cgo ?
sorry for late reply. thanks very much. it got the key. 在 2019年1月11日星期五 UTC+8下午10:09:17,Jan Mercl写道: > > > On Fri, Jan 11, 2019 at 2:49 PM > wrote: > > > I get the file 'exit0', but didn't get the file 'exit1'. > > As far as I can tell, it works as expected. Exit handlers are called when > libc's 'exit' is invoked. I don't think that the Go runtime does that. The > proper way to handle process exiting is to handle it in its parent process. > > -- > > -j > -- 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.
[go-nuts] How many times gc stw ?
I look up the doc for gctrace: https://godoc.org/runtime it show us: Currently, it is: gc # @#s #%: #+#+# ms clock, #+#/#/#+# ms cpu, #->#-># MB, # MB goal, # P where the fields are as follows: gc #the GC number, incremented at each GC @#s time in seconds since program start #% percentage of time spent in GC since program start #+...+# wall-clock/CPU times for the phases of the GC #->#-># MB heap size at GC start, at GC end, and live heap # MB goal goal heap size # P number of processors used The phases are stop-the-world (STW) sweep termination, concurrent mark and scan, and STW mark termination. The CPU times for mark/scan are broken down in to assist time (GC performed in line with allocation), background GC time, and idle GC time. If the line ends with "(forced)", this GC was forced by a runtime.GC() call. I am very confused. Will it be swt in the cleanup phase? And how many times gc stw? mark start? concurrent mark? remark ? or sweep ? -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/0b509e5d-fe61-478b-9b88-f21a29d1f9cf%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How many times gc stw ?
Sorry. Which I understand is that 'sweep termination = clean up = release the physical memory' The long comment is helpful. I got 'b. Sweep any unswept spans. There will only be unswept spans if this GC cycle was forced before the expected time.' Dose it means 'sweep = scan the root span', like java cms 'gc root scan'? not the release the physical memory? 在 2019年6月21日星期五 UTC+8上午8:54:31,Ian Lance Taylor写道: > > On Thu, Jun 20, 2019 at 9:56 AM Chou Yan > wrote: > > > > I look up the doc for gctrace: > > https://godoc.org/runtime > > it show us: > > > > Currently, it is: > > gc # @#s #%: #+#+# ms clock, #+#/#/#+# ms cpu, #->#-># MB, # MB goal, # > P > > where the fields are as follows: > > gc #the GC number, incremented at each GC > > @#s time in seconds since program start > > #% percentage of time spent in GC since program start > > #+...+# wall-clock/CPU times for the phases of the GC > > #->#-># MB heap size at GC start, at GC end, and live heap > > # MB goal goal heap size > > # P number of processors used > > The phases are stop-the-world (STW) sweep termination, concurrent > > mark and scan, and STW mark termination. The CPU times > > for mark/scan are broken down in to assist time (GC performed in > > line with allocation), background GC time, and idle GC time. > > If the line ends with "(forced)", this GC was forced by a > > runtime.GC() call. > > > > > > I am very confused. Will it be swt in the cleanup phase? > > I'm sorry, I don't understand what you are asking. What is the cleanup > phase? > > > And how many times gc stw? mark start? concurrent mark? remark ? or > sweep ? > > See the long comment near the top of runtime/mgc.go. Currently each > cycle stops the world twice, very briefly, in the sweep termination > and mark termination phases. > > Ian > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/58a54b06-271c-4c39-a891-2ec157c42ee9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How many times gc stw ?
The describe 'release the physical memory' may not be rigorous. Because gc remand the span,obj, or big obj to heap or central area, may not release the physical memory. "When the next GC starts, it sweeps all not-yet-swept spans (if any)." maybe it is the sweeps termination phrase mean. BTW, I look the doc and look up three time of stw. sweep termination GC performs the mark phase. No objects may be //scanned until all Ps have enabled the write barrier, which is //accomplished using STW. mark termination phases. or "write barrier" accomplished during sweep termination? 在 2019年6月21日星期五 UTC+8上午8:54:31,Ian Lance Taylor写道: > > On Thu, Jun 20, 2019 at 9:56 AM Chou Yan > wrote: > > > > I look up the doc for gctrace: > > https://godoc.org/runtime > > it show us: > > > > Currently, it is: > > gc # @#s #%: #+#+# ms clock, #+#/#/#+# ms cpu, #->#-># MB, # MB goal, # > P > > where the fields are as follows: > > gc #the GC number, incremented at each GC > > @#s time in seconds since program start > > #% percentage of time spent in GC since program start > > #+...+# wall-clock/CPU times for the phases of the GC > > #->#-># MB heap size at GC start, at GC end, and live heap > > # MB goal goal heap size > > # P number of processors used > > The phases are stop-the-world (STW) sweep termination, concurrent > > mark and scan, and STW mark termination. The CPU times > > for mark/scan are broken down in to assist time (GC performed in > > line with allocation), background GC time, and idle GC time. > > If the line ends with "(forced)", this GC was forced by a > > runtime.GC() call. > > > > > > I am very confused. Will it be swt in the cleanup phase? > > I'm sorry, I don't understand what you are asking. What is the cleanup > phase? > > > And how many times gc stw? mark start? concurrent mark? remark ? or > sweep ? > > See the long comment near the top of runtime/mgc.go. Currently each > cycle stops the world twice, very briefly, in the sweep termination > and mark termination phases. > > Ian > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/7b0bedb9-3450-4502-bfa3-c290be1b51f8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] How many times gc stw ?
thx 在 2019年6月21日星期五 UTC+8下午12:38:50,Ian Lance Taylor写道: > > On Thu, Jun 20, 2019 at 7:22 PM Chou Yan > wrote: > > > > The describe 'release the physical memory' may not be rigorous. Because > gc remand the span,obj, or big obj to heap or central area, may not release > the physical memory. > > "When the next GC starts, it sweeps all not-yet-swept spans (if any)." > > maybe it is the sweeps termination phrase mean. > > BTW, I look the doc and look up three time of stw. > > sweep termination > > > > GC performs the mark phase. No objects may be > > > > //scanned until all Ps have enabled the write barrier, which is > > //accomplished using STW. > > > > mark termination phases. > > or "write barrier" accomplished during sweep termination? > > The write barrier is enabled as sweep termination completes. > > Ian > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3b7f3799-f44c-4640-908f-17e148b2fb6c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] how to decrease the HeapIdle of Memory to free memory to Linux?
My server have 100G memory. I limit my server 60G by cgroups. But my app process use the momory more and more ! even more than 50G. my prof: # HeapIdle = 27377164288 # HeapInuse = 21910396928 The Cgroup will kill the process when it use more than 60G But golang runtime gc will not release the memory to the os. It's bad. The Go garbage collector occasionally makes requests to the OS to release unused memory. The OS may decide to not release the memory because the system has plenty to spare, other some other reason . How should this be solved? -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/14555dc7-2acd-48df-a206-8687a6697358%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: how to decrease the HeapIdle of Memory to free memory to Linux?
some of gc logs: gc 8639 @331692.423s 6%: 60+2541+2.3 ms clock, 1928+112357/40484/0+75 ms cpu, 22264->22299->4575 MB, 23164 MB goal, 64 P gc 8640 @331719.932s 6%: 21+2580+1.5 ms clock, 673+106151/41127/0+48 ms cpu, 21976->22064->4769 MB, 22878 MB goal, 64 P gc 8641 @331759.750s 6%: 31+2671+1.6 ms clock, 1019+115220/42609/0+54 ms cpu, 22904->22985->4785 MB, 23848 MB goal, 64 P gc 8642 @331805.499s 6%: 86+2647+2.0 ms clock, 2771+106447/42162/0+65 ms cpu, 22976->23081->4678 MB, 23926 MB goal, 64 P scvg2211: 0 MB released scvg2211: inuse: 23445, idle: 23386, sys: 46832, released: 20705, consumed: 26126 (MB) gc 8643 @331847.230s 6%: 43+2588+1.3 ms clock, 1399+112616/41295/0+44 ms cpu, 22463->22514->4605 MB, 23391 MB goal, 64 P gc 8644 @331880.496s 6%: 31+2528+4.0 ms clock, 1001+113331/40209/0+128 ms cpu, 22127->22159->4613 MB, 23025 MB goal, 64 P gc 8645 @331912.342s 6%: 35+2544+0.67 ms clock, 1145+109977/40616/0+21 ms cpu, 22151->22215->4685 MB, 23069 MB goal, 64 P scvg2212: 81 MB released scvg2212: inuse: 25495, idle: 21334, sys: 46830, released: 20773, consumed: 26056 (MB) gc 8646 @331959.029s 6%: 35+2602+9.3 ms clock, 1136+109565/40585/0+297 ms cpu, 22495->22569->4643 MB, 23425 MB goal, 64 P 在 2019年6月24日星期一 UTC+8上午10:59:06,Chou Yan写道: > > My server have 100G memory. > I limit my server 60G by cgroups. > But my app process use the momory more and more ! > even more than 50G. > my prof: > > # HeapIdle = 27377164288 > # HeapInuse = 21910396928 > > The Cgroup will kill the process when it use more than 60G > > But golang runtime gc will not release the memory to the os. > > It's bad. > > The Go garbage collector occasionally makes requests to the OS to release > unused memory. The OS may decide to not release the memory because the system > has plenty to spare, other some other reason . > How should this be solved? > > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/68d6e955-5ea9-445b-99d6-ae87c569b434%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: how to decrease the HeapIdle of Memory to free memory to Linux?
I am use 'debug.FreeOsMemory'. But it is not the certain. 在 2019年6月24日星期一 UTC+8上午10:59:06,Chou Yan写道: > > My server have 100G memory. > I limit my server 60G by cgroups. > But my app process use the momory more and more ! > even more than 50G. > my prof: > > # HeapIdle = 27377164288 > # HeapInuse = 21910396928 > > The Cgroup will kill the process when it use more than 60G > > But golang runtime gc will not release the memory to the os. > > It's bad. > > The Go garbage collector occasionally makes requests to the OS to release > unused memory. The OS may decide to not release the memory because the system > has plenty to spare, other some other reason . > How should this be solved? > > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9556e37e-a59d-4249-a761-bfd026370dd5%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: how to decrease the HeapIdle of Memory to free memory to Linux?
I use 'debug.FreeOsMemory'. But it is not the certain. 在 2019年6月24日星期一 UTC+8上午10:59:06,Chou Yan写道: > > My server have 100G memory. > I limit my server 60G by cgroups. > But my app process use the momory more and more ! > even more than 50G. > my prof: > > # HeapIdle = 27377164288 > # HeapInuse = 21910396928 > > The Cgroup will kill the process when it use more than 60G > > But golang runtime gc will not release the memory to the os. > > It's bad. > > The Go garbage collector occasionally makes requests to the OS to release > unused memory. The OS may decide to not release the memory because the system > has plenty to spare, other some other reason . > How should this be solved? > > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/0bc4f86c-833c-4798-b06c-a1559edd6212%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] rand seed using 'time.Now().Unix()' consequence mass common rand numbers, but using unixNano as the seed will not ,how to choose the rand's seed between 'time.Now().Unix()' and 'time.Now().U
I use: r:=rand.New(rand.NewSource(time.Now().Unix())) r..Intn(96) I got: and val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 39 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 rand val: 82 ... mass common sequential number . But if I change that: r:=rand.New(rand.NewSource(time.Now().UnixNano())) It will not happen. Why does this happened? and how do I choose it between time.Now().Unix() or UnixNano()? -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/ce0671c5-f2df-42d9-a7af-bdef939e6d6d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] rand seed using 'time.Now().Unix()' consequence mass common rand numbers, but using unixNano as the seed will not ,how to choose the rand's seed between 'time.Now().Unix()' and 'time.Now
like this: r:=rand.New(rand.NewSource(time.Now().Unix())) for { r.Intn(96) } I know the same seed will generate the same sequence. But I don't know why it generate mass same number when I use seed of 'time.Now().Unix()', But when I use seed of 'time.Now().UnixNano()', It will not. I suspect what this is related to the seqence rand algorithm,But I have no relevant evidence 在 2019年6月27日星期四 UTC+8上午10:32:38,Burak Serdar写道: > > On Wed, Jun 26, 2019 at 8:17 PM Chou Yan > wrote: > > > > I use: > > r:=rand.New(rand.NewSource(time.Now().Unix())) > > r..Intn(96) > > How are you generating multiple random numbers? If your loop that > generates these numbers include the r:=rand.New(...), then you're > essentially seeding the random number generator with the same number, > because the program ends before time.Now().Unix() returns a different > value every second. > > Move the r:=rand.New(...) outsite the for loop. > > > I got: > > > > and val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 39 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > rand val: 82 > > ... > > mass common sequential number . > > But if I change that: > > r:=rand.New(rand.NewSource(time.Now().UnixNano())) > > It will not happen. > > Why does this happened? and how do I choose it between time.Now().Unix() > or UnixNano()? > > > > -- > > 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 golan...@googlegroups.com . > > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/ce0671c5-f2df-42d9-a7af-bdef939e6d6d%40googlegroups.com. > > > > For more options, visit https://groups.google.com/d/optout. > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/99351298-7843-4556-b422-8635eb96c936%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] rand seed using 'time.Now().Unix()' consequence mass common rand numbers, but using unixNano as the seed will not ,how to choose the rand's seed between 'time.Now().Unix()' and 'time.Now
The situation I am currently experiencing is that it only occur on my online app. I try it at local but I can not got the result. haha... I make a mistake. the code is : func WeightRandom(services []*registry.Service) Next{ w := weighted.NewRandW() for _, service := range services { for _,n := range service.Nodes { w.Add(n,n.Weight) } } return func() (*registry.Node, error) { n := w.Next() no, ok := n.(*registry.Node) if !ok { return nil,errors.New("get next err") } return no, nil } } The 'rand.New(...SEED)' is outside the loop of for But I neglect that this func 'WeightRandom' will be mass goroutine call. so each time.Now().Unix() ,the same seed ,the same sequence. So I got mass common rand number.But when I change it as time.Now().UnixNano(), the seed will not be the same because of the unixnano. so I got correctly. thank you very much 在 2019年6月27日星期四 UTC+8上午10:52:56,Burak Serdar写道: > > On Wed, Jun 26, 2019 at 8:48 PM Chou Yan > wrote: > > > > like this: > > r:=rand.New(rand.NewSource(time.Now().Unix())) > > for { > > r.Intn(96) > > } > > I know the same seed will generate the same sequence. But I don't know > why it generate mass same number when I use seed of 'time.Now().Unix()', > But when I use seed of 'time.Now().UnixNano()', It will not. > > I suspect what this is related to the seqence rand algorithm,But I have > no relevant evidence > > This doesn't make sense. Can you reproduce it in the go playground? > > > > > 在 2019年6月27日星期四 UTC+8上午10:32:38,Burak Serdar写道: > >> > >> On Wed, Jun 26, 2019 at 8:17 PM Chou Yan wrote: > >> > > >> > I use: > >> > r:=rand.New(rand.NewSource(time.Now().Unix())) > >> > r..Intn(96) > >> > >> How are you generating multiple random numbers? If your loop that > >> generates these numbers include the r:=rand.New(...), then you're > >> essentially seeding the random number generator with the same number, > >> because the program ends before time.Now().Unix() returns a different > >> value every second. > >> > >> Move the r:=rand.New(...) outsite the for loop. > >> > >> > I got: > >> > > >> > and val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 39 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > rand val: 82 > >> > ... > >> > mass common sequential number . > >> > But if I change that: > >> > r:=rand.New(rand.NewSource(time.Now().UnixNano())) > >> > It will not happen. > >> > Why does this happened? and how do I choose it between > time.Now().Unix() or UnixNano()? > >> > > >> > -- > >> > 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 golan...@googlegroups.com. > >> > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/ce0671c5-f2df-42d9-a7af-bdef939e6d6d%40googlegroups.com. > > > >> > For more options, visit https://groups.google.com/d/optout. > > > > -- > > 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 golan...@googlegroups.com . > > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/99351298-7843-4556-b422-8635eb96c936%40googlegroups.com. > > > > For more options, visit https://groups.google.com/d/optout. > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/1760eb39-21e7-479b-bea7-8276e03e3873%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] rand seed using 'time.Now().Unix()' consequence mass common rand numbers, but using unixNano as the seed will not ,how to choose the rand's seed between 'time.Now().Unix()' and 'time.Now
I fix it by : var w = weighted.NewRandW() func WeightRandom(services []*registry.Service) Next{ for _, service := range services { for _,n := range service.Nodes { w.Add(n,n.Weight) } } return func() (*registry.Node, error) { n := w.Next() no, ok := n.(*registry.Node) if !ok { return nil,errors.New("get next err") } return no, nil } } thx 在 2019年6月27日星期四 UTC+8上午11:16:01,Chou Yan写道: > > The situation I am currently experiencing is that it only occur on my > online app. I try it at local but I can not got the result. > haha... I make a mistake. > the code is : > > func WeightRandom(services []*registry.Service) Next{ > w := weighted.NewRandW() > for _, service := range services { > for _,n := range service.Nodes { > w.Add(n,n.Weight) > } > } > return func() (*registry.Node, error) { > n := w.Next() > no, ok := n.(*registry.Node) > if !ok { > return nil,errors.New("get next err") > } > return no, nil > } > } > > The 'rand.New(...SEED)' is outside the loop of for But I neglect that this > func 'WeightRandom' will be mass goroutine call. so each time.Now().Unix() > ,the same seed ,the same sequence. So I got mass common rand number.But > when I change it as time.Now().UnixNano(), the seed will not be the same > because of the unixnano. so I got correctly. thank you very much > > 在 2019年6月27日星期四 UTC+8上午10:52:56,Burak Serdar写道: >> >> On Wed, Jun 26, 2019 at 8:48 PM Chou Yan wrote: >> > >> > like this: >> > r:=rand.New(rand.NewSource(time.Now().Unix())) >> > for { >> > r.Intn(96) >> > } >> > I know the same seed will generate the same sequence. But I don't know >> why it generate mass same number when I use seed of 'time.Now().Unix()', >> But when I use seed of 'time.Now().UnixNano()', It will not. >> > I suspect what this is related to the seqence rand algorithm,But I have >> no relevant evidence >> >> This doesn't make sense. Can you reproduce it in the go playground? >> >> > >> > 在 2019年6月27日星期四 UTC+8上午10:32:38,Burak Serdar写道: >> >> >> >> On Wed, Jun 26, 2019 at 8:17 PM Chou Yan wrote: >> >> > >> >> > I use: >> >> > r:=rand.New(rand.NewSource(time.Now().Unix())) >> >> > r..Intn(96) >> >> >> >> How are you generating multiple random numbers? If your loop that >> >> generates these numbers include the r:=rand.New(...), then you're >> >> essentially seeding the random number generator with the same number, >> >> because the program ends before time.Now().Unix() returns a different >> >> value every second. >> >> >> >> Move the r:=rand.New(...) outsite the for loop. >> >> >> >> > I got: >> >> > >> >> > and val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 39 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > rand val: 82 >> >> > ... >> >> > mass common sequential number . >> >> > But if I change that: >> >> > r:=rand.New(rand.NewSource(time.Now().UnixNano())) >> >> > It will not happen. >
Re: [go-nuts] rand seed using 'time.Now().Unix()' consequence mass common rand numbers, but using unixNano as the seed will not ,how to choose the rand's seed between 'time.Now().Unix()' and 'time.Now
thx. you are right. I make a mistake. I negleck that my func will be called by mass goroutine, it will get the same seed and the same sequence 在 2019年6月27日星期四 UTC+8上午11:07:28,Kurtis Rader写道: > > Works for me: https://play.golang.org/p/zD5F7gp41re > > Like Burak I suspect you are initializing the RNG in a tight loop. Since > `time.Now().Unix()` has a resolution of one second you end up generating > the same initial value every time through the loop until the current time > advances to the next second. > > On Wed, Jun 26, 2019 at 7:48 PM Chou Yan > wrote: > >> like this: >> r:=rand.New(rand.NewSource(time.Now().Unix())) >> for { >> r.Intn(96) >> } >> I know the same seed will generate the same sequence. But I don't know >> why it generate mass same number when I use seed of 'time.Now().Unix()', >> But when I use seed of 'time.Now().UnixNano()', It will not. >> I suspect what this is related to the seqence rand algorithm,But I have >> no relevant evidence >> >> 在 2019年6月27日星期四 UTC+8上午10:32:38,Burak Serdar写道: >>> >>> On Wed, Jun 26, 2019 at 8:17 PM Chou Yan wrote: >>> > >>> > I use: >>> > r:=rand.New(rand.NewSource(time.Now().Unix())) >>> > r..Intn(96) >>> >>> How are you generating multiple random numbers? If your loop that >>> generates these numbers include the r:=rand.New(...), then you're >>> essentially seeding the random number generator with the same number, >>> because the program ends before time.Now().Unix() returns a different >>> value every second. >>> >>> Move the r:=rand.New(...) outsite the for loop. >>> >>> > I got: >>> > >>> > and val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 39 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > rand val: 82 >>> > ... >>> > mass common sequential number . >>> > But if I change that: >>> > r:=rand.New(rand.NewSource(time.Now().UnixNano())) >>> > It will not happen. >>> > Why does this happened? and how do I choose it between >>> time.Now().Unix() or UnixNano()? >>> > >>> > -- >>> > 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 golan...@googlegroups.com. >>> > To view this discussion on the web visit >>> https://groups.google.com/d/msgid/golang-nuts/ce0671c5-f2df-42d9-a7af-bdef939e6d6d%40googlegroups.com. >>> >>> >>> > For more options, visit https://groups.google.com/d/optout. >>> >> -- >> 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 golan...@googlegroups.com . >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/99351298-7843-4556-b422-8635eb96c936%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/99351298-7843-4556-b422-8635eb96c936%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > Kurtis Rader > Caretaker of the exceptional canines Junior and Hank > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/1e5a8486-ef43-4258-8ffc-d21dc542638f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] rand seed using 'time.Now().Unix()' consequence mass common rand numbers, but using unixNano as the seed will not ,how to choose the rand's seed between 'time.Now().Unix()' and 'time.Now
It's the context: // NewRandW creates a new RandW with a random object. func NewRandW() *RandW { return &RandW{r: rand.New(rand.NewSource(time.Now().Unix()))} } n := w.Next() // Next returns next selected item. func (rw *RandW) Next() (item interface{}) { ... randomWeight := rw.r.Intn(rw.sumOfWeights) //fmt.Printf("rand val: %d\n",randomWeight) ... } I am sorry about that I did't give the context of my code. 在 2019年6月27日星期四 UTC+8上午11:22:49,Kurtis Rader写道: > > On Wed, Jun 26, 2019 at 8:18 PM Chou Yan > wrote: > >> I fix it by : >> >> var w = weighted.NewRandW() >> > > Insufficient context to understand what that does. Let alone how it > "fixes" the problem since you haven't shown us your `NewRandW()` function. > In general you should never initialize a RNG more than once unless you are > doing so to create a reproducible sequence of values. In which case you > should be initializing it with a constant value rather than a pseudo-random > value like `time.Now().Unix()`. > > -- > Kurtis Rader > Caretaker of the exceptional canines Junior and Hank > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/638a5f5b-552f-4f56-9f7f-3253fb8c2e29%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Does scheduler step in my weighted fair queue implementation?
I implemented a weighted fair queue using a naive approach which is giving different amount of attempts according to weights to access upstreams. However, when calls of fetch() come very fast, our internal sync constructs are not ready(when *select*) and many attempts are simply wasted. It seems that Go's scheduler steps in, therefore the results of many scenarios are not always predictable. The involvement of Go's scheduler seems unavoidable. So is it innately unfit to implement WFQ in this way? One solution is to sleep in between calls of fetch() to simulate a constraint bandwidth which gives the scheduler leeway to synchronize, but this brings up another question of how long it should sleep. An alternative is instead of trying to access multiple queues in one process, use as many processes as the weight of one queue to serve the queue in question. Or can we tune the scheduler to what we want? What's the suggestion for this sort of problem? Code below: func Test_WFQ_DoNotWork(t *testing.T) { msgNum := 3600 // upstreams run at the same pace c1 := make(chan int, msgNum) c2 := make(chan int, msgNum) go func() { for i := 0; i < msgNum; i++ { c1 <- i c2 <- i } }() //weights 1:2 queueNames := []string{ "c1", "c2", "c2"} errEmpty := errors.New("msg N/A") fetch := func(c <-chan int) (int, error) { select { case i :=<- c: return i, nil default: return 0, errEmpty } } countC1, countC2 := 0, 0 for i := 0; i < msgNum; i++ { idx := i % len(queueNames) if queueNames[idx] == "c1" { _, err := fetch(c1) if err == nil { countC1++ } } else { _, err := fetch(c2) if err == nil { countC2++ } } } // The output is not always expected 1200:24000 fmt.Printf("countC1:%d, countC2:%d", countC1, countC2) } -- 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.
Re: [go-nuts] Does scheduler step in my weighted fair queue implementation?
The reason why using select instead ok-comma is because I don't one upstream to block another. Using blocking ok-comma is ok when upstreams are fast. However, when one is slow, others could starve. On Friday, July 14, 2017 at 12:46:27 PM UTC+8, Ian Lance Taylor wrote: > > On Thu, Jul 13, 2017 at 9:15 PM, Chifeng Chou > wrote: > > > > I implemented a weighted fair queue using a naive approach which is > giving > > different amount of attempts according to weights to access upstreams. > > However, when calls of fetch() come very fast, our internal sync > constructs > > are not ready(when select) and many attempts are simply wasted. > > It seems that Go's scheduler steps in, therefore the results of many > > scenarios are not always predictable. > > > > The involvement of Go's scheduler seems unavoidable. So is it innately > unfit > > to implement WFQ in this way? > > I don't understand why you are using a select statement with a default > case. > > Just use the comma-ok form to read from the channel, as in > https://play.golang.org/p/OqK0nELGcX . > > Ian > -- 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.
[go-nuts] defer func running timing
Hello, https://go.dev/play/p/J1tVplkIrjt why o1.Ref print `2` but p1.Ref print `1` ? why o1.Ref print `2` but o2.NonRef print `3` ? it's so confused. -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/19cbb40a-b21a-4dd5-964d-7921095de33dn%40googlegroups.com.
Re: [go-nuts] defer func running timing
Thanks for taking time. It's really big help. I understand what exactly happened. best regards - lee 在2022年6月26日星期日 UTC+8 05:11:29 写道: > Maybe it's clearer if you look at what's happening like this > https://go.dev/play/p/jAia9OPJfbY > > The arguments to defer are evaluated immediately, but the execution only > happens later > > - sean > > On Sat, Jun 25, 2022, 21:40 Lee Chou wrote: > >> Hello, >> >> https://go.dev/play/p/J1tVplkIrjt >> >> why o1.Ref print `2` but p1.Ref print `1` ? >> why o1.Ref print `2` but o2.NonRef print `3` ? it's so confused. >> >> -- >> 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...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/19cbb40a-b21a-4dd5-964d-7921095de33dn%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/19cbb40a-b21a-4dd5-964d-7921095de33dn%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/30cf2594-151f-4452-bb4d-7efd0a5dd0e7n%40googlegroups.com.
[go-nuts] Some confusion about escape analysis
I was try using net.Buffers for writev. But I meet a unexptected allocs in benchmark. https://go.dev/play/p/SHpxSYbP1I5 when I run the benchmark: goos: linux goarch: amd64 pkg: writev BenchmarkWrite_Writev/escape-4 272901 4198 ns/op 24 B/op 1 allocs/op BenchmarkWrite_Writev/noescape-4 273751 4267 ns/op 0 B/op 0 allocs/op PASS ok writev3.410s Is the noescape safe ? Is there a better way to avoid the alloc/escape ? - Best regards Lee -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/04b23c46-b992-444d-b80e-cb02eaf06a43n%40googlegroups.com.
[go-nuts] Re: Some confusion about escape analysis
Thanks for taking the time for the clue. It seems that this is an open issue. Actually, It work for this case. aovid the alloc will have more benefit for gc. 在2022年8月26日星期五 UTC+8 02:49:08 写道: > Actually, looking more closely at your benchmark numbers, the trick does > not work in your case. Which makes sense to me, I don't see why it would > work. > > On Wednesday, August 24, 2022 at 2:59:34 AM UTC-4 mozart...@gmail.com > wrote: > >> I was try using net.Buffers for writev. But I meet a unexptected allocs >> in benchmark. >> >> https://go.dev/play/p/SHpxSYbP1I5 >> >> when I run the benchmark: >> >> goos: linux >> goarch: amd64 >> pkg: writev >> BenchmarkWrite_Writev/escape-4 272901 4198 ns/op >>24 B/op 1 allocs/op >> BenchmarkWrite_Writev/noescape-4 273751 4267 ns/op >> 0 B/op 0 allocs/op >> PASS >> ok writev3.410s >> >> Is the noescape safe ? >> Is there a better way to avoid the alloc/escape ? >> - >> Best regards >> Lee >> > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/95daef29-ff45-4d3a-bca8-d8911b74eabbn%40googlegroups.com.
[go-nuts] Which part of go compiler set the symbol "runtime.text" in the final build?
Yesterday, I reported an issue on debug/gosym at issues/65232 regarding the difference between the symbol table and gopclntab. A member of the Go team informed me that the start of the .text segment is not always kept the same as 'runtime.text' value. I am curious about how the compiler sets this symbol and if there is a way to obtain this value without relying on the symbol table. Additionally, how does a compiled binary locate it even after being stripped? Any suggestions would be appreciated. -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/cf32849d-64a0-4615-bfa1-8add7b1f2b62n%40googlegroups.com.
[go-nuts] Re: Reproducible builds with CGO
golang will embed the path of the source file into the binary, also the .gopclntab will contains the path. try use -trimpath and see if there's any change. 在2024年4月27日星期六 UTC+8 01:28:05 写道: > Hi All, > > *Does anybody have experience in how the use of CGO and dynamic linking > may affect the reproducibility of a Go project?* > > *Context* > I am trying to reproduce a Linux amd64 binary release using the same > source commit, os & dist, Go, C compiler, and linker version. It reproduces > locally but not against the reference build. I can see that e.g. > gnu.build-id is embedded, yet the diffs are much larger than this, for > example seeing differences in the ELF .rodata (which may or may not have to > do with the use of CGO). > > Regards, > Vivi > > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/716dbec1-c492-4229-8865-668e96714ff5n%40googlegroups.com.
[go-nuts] Re: programmatic way to find if application go binary is built with -cover flag ?
try debug.ReadBuildInfo(), then iterate the pair in the buildinfo.Settings 在2024年5月13日星期一 UTC+8 20:56:51 写道: > Is there a way in go to find whether a go binary is built with -cover flag > ? -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b78a192f-80f9-4a93-a1d6-bed613e56000n%40googlegroups.com.
[go-nuts] Discover go-size-analyzer: Streamline Your Go Binary Insights
Hello go-nuts, I'm excited to share a new tool that has landed in our Go ecosystem: go-size-analyzer. This utility is designed to give you a clear picture of the size of your compiled Go binaries, with a focus on how dependencies contribute to the overall footprint. It simplifies the process of binary size analysis and offers a range of viewing options, from web interfaces to terminal UIs and text formats. It's also highly customisable, so you can tailor the output to suit your needs. The project is open source and actively seeking contributions, so if you're interested in this kind of tool, it's definitely worth a look. You can find more information and get started with go-size-analyzer on its GitHub page: https://github.com/Zxilly/go-size-analyzer Happy coding! Best, Zxilly -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/af78ab03-f793-40f2-8721-20ef3f3a5a13n%40googlegroups.com.
Re: [go-nuts] strip / reduce module compile size
Please try https://github.com/Zxilly/go-size-analyzer . I created this based on reverse engineering, so only the bytes in the final build will be count. 在2024年6月18日星期二 UTC+8 01:14:09 写道: > Are there other tools that may show the final size? I'd like to see if > there are more aggressive flags to strip unused code? It's a simple module, > with some grpc (protobuf), http . I don't believe all these code paths are > in scope for my 200 LOC > > On Friday, June 14, 2024 at 6:20:37 PM UTC-7 Dan Kortschak wrote: > >> On Fri, 2024-06-14 at 19:35 -0500, robert engels wrote: >> > Something doesn’t seem right... You state the total compiled size is >> > 22MB, but the first 3 entries combined are more than that. >> >> It looks like goweight just gets the size of the .a files that are >> generated during the build and returns the sum of that for each of the >> dependencies. So it does not take into account the the linker's removal >> of unused things. >> >> -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/ad94bcbd-6c44-4d31-84be-eecf72111860n%40googlegroups.com.
[go-nuts] Re: go tool cover vs go tool covdata
Simply, cover for text format coverage and covdata for bianry format. 在2024年7月10日星期三 UTC+8 18:07:21 写道: > what is the difference between go tool cover and go tool covdata ? > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/5ab8ea29-3c46-4b87-8f50-5685eec6bf42n%40googlegroups.com.
[go-nuts] Why is there a huge gap between the memory profile's inuse_space in pprof and the externally obtained memory footprint?
I'm working on the project https://github.com/Zxilly/go-size-analyzer, a program that can be very memory intensive, so I've written some scripts to fetch the pprof file during integration testing, and I'm using python's psutil to read the cpu and memory usage to automatically plot into the images. Recently I was working on some optimizations so I started to analyze the pprof files collected in CI, my test program prints the heap profile file once per second, but I noticed that in all mem pprof files the process memory footprint varies dramatically for both inuse_space and psutil reads. Here are two images showing the data read by the same test. As shown in the figure, the difference in size between the memory read by psutil and the memory fetched by pprof is almost 800mb. I know that mem pprof can't count data on the stack, but I don't think the stack holds that much. You can download the data collected by CI and the rendered images at https://github.com/Zxilly/go-size-analyzer/actions/runs/10007859171/artifacts/1718981276. The data is in the cockroach-linux-amd64/json directory in the tarball. Below is the key code for collecting data. python part: ps_process = psutil.Process(process.pid) while process.poll() is None: percent = ps_process.cpu_percent(interval=0.1) mem = ps_process.memory_info().rss / (1024 * 1024) elapsed_time = time.time() - start_time if elapsed_time > timeout: raise TimeoutError(f"Process {name} timed out after {timeout} seconds.") if draw: cpu_percentages.append(percent) memory_usage_mb.append(mem) timestamps.append(elapsed_time) golang part: var ctx context.Context ctx, heapProfileStop = context.WithCancel(context.Background()) go func() { ticker := time.NewTicker(1 * time.Second) defer ticker.Stop() id := 0 write := func() { id++ path := filepath.Join(outputDir, fmt.Sprintf("mem-%d.pprof", id)) f, err := os.Create(path) defer func(f *os.File) { err = f.Close() if err != nil { panic(err) } }(f) if err != nil { panic(err) } err = pprof.WriteHeapProfile(f) if err != nil { panic(err) } } for { select { case <-ctx.Done(): write() return case <-ticker.C: write() } } }() -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/117b16d4-a1a2-46a1-915e-8b7d8b607a46n%40googlegroups.com.
[go-nuts] Re: Can a golang program be compiled to run with only ONE goroutine ?
If you compile it to WebAssembly, it will works under the single thread model. However, there are still multi *goroutine *be created, it was designed to. 在2024年9月10日星期二 UTC+8 21:54:56 写道: > Hello, > > Maybe the question has already been asked, but I would be glad to have > your feedback. > > *Can a golang program be compiled to run with only one goroutine, or at > least one "OS thread" ?* > > I am aware of using GOMAXPROCS(1) to have only one "OS thread" or to use > taskset > -c 1 go build . to force having one "OS thread". These commands don't > really work in practice, since with trace execution tools, I can see that > many threads are used during the execution at the end. > > Thank you for your help, > Karolina > -- > Les informations contenues dans ce message électronique ainsi que celles > contenues dans les documents attachés sont strictement confidentielles et > sont destinées à l'usage exclusif du (des) destinataire(s) nommé(s). > Toute divulgation, distribution ou reproduction, même partielle, en est > strictement interdite sauf autorisation écrite et expresse de l’émetteur. > Si vous recevez ce message par erreur, veuillez le notifier immédiatement > à son émetteur par retour, et le détruire ainsi que tous les documents qui > y sont attachés. > > The information contained in this email and in any document enclosed is > strictly confidential and is intended solely for the use of the individual > or entity to which it is addressed. > Partial or total disclosure, distribution or reproduction of its contents > is strictly prohibited unless expressly approved in writing by the sender. > If you have received this communication in error, please notify us > immediately by responding to this email, and then delete the message and > its attached files from your system. > -- > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/4a673bea-dd59-4f20-acb0-507b4d60059en%40googlegroups.com.