Skip to content

Instantly share code, notes, and snippets.

@GeraldHost
Created January 27, 2021 19:48
Show Gist options
  • Save GeraldHost/da2e2b9a697caa59ca1e17bae9ec766f to your computer and use it in GitHub Desktop.
Save GeraldHost/da2e2b9a697caa59ca1e17bae9ec766f to your computer and use it in GitHub Desktop.
basic-go-faster-http-idea
// This is obviously shit code but you get the idea
// we use a connection and when it closes we open a new one
// but we want this to run concurrently so we need some kind of connection
// pool that all the go routines can dip into
func Dial() net.Conn {
conn, _ := net.Dial("tcp", "localhost:3000")
return conn
}
func BenchmarkHttp2(b *testing.B) {
conn := Dial()
for i := 0; i < b.N; i++ {
tmp := make([]byte, 12)
_, err := conn.Write([]byte("GET / HTTP/1.0\r\n\r\n"))
if err != nil {
conn = Dial()
continue
}
_, err = conn.Read(tmp)
if err != nil {
conn = Dial()
continue
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment