Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
listener: Add benchmarks for HTTP listener
Browse files Browse the repository at this point in the history
  • Loading branch information
mjs committed May 22, 2018
1 parent 842bcce commit d7a711e
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions listener/listener_medium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,46 @@ func BenchmarkListenerLatency(b *testing.B) {
b.StopTimer()
}

func BenchmarkHTTPListener(b *testing.B) {
listener := startHTTPListener(b, testConfig())
defer listener.Stop()

listenerCh, unsubscribe := subListener(b)
defer unsubscribe()

url := fmt.Sprintf("http://localhost:%d/write", listenPort)
line := []byte(fmt.Sprintf("foo bar=2 %d", time.Now().UnixNano()))
reader := bytes.NewReader(line)

b.ResetTimer()
for i := 0; i < b.N; i++ {
http.Post(url, "text/plain", reader)
reader.Seek(0, 0)
<-listenerCh
}
b.StopTimer()
}

func BenchmarkHTTPListenerWithPrecision(b *testing.B) {
listener := startHTTPListener(b, testConfig())
defer listener.Stop()

listenerCh, unsubscribe := subListener(b)
defer unsubscribe()

url := fmt.Sprintf("http://localhost:%d/write?precision=s", listenPort)
line := []byte(fmt.Sprintf("foo bar=2 %d", time.Now().UnixNano()/int64(time.Second)))
reader := bytes.NewReader(line)

b.ResetTimer()
for i := 0; i < b.N; i++ {
http.Post(url, "text/plain", reader)
reader.Seek(0, 0)
<-listenerCh
}
b.StopTimer()
}

func startListener(t require.TestingT, conf *config.Config) *Listener {
listener, err := StartListener(conf)
require.NoError(t, err)
Expand Down

0 comments on commit d7a711e

Please sign in to comment.