Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmark README and latest numbers #689

Merged
merged 10 commits into from
Jan 24, 2020
53 changes: 53 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Benchmarks

## How to run

To run your benchmark, just:
```sh
$ npm run bench
```

The minimum sample size is set to 10 to perform statistical analysis on benchmark, you can re-configure that in `benchmark.js`.

> NOTE: If you're interested in writing benchmark for other APIs, please write a benchmark in the `benchmark/index.js` module. Please refer to the `benchmark/tracer.js` or `benchmark/propagator.js` for more comprehensive examples.

## Results

### `v0.3.3` release

```
Beginning BasicTracerRegistry Benchmark...
7 tests completed.

#startSpan x 79,704 ops/sec ±4.46% (10 runs sampled)
#startSpan:parent x 55,975 ops/sec ±1.90% (10 runs sampled)
#startSpan with attribute x 84,479 ops/sec ±2.82% (10 runs sampled)
#startSpan with 30 attributes x 36,239 ops/sec ±2.67% (10 runs sampled)
#startSpan with 100 attributes x 3,716 ops/sec ±1.92% (10 runs sampled)
#startSpan with SimpleSpanProcessor x 5,440 ops/sec ±39.90% (10 runs sampled)
#startSpan with BatchSpanProcessor x 2,284 ops/sec ±6.51% (10 runs sampled)

Beginning NodeTracerRegistry Benchmark...
7 tests completed.

#startSpan x 81,777 ops/sec ±4.32% (10 runs sampled)
#startSpan:parent x 57,455 ops/sec ±3.87% (10 runs sampled)
#startSpan with attribute x 85,139 ops/sec ±4.09% (10 runs sampled)
#startSpan with 30 attributes x 38,240 ops/sec ±1.95% (10 runs sampled)
#startSpan with 100 attributes x 3,670 ops/sec ±6.85% (10 runs sampled)
#startSpan with SimpleSpanProcessor x 4,504 ops/sec ±37.04% (10 runs sampled)
#startSpan with BatchSpanProcessor x 1,847 ops/sec ±5.26% (10 runs sampled)


Beginning B3Format Benchmark...
2 tests completed.

#Inject x 5,569,330 ops/sec ±1.44% (10 runs sampled)
#Extract x 4,882,488 ops/sec ±3.72% (10 runs sampled)

Beginning HttpTraceContext Benchmark...
2 tests completed.

#Inject x 13,423,892 ops/sec ±4.62% (10 runs sampled)
#Extract x 1,673,804 ops/sec ±2.29% (10 runs sampled)
```
5 changes: 2 additions & 3 deletions benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ const Benchmark = require('benchmark');
const benchmarks = require('beautify-benchmark');

Benchmark.options.maxTime = 0;
// @todo : Change it to between 50-100 or keep it random.
Benchmark.options.minSamples = 10;

module.exports = () => {
module.exports = (minSamples) => {
Benchmark.options.minSamples = minSamples;
const suite = new Benchmark.Suite();

return suite
Expand Down
4 changes: 2 additions & 2 deletions benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
const execSync = require('child_process').execSync;
const exec = cmd => execSync(cmd, { stdio: [0, 1, 2] });

exec('node benchmark/tracer');
exec('node benchmark/propagator');
exec('node benchmark/tracer.js');
exec('node benchmark/propagator.js');
4 changes: 2 additions & 2 deletions benchmark/propagator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const benchmark = require('./benchmark');
const opentelemetry = require('@opentelemetry/core');
const opentelemetry = require('../packages/opentelemetry-core');

const setups = [
{
Expand All @@ -26,7 +26,7 @@ const setups = [
for (const setup of setups) {
console.log(`Beginning ${setup.name} Benchmark...`);
const propagator = setup.propagator;
const suite = benchmark()
const suite = benchmark(100)
.add('#Inject', function () {
propagator.inject({
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
Expand Down
43 changes: 19 additions & 24 deletions benchmark/tracer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';

const benchmark = require('./benchmark');
const opentelemetry = require('@opentelemetry/core');
const { BasicTracerRegistry, BatchSpanProcessor, InMemorySpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { NodeTracerRegistry } = require('@opentelemetry/node');
const opentelemetry = require('../packages/opentelemetry-core');
const { BasicTracerRegistry, BatchSpanProcessor, InMemorySpanExporter, SimpleSpanProcessor } = require('../packages/opentelemetry-tracing');

const exporter = new InMemorySpanExporter();
const logger = new opentelemetry.NoopLogger();

const setups = [
Expand All @@ -14,15 +12,23 @@ const setups = [
registry: new BasicTracerRegistry({ logger })
},
{
name: 'NodeTracerRegistry',
registry: new NodeTracerRegistry({ logger })
name: 'BasicTracerRegistry with SimpleSpanProcessor',
registry: getRegistry(new SimpleSpanProcessor(new InMemorySpanExporter()))
},
{
name: 'BasicTracerRegistry with BatchSpanProcessor',
registry: getRegistry(new BatchSpanProcessor(new InMemorySpanExporter()))
},
{
name: 'NoopTracerRegistry',
registry: opentelemetry.getTracerRegistry()
}
];

for (const setup of setups) {
console.log(`Beginning ${setup.name} Benchmark...`);
const tracer = setup.registry.getTracer("benchmark");
const suite = benchmark()
const suite = benchmark(20)
.add('#startSpan', function () {
const span = tracer.startSpan('op');
span.end();
Expand Down Expand Up @@ -51,25 +57,14 @@ for (const setup of setups) {
span.setAttribute('attr-key-' + j, 'attr-value-' + j);
}
span.end();
})
.add('#startSpan with SimpleSpanProcessor', function () {
const simpleSpanProcessor = new SimpleSpanProcessor(exporter);

registry.addSpanProcessor(simpleSpanProcessor);
const span = tracer.startSpan('op');
span.end();

simpleSpanProcessor.shutdown();
})
.add('#startSpan with BatchSpanProcessor', function () {
const batchSpanProcessor = new BatchSpanProcessor(exporter);

registry.addSpanProcessor(batchSpanProcessor);
const span = tracer.startSpan('op');
span.end();
batchSpanProcessor.shutdown();
});

// run async
suite.run({ async: false });
}
function getRegistry(processor) {
const registry = new BasicTracerRegistry({ logger });
registry.addSpanProcessor(processor);
return registry;
}