Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5bc23b0

Browse files
authored
Add resource usage performance tests for creating a span (open-telemetry#1499)
1 parent 731f32c commit 5bc23b0

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,26 @@ pip install -e ./instrumentation/opentelemetry-instrumentation-{instrumentation}
9797
For additional exporter and instrumentation packages, see the
9898
[`opentelemetry-python-contrib`](https://github.com/open-telemetry/opentelemetry-python-contrib) repository.
9999

100+
## Running Performance Tests
101+
102+
This section provides details on how to reproduce performance tests results on your own
103+
machine.
104+
105+
### Resource Usage Tests
106+
107+
1. Install scalene using the following command
108+
109+
::
110+
111+
pip install -U scalene
112+
113+
2. Run the `scalene` tests on any of the example Python programs
114+
115+
::
116+
117+
scalene opentelemetry-<PACKAGE>/tests/performance/resource-usage/<PATH_TO_TEST>/profile_resource_usage_<NAME_OF_TEST>.py
118+
119+
100120
## Documentation
101121

102122
The online documentation is available at https://opentelemetry-python.readthedocs.io/.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import time
16+
from unittest.mock import patch
17+
18+
from opentelemetry.exporter.otlp.trace_exporter import OTLPSpanExporter
19+
from opentelemetry.sdk.trace import TracerProvider, sampling
20+
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
21+
22+
TEST_DURATION_SECONDS = 15
23+
SPANS_PER_SECOND = 10_000
24+
25+
26+
class MockTraceServiceStub(object):
27+
def __init__(self, channel):
28+
self.Export = lambda *args, **kwargs: None
29+
30+
31+
old_stub = OTLPSpanExporter._stub
32+
OTLPSpanExporter._stub = MockTraceServiceStub
33+
34+
simple_span_processor = BatchExportSpanProcessor(OTLPSpanExporter())
35+
tracer = TracerProvider(
36+
active_span_processor=simple_span_processor, sampler=sampling.DEFAULT_ON,
37+
).get_tracer("resource_usage_tracer")
38+
39+
starttime = time.time()
40+
for _ in range(TEST_DURATION_SECONDS):
41+
for _ in range(SPANS_PER_SECOND):
42+
span = tracer.start_span("benchmarkedSpan")
43+
span.end()
44+
time_to_finish_spans = time.time() - starttime
45+
time.sleep(1.0 - time_to_finish_spans if time_to_finish_spans < 1.0 else 0)
46+
47+
OTLPSpanExporter._stub = old_stub
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import time
16+
from unittest.mock import patch
17+
18+
from opentelemetry.exporter.otlp.trace_exporter import OTLPSpanExporter
19+
from opentelemetry.sdk.trace import TracerProvider, sampling
20+
from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor
21+
22+
TEST_DURATION_SECONDS = 15
23+
SPANS_PER_SECOND = 10_000
24+
25+
26+
class MockTraceServiceStub(object):
27+
def __init__(self, channel):
28+
self.Export = lambda *args, **kwargs: None
29+
30+
31+
old_stub = OTLPSpanExporter._stub
32+
OTLPSpanExporter._stub = MockTraceServiceStub
33+
34+
simple_span_processor = SimpleExportSpanProcessor(OTLPSpanExporter())
35+
tracer = TracerProvider(
36+
active_span_processor=simple_span_processor, sampler=sampling.DEFAULT_ON,
37+
).get_tracer("resource_usage_tracer")
38+
39+
starttime = time.time()
40+
for _ in range(TEST_DURATION_SECONDS):
41+
for _ in range(SPANS_PER_SECOND):
42+
span = tracer.start_span("benchmarkedSpan")
43+
span.end()
44+
time_to_finish_spans = time.time() - starttime
45+
time.sleep(1.0 - time_to_finish_spans if time_to_finish_spans < 1.0 else 0)
46+
47+
OTLPSpanExporter._stub = old_stub

0 commit comments

Comments
 (0)