Skip to content

Commit 512a37d

Browse files
authored
Merge pull request #18 from smira/split-benchmarks
Split out benchmarks, initialize go.mod
2 parents 76dd963 + 86463d1 commit 512a37d

File tree

6 files changed

+52
-191
lines changed

6 files changed

+52
-191
lines changed

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ go:
88
- 1.12.x
99
- master
1010

11+
env:
12+
- GO111MODULE=on
13+
1114
before_install:
1215
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
1316

Makefile

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
all: test check bench
22

3-
.PHONY: deps
4-
deps:
5-
go get -v -d -t ./...
6-
73
.PHONY: test
8-
test: deps
4+
test:
95
go test -race -v -coverprofile=coverage.txt -covermode=atomic
106

117
.PHONY: bench
12-
bench: deps
8+
bench:
139
go test -v -bench . -benchmem -run nothing ./...
1410

1511
.PHONY: check
16-
check: deps
12+
check:
1713
golangci-lint run
1814

19-
.PHONY: deps bench test check

README.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# go-statsd
2-
31
[![Build Status](https://travis-ci.org/smira/go-statsd.svg?branch=master)](https://travis-ci.org/smira/go-statsd)
42
[![Documentation](https://godoc.org/github.com/smira/go-statsd?status.svg)](http://godoc.org/github.com/smira/go-statsd)
53
[![Go Report Card](https://goreportcard.com/badge/github.com/smira/go-statsd)](https://goreportcard.com/report/github.com/smira/go-statsd)
@@ -95,7 +93,7 @@ client.Incr("request", 1,
9593

9694
## Benchmark
9795

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

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

107105
Benchmark results:
108106

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

116114
## Origins
117115

client_test.go

+36-3
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,39 @@ func TestConcurrent(t *testing.T) {
339339
}
340340
}
341341

342+
func BenchmarkSimple(b *testing.B) {
343+
inSocket, err := net.ListenUDP("udp4", &net.UDPAddr{
344+
IP: net.IPv4(127, 0, 0, 1),
345+
})
346+
if err != nil {
347+
b.Error(err)
348+
}
349+
350+
go func() {
351+
buf := make([]byte, 1500)
352+
for {
353+
_, err := inSocket.Read(buf)
354+
if err != nil {
355+
return
356+
}
357+
}
358+
359+
}()
360+
361+
c := NewClient(inSocket.LocalAddr().String(), MetricPrefix("metricPrefix"), MaxPacketSize(1432),
362+
FlushInterval(100*time.Millisecond), SendLoopCount(2))
363+
364+
b.ResetTimer()
365+
366+
for i := 0; i < b.N; i++ {
367+
c.Incr("foo.bar.counter", 1)
368+
c.Gauge("foo.bar.gauge", 42)
369+
c.PrecisionTiming("foo.bar.timing", 153*time.Millisecond)
370+
}
371+
_ = c.Close()
372+
_ = inSocket.Close()
373+
}
374+
342375
func BenchmarkComplexDelivery(b *testing.B) {
343376
inSocket, err := net.ListenUDP("udp4", &net.UDPAddr{
344377
IP: net.IPv4(127, 0, 0, 1),
@@ -392,14 +425,14 @@ func BenchmarkTagged(b *testing.B) {
392425

393426
}()
394427

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

399432
b.ResetTimer()
400433

401434
for i := 0; i < b.N; i++ {
402-
client.Incr(counterKey, 1, StringTag("route", "api.one"), IntTag("status", 200))
435+
client.Incr("foo.bar.counter", 1, StringTag("route", "api.one"), IntTag("status", 200))
403436
client.Timing("another.value", 157, StringTag("service", "db"))
404437
client.PrecisionTiming("response.time.for.some.api", 150*time.Millisecond, IntTag("status", 404))
405438
client.PrecisionTiming("response.time.for.some.api.case1", 150*time.Millisecond, StringTag("service", "db"), IntTag("status", 200))

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/smira/go-statsd
2+
3+
go 1.12

statsdbench_test.go

-171
This file was deleted.

0 commit comments

Comments
 (0)