Skip to content

Commit

Permalink
Merge pull request #18 from smira/split-benchmarks
Browse files Browse the repository at this point in the history
Split out benchmarks, initialize go.mod
  • Loading branch information
smira authored May 15, 2019
2 parents 76dd963 + 86463d1 commit 512a37d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 191 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ go:
- 1.12.x
- master

env:
- GO111MODULE=on

before_install:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0

Expand Down
11 changes: 3 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
all: test check bench

.PHONY: deps
deps:
go get -v -d -t ./...

.PHONY: test
test: deps
test:
go test -race -v -coverprofile=coverage.txt -covermode=atomic

.PHONY: bench
bench: deps
bench:
go test -v -bench . -benchmem -run nothing ./...

.PHONY: check
check: deps
check:
golangci-lint run

.PHONY: deps bench test check
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# go-statsd

[![Build Status](https://travis-ci.org/smira/go-statsd.svg?branch=master)](https://travis-ci.org/smira/go-statsd)
[![Documentation](https://godoc.org/github.com/smira/go-statsd?status.svg)](http://godoc.org/github.com/smira/go-statsd)
[![Go Report Card](https://goreportcard.com/badge/github.com/smira/go-statsd)](https://goreportcard.com/report/github.com/smira/go-statsd)
Expand Down Expand Up @@ -95,7 +93,7 @@ client.Incr("request", 1,

## Benchmark

Benchmark comparing several clients:
[Benchmark](https://github.com/smira/go-statsd-benchmark) comparing several clients:

* https://github.com/alexcesaro/statsd/ (`Alexcesaro`)
* this client (`GoStatsd`)
Expand All @@ -106,12 +104,12 @@ Benchmark comparing several clients:

Benchmark results:

BenchmarkAlexcesaro-8 3000000 476 ns/op 0 B/op 0 allocs/op
BenchmarkGoStatsd-8 5000000 266 ns/op 1 B/op 0 allocs/op
BenchmarkCactus-8 2000000 626 ns/op 11 B/op 0 allocs/op
BenchmarkG2s-8 50000 20539 ns/op 576 B/op 21 allocs/op
BenchmarkQuipo-8 1000000 1508 ns/op 383 B/op 6 allocs/op
BenchmarkUnix4ever-8 1000000 1906 ns/op 376 B/op 18 allocs/op
BenchmarkAlexcesaro-12 5000000 333 ns/op 0 B/op 0 allocs/op
BenchmarkGoStatsd-12 10000000 230 ns/op 23 B/op 0 allocs/op
BenchmarkCactus-12 3000000 604 ns/op 5 B/op 0 allocs/op
BenchmarkG2s-12 200000 7499 ns/op 576 B/op 21 allocs/op
BenchmarkQuipo-12 1000000 1048 ns/op 384 B/op 7 allocs/op
BenchmarkUnix4ever-12 1000000 1695 ns/op 408 B/op 18 allocs/op

## Origins

Expand Down
39 changes: 36 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,39 @@ func TestConcurrent(t *testing.T) {
}
}

func BenchmarkSimple(b *testing.B) {
inSocket, err := net.ListenUDP("udp4", &net.UDPAddr{
IP: net.IPv4(127, 0, 0, 1),
})
if err != nil {
b.Error(err)
}

go func() {
buf := make([]byte, 1500)
for {
_, err := inSocket.Read(buf)
if err != nil {
return
}
}

}()

c := NewClient(inSocket.LocalAddr().String(), MetricPrefix("metricPrefix"), MaxPacketSize(1432),
FlushInterval(100*time.Millisecond), SendLoopCount(2))

b.ResetTimer()

for i := 0; i < b.N; i++ {
c.Incr("foo.bar.counter", 1)
c.Gauge("foo.bar.gauge", 42)
c.PrecisionTiming("foo.bar.timing", 153*time.Millisecond)
}
_ = c.Close()
_ = inSocket.Close()
}

func BenchmarkComplexDelivery(b *testing.B) {
inSocket, err := net.ListenUDP("udp4", &net.UDPAddr{
IP: net.IPv4(127, 0, 0, 1),
Expand Down Expand Up @@ -392,14 +425,14 @@ func BenchmarkTagged(b *testing.B) {

}()

client := NewClient(inSocket.LocalAddr().String(), MetricPrefix(prefixNoDot), MaxPacketSize(1432),
FlushInterval(flushPeriod), SendLoopCount(2), DefaultTags(StringTag("host", "foo")),
client := NewClient(inSocket.LocalAddr().String(), MetricPrefix("metricPrefix"), MaxPacketSize(1432),
FlushInterval(100*time.Millisecond), SendLoopCount(2), DefaultTags(StringTag("host", "foo")),
SendQueueCapacity(10), BufPoolCapacity(40))

b.ResetTimer()

for i := 0; i < b.N; i++ {
client.Incr(counterKey, 1, StringTag("route", "api.one"), IntTag("status", 200))
client.Incr("foo.bar.counter", 1, StringTag("route", "api.one"), IntTag("status", 200))
client.Timing("another.value", 157, StringTag("service", "db"))
client.PrecisionTiming("response.time.for.some.api", 150*time.Millisecond, IntTag("status", 404))
client.PrecisionTiming("response.time.for.some.api.case1", 150*time.Millisecond, StringTag("service", "db"), IntTag("status", 200))
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/smira/go-statsd

go 1.12
171 changes: 0 additions & 171 deletions statsdbench_test.go

This file was deleted.

0 comments on commit 512a37d

Please sign in to comment.