From b2128904e2e25c5473de89d8bce5039adfab318d Mon Sep 17 00:00:00 2001 From: Bjoern Rabenstein Date: Tue, 27 Jan 2015 17:16:23 +0100 Subject: [PATCH] Add BenchmarkProcessor002ParseOnly, to get at least a hint of the JSON speed. --- .../fixtures/test0_0_1-0_0_2-large.json | 1032 +++++++++++++++++ extraction/processor0_0_2_test.go | 24 + text/bench_test.go | 5 +- 3 files changed, 1060 insertions(+), 1 deletion(-) create mode 100644 extraction/fixtures/test0_0_1-0_0_2-large.json diff --git a/extraction/fixtures/test0_0_1-0_0_2-large.json b/extraction/fixtures/test0_0_1-0_0_2-large.json new file mode 100644 index 0000000..7168338 --- /dev/null +++ b/extraction/fixtures/test0_0_1-0_0_2-large.json @@ -0,0 +1,1032 @@ +[ + { + "baseLabels": { + "__name__": "rpc_calls_total_0", + "job": "batch_job" + }, + "docstring": "Total count of RPC calls.", + "metric": { + "type": "counter", + "value": [ + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": 25 + }, + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "foo" + }, + "value": 25 + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_latency_microseconds_0" + }, + "docstring": "RPC latency summary.", + "metric": { + "type": "histogram", + "value": [ + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": { + "0.010000": 15.890724674774395, + "0.050000": 15.890724674774395, + "0.500000": 84.63044031436561, + "0.900000": 160.21100853053224, + "0.990000": 172.49828748957728 + } + }, + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": { + "0.010000": 0.0459814091918713, + "0.050000": 0.0459814091918713, + "0.500000": 0.6120456642749681, + "0.900000": 1.355915069887731, + "0.990000": 1.772733213161236 + } + }, + { + "labels": { + "foo": "bar", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_calls_total_1", + "job": "batch_job" + }, + "docstring": "Total count of RPC calls.", + "metric": { + "type": "counter", + "value": [ + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": 25 + }, + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "foo" + }, + "value": 25 + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_latency_microseconds_1" + }, + "docstring": "RPC latency summary.", + "metric": { + "type": "histogram", + "value": [ + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": { + "0.010000": 15.890724674774395, + "0.050000": 15.890724674774395, + "0.500000": 84.63044031436561, + "0.900000": 160.21100853053224, + "0.990000": 172.49828748957728 + } + }, + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": { + "0.010000": 0.0459814091918713, + "0.050000": 0.0459814091918713, + "0.500000": 0.6120456642749681, + "0.900000": 1.355915069887731, + "0.990000": 1.772733213161236 + } + }, + { + "labels": { + "foo": "bar", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_calls_total_2", + "job": "batch_job" + }, + "docstring": "Total count of RPC calls.", + "metric": { + "type": "counter", + "value": [ + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": 25 + }, + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "foo" + }, + "value": 25 + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_latency_microseconds_2" + }, + "docstring": "RPC latency summary.", + "metric": { + "type": "histogram", + "value": [ + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": { + "0.010000": 15.890724674774395, + "0.050000": 15.890724674774395, + "0.500000": 84.63044031436561, + "0.900000": 160.21100853053224, + "0.990000": 172.49828748957728 + } + }, + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": { + "0.010000": 0.0459814091918713, + "0.050000": 0.0459814091918713, + "0.500000": 0.6120456642749681, + "0.900000": 1.355915069887731, + "0.990000": 1.772733213161236 + } + }, + { + "labels": { + "foo": "bar", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_calls_total_3", + "job": "batch_job" + }, + "docstring": "Total count of RPC calls.", + "metric": { + "type": "counter", + "value": [ + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": 25 + }, + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "foo" + }, + "value": 25 + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_latency_microseconds_3" + }, + "docstring": "RPC latency summary.", + "metric": { + "type": "histogram", + "value": [ + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": { + "0.010000": 15.890724674774395, + "0.050000": 15.890724674774395, + "0.500000": 84.63044031436561, + "0.900000": 160.21100853053224, + "0.990000": 172.49828748957728 + } + }, + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": { + "0.010000": 0.0459814091918713, + "0.050000": 0.0459814091918713, + "0.500000": 0.6120456642749681, + "0.900000": 1.355915069887731, + "0.990000": 1.772733213161236 + } + }, + { + "labels": { + "foo": "bar", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_calls_total_4", + "job": "batch_job" + }, + "docstring": "Total count of RPC calls.", + "metric": { + "type": "counter", + "value": [ + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": 25 + }, + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "foo" + }, + "value": 25 + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_latency_microseconds_4" + }, + "docstring": "RPC latency summary.", + "metric": { + "type": "histogram", + "value": [ + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": { + "0.010000": 15.890724674774395, + "0.050000": 15.890724674774395, + "0.500000": 84.63044031436561, + "0.900000": 160.21100853053224, + "0.990000": 172.49828748957728 + } + }, + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": { + "0.010000": 0.0459814091918713, + "0.050000": 0.0459814091918713, + "0.500000": 0.6120456642749681, + "0.900000": 1.355915069887731, + "0.990000": 1.772733213161236 + } + }, + { + "labels": { + "foo": "bar", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_calls_total_5", + "job": "batch_job" + }, + "docstring": "Total count of RPC calls.", + "metric": { + "type": "counter", + "value": [ + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": 25 + }, + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "foo" + }, + "value": 25 + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_latency_microseconds_5" + }, + "docstring": "RPC latency summary.", + "metric": { + "type": "histogram", + "value": [ + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": { + "0.010000": 15.890724674774395, + "0.050000": 15.890724674774395, + "0.500000": 84.63044031436561, + "0.900000": 160.21100853053224, + "0.990000": 172.49828748957728 + } + }, + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": { + "0.010000": 0.0459814091918713, + "0.050000": 0.0459814091918713, + "0.500000": 0.6120456642749681, + "0.900000": 1.355915069887731, + "0.990000": 1.772733213161236 + } + }, + { + "labels": { + "foo": "bar", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_calls_total_6", + "job": "batch_job" + }, + "docstring": "Total count of RPC calls.", + "metric": { + "type": "counter", + "value": [ + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": 25 + }, + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "foo" + }, + "value": 25 + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_latency_microseconds_6" + }, + "docstring": "RPC latency summary.", + "metric": { + "type": "histogram", + "value": [ + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": { + "0.010000": 15.890724674774395, + "0.050000": 15.890724674774395, + "0.500000": 84.63044031436561, + "0.900000": 160.21100853053224, + "0.990000": 172.49828748957728 + } + }, + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": { + "0.010000": 0.0459814091918713, + "0.050000": 0.0459814091918713, + "0.500000": 0.6120456642749681, + "0.900000": 1.355915069887731, + "0.990000": 1.772733213161236 + } + }, + { + "labels": { + "foo": "bar", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_calls_total_7", + "job": "batch_job" + }, + "docstring": "Total count of RPC calls.", + "metric": { + "type": "counter", + "value": [ + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": 25 + }, + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "foo" + }, + "value": 25 + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_latency_microseconds_7" + }, + "docstring": "RPC latency summary.", + "metric": { + "type": "histogram", + "value": [ + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": { + "0.010000": 15.890724674774395, + "0.050000": 15.890724674774395, + "0.500000": 84.63044031436561, + "0.900000": 160.21100853053224, + "0.990000": 172.49828748957728 + } + }, + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": { + "0.010000": 0.0459814091918713, + "0.050000": 0.0459814091918713, + "0.500000": 0.6120456642749681, + "0.900000": 1.355915069887731, + "0.990000": 1.772733213161236 + } + }, + { + "labels": { + "foo": "bar", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_calls_total_8", + "job": "batch_job" + }, + "docstring": "Total count of RPC calls.", + "metric": { + "type": "counter", + "value": [ + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": 25 + }, + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "foo" + }, + "value": 25 + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_latency_microseconds_8" + }, + "docstring": "RPC latency summary.", + "metric": { + "type": "histogram", + "value": [ + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": { + "0.010000": 15.890724674774395, + "0.050000": 15.890724674774395, + "0.500000": 84.63044031436561, + "0.900000": 160.21100853053224, + "0.990000": 172.49828748957728 + } + }, + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": { + "0.010000": 0.0459814091918713, + "0.050000": 0.0459814091918713, + "0.500000": 0.6120456642749681, + "0.900000": 1.355915069887731, + "0.990000": 1.772733213161236 + } + }, + { + "labels": { + "foo": "bar", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_calls_total_9", + "job": "batch_job" + }, + "docstring": "Total count of RPC calls.", + "metric": { + "type": "counter", + "value": [ + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": 25 + }, + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": 25 + }, + { + "labels": { + "foo": "baz", + "service": "foo" + }, + "value": 25 + } + ] + } + }, + { + "baseLabels": { + "__name__": "rpc_latency_microseconds_9" + }, + "docstring": "RPC latency summary.", + "metric": { + "type": "histogram", + "value": [ + { + "labels": { + "foo": "bar", + "service": "foo" + }, + "value": { + "0.010000": 15.890724674774395, + "0.050000": 15.890724674774395, + "0.500000": 84.63044031436561, + "0.900000": 160.21100853053224, + "0.990000": 172.49828748957728 + } + }, + { + "labels": { + "foo": "bar", + "service": "zed" + }, + "value": { + "0.010000": 0.0459814091918713, + "0.050000": 0.0459814091918713, + "0.500000": 0.6120456642749681, + "0.900000": 1.355915069887731, + "0.990000": 1.772733213161236 + } + }, + { + "labels": { + "foo": "bar", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + }, + { + "labels": { + "foo": "baz", + "service": "bar" + }, + "value": { + "0.010000": 78.48563317257356, + "0.050000": 78.48563317257356, + "0.500000": 97.31798360385088, + "0.900000": 109.89202084295582, + "0.990000": 109.99626121011262 + } + } + ] + } + } +] diff --git a/extraction/processor0_0_2_test.go b/extraction/processor0_0_2_test.go index 6a7d458..6ef8fb3 100644 --- a/extraction/processor0_0_2_test.go +++ b/extraction/processor0_0_2_test.go @@ -14,7 +14,9 @@ package extraction import ( + "bytes" "errors" + "io/ioutil" "os" "path" "runtime" @@ -200,3 +202,25 @@ func BenchmarkProcessor002Process(b *testing.B) { b.Logf("Allocated %d at %f per cycle with %d cycles.", allocated, float64(allocated)/float64(b.N), b.N) } + +func BenchmarkProcessor002ParseOnly(b *testing.B) { + b.StopTimer() + data, err := ioutil.ReadFile("fixtures/test0_0_1-0_0_2-large.json") + if err != nil { + b.Fatal(err) + } + ing := fakeIngester{} + b.StartTimer() + + for i := 0; i < b.N; i++ { + if err := Processor002.ProcessSingle(bytes.NewReader(data), ing, &ProcessOptions{}); err != nil { + b.Fatal(err) + } + } +} + +type fakeIngester struct{} + +func (i fakeIngester) Ingest(model.Samples) error { + return nil +} diff --git a/text/bench_test.go b/text/bench_test.go index 806551e..e343bff 100644 --- a/text/bench_test.go +++ b/text/bench_test.go @@ -19,7 +19,6 @@ import ( "io" "io/ioutil" "testing" - dto "github.com/prometheus/client_model/go" "github.com/matttproud/golang_protobuf_extensions/ext" @@ -40,6 +39,10 @@ import ( // the difference becomes less relevant, only ~4x. // // The test data contains 248 samples. +// +// BenchmarkProcessor002ParseOnly in the extraction package is not quite +// comparable to the benchmarks here, but it gives an idea: JSON parsing is even +// slower than text parsing and needs a comparable amount of allocs. // BenchmarkParseText benchmarks the parsing of a text-format scrape into metric // family DTOs.