Created
January 27, 2021 19:48
-
-
Save GeraldHost/da2e2b9a697caa59ca1e17bae9ec766f to your computer and use it in GitHub Desktop.
basic-go-faster-http-idea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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