On Wed, May 31, 2023 at 8:29 PM Cardy Tang <zunior...@gmail.com> wrote:
>
> We encountering similar issue. It would be great if we can have some form of 
> slicing/offset option/per goroutine stack dumping feature.

The next step would be to design an API that would work well in the
runtime package, and open a proposal, as described at
https://go.dev/s/proposal.  Thanks.

Ian


> On Wednesday, May 31, 2023 at 8:15:58 PM UTC+8 Jinda Lu wrote:
>>
>> Take Containerd as an example. The current way of printing the stack may be 
>> unsafe.
>> Containerd print stack function:
>> ```
>> func dumpStacks(writeToFile bool) {
>> var (
>> buf       []byte
>> stackSize int
>> )
>> bufferLen := 16384
>> for stackSize == len(buf) {
>> buf = make([]byte, bufferLen)
>> stackSize = runtime.Stack(buf, true)
>> bufferLen *= 2
>> }
>> buf = buf[:stackSize]
>> logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine 
>> stack dump ===", buf)
>>
>> if writeToFile {
>> // Also write to file to aid gathering diagnostics
>> name := filepath.Join(os.TempDir(), fmt.Sprintf("containerd.%d.stacks.log", 
>> os.Getpid()))
>> f, err := os.Create(name)
>> if err != nil {
>> return
>> }
>> defer f.Close()
>> f.WriteString(string(buf))
>> logrus.Infof("goroutine stack dump written to %s", name)
>> }
>> }
>> ```
>>
>> In a production environment, containerd will be stuck due to some requests, 
>> resulting in hundreds of thousands of Goroutines. If you dump all the 
>> Goroutine stacks, it may consume several gigabytes of memory.
>> In addition, the log function may enlarge the memory (maybe double the 
>> original size, or more).
>> Can Golang provide stack output of slices? For example, using Goroutine as 
>> the granularity is a good choice.
>>
> --
> 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/8fd185df-8ccc-4de8-ab95-f1d22309c221n%40googlegroups.com.

-- 
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/CAOyqgcW4ExP8T%3DCZWjyjBJtxt1e4S8tdR7MrV4EgOqtY-uK1Rg%40mail.gmail.com.

Reply via email to