I'm trying to stress test my golang net/http server with k6. When I'm using 2048 virtual users to hit my aws ubuntu server, k6 throws "connection reset by peer". Investigating on the internet, I found that probably the backlog queue is the problem. Reading some stackoverflow questions, I tried to modify SOMAXCONN variable from sysctl.conf file. After modifying it from 128 to 1024, when I run my main go program:
package main
import (
"fmt"
"log"
"net/http"
"strings"
"golang.org/x/sys/unix"
)
func main() {
http.HandleFunc("/some_path", handler)
fmt.Println("SOMAXCONN:", unix.SOMAXCONN)
log.Fatal(http.ListenAndServe(":8888", nil))
}
I have the following terminal output:
SOMAXCONN: 128
When in fact it should print:
SOMAXCONN: 1024
I'd appreciate if anyone can explain me why is GOLANG detecting 128 and not 1024.
I would guess that the way you are checking the SOMAX is set when go is compiled?
Checking it in a different way by reading from /proc shows that net.core.somaxconn is altered
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
filename := "/proc/sys/net/core/somaxconn"
f, err := os.Open(filename)
data := make([]byte, 100)
_, err2 := f.Read(data)
if err != nil || err2 != nil {
log.Println(err2)
log.Fatal(err)
}
fmt.Printf("SOMAXCONN: %v", string(data))
log.Fatal(http.ListenAndServe(":8888", nil))
}