You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code starts new goroutine for serving each incoming connection or request. Go runtime starts new goroutines with small initial stack sizes (2KB). This stack may grow if serveConn or serveRequest calls many nested functions. This results in unnecessary CPU time spent in newStack calls for each incoming connection or request. See this article from Uber engineers for details.
The solution
Create new goroutines with dynamic initial stack sizes according to stack size stats from recently exited goroutines. This will eliminate newStack calls in typical server code, including net/http.Server.
The workaround I don't like
To serve connections / requests via goroutine pool. See this article for details.
The issue
Typical server written in go has the following loop (net/http.Server has similar loop):
or
This code starts new goroutine for serving each incoming connection or request. Go runtime starts new goroutines with small initial stack sizes (2KB). This stack may grow if
serveConn
orserveRequest
calls many nested functions. This results in unnecessary CPU time spent innewStack
calls for each incoming connection or request. See this article from Uber engineers for details.The solution
Create new goroutines with dynamic initial stack sizes according to stack size stats from recently exited goroutines. This will eliminate
newStack
calls in typical server code, includingnet/http.Server
.The workaround I don't like
To serve connections / requests via goroutine pool. See this article for details.
cc'ing @josharian and @aclements
The text was updated successfully, but these errors were encountered: