felixge / httpsnoop

Package httpsnoop provides an easy way to capture http related metrics (i.e. response time, bytes written, and http status code) from your application's http.Handlers.

Home Page:https://godoc.org/github.com/felixge/httpsnoop

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

runtime.newStack getting called from Wrap?

ankon opened this issue · comments

We're looking at CPU profiles of our servers, and noticed that there's a considerable amount of runtime.newStack getting attributed to httpsnoop.Wrap:
Screenshot 2024-02-06 at 13 36 31

I cannot find any explicit code doing that though, do you have any pointers here that could help us track this down (and ultimately eliminate)?

Sorry for the late reply. What you're seeing is the stack of the goroutine growing from it's initial size (probably 2 KiB) to a bigger size (probably 4 KiB) due to the initially stack having filled up, and more space being required by the current callee (in this case httpsnooop.Wrap. The fact that this is happening in httpsnoop is coincidental. If you were to add another middleware, you'd probably see the stack growth happening in those functions. Or if you remove a middleware, you'd see the stack growth in your final handler code.

I'm closing this issue for now because this is more of a general Go performance topic best discussed on either the Go issue tracker (there are already issues for this, please search before opening a new one) or similar forums.