//question > I write a simple golang tcp server > and use tcp short connect client to bench it. > when qps up to 28K, client have many dial i/o timeout > > I don't know what is the performance bottleneck?? > > I modify the server: > cat /proc/sys/net/ipv4/tcp_max_syn_backlog 1024 > cat /proc/sys/net/core/somaxconn 1024
//a simple golang tcp server package main import ( "io" "log" "net" ) func init() { log.SetFlags(log.LstdFlags | log.Lshortfile) } func main() { tcpAddr, err := net.ResolveTCPAddr("tcp", ":9999") if err != nil { log.Println(err) return } tcpListener, err := net.ListenTCP("tcp", tcpAddr) if err != nil { log.Println(err) return } defer tcpListener.Close() for { tcpConn, err := tcpListener.AcceptTCP() if err != nil { log.Println(err) continue } go handle(tcpConn) } } func handle(conn *net.TCPConn) { //log.Println(conn.RemoteAddr().String()) buf := make([]byte, 1024) for { _, err := conn.Read(buf) if err != nil { if err != io.EOF { log.Println(err) } return } _, err = conn.Write([]byte{'h', 'e', 'l', 'l', 'o'}) if err != nil { log.Println(err) } } } // tcp short connection bench package main import ( "log" "net" "sync" "time" ) var ( wg sync.WaitGroup ) func init() { log.SetFlags(log.LstdFlags | log.Lshortfile) } func main() { for i := 0; i < 150; i++ { wg.Add(1) go func() { for { req() time.Sleep(10 * time.Millisecond) } wg.Done() }() } wg.Wait() } // tcp req func req() { conn, err := net.DialTimeout("tcp", "192.168.67.133:9999", 300*time.Millisecond) if err != nil { log.Println(err) return } // conn.SetDeadline(time.Now().Add(300 * time.Millisecond)) defer conn.Close() _, err = conn.Write([]byte("client")) if err != nil { log.Println(err) return } buf := make([]byte, 1024) _, err = conn.Read(buf) if err != nil { log.Println(err) } } -- 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. For more options, visit https://groups.google.com/d/optout.