Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: dynamically adjust initial stack size according to workload #31558

valyala opened this issue Apr 18, 2019 · 1 comment


None yet
2 participants
Copy link

commented Apr 18, 2019

The issue

Typical server written in go has the following loop (net/http.Server has similar loop):

for {
    conn := listener.Accept()
    go serveConn(conn)


for {
    req := getRequest()
    go serveRequest(req)

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.

cc'ing @josharian and @aclements


This comment has been minimized.

Copy link

commented Apr 18, 2019

Dup of #18138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.