-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d9a031
commit 929b9d1
Showing
4 changed files
with
486 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import subprocess | ||
import venv | ||
import shutil | ||
|
||
def create_venv(venv_path: str) -> None: | ||
venv.create(venv_path, with_pip=True) | ||
|
||
def install_package(venv_path: str, package: str) -> int: | ||
subprocess.run([f"{venv_path}/bin/pip", "install", package], check=True) | ||
|
||
def import_package(venv_path: str, package: str) -> str: | ||
subprocess.run([f"{venv_path}/bin/python", "-X", "importtime", "-c", f"{package}"], check=True) | ||
|
||
""" | ||
v0.5.0 | ||
import time: self [us] | cumulative | imported package | ||
import time: 297 | 408355 | snowflake.telemetry._internal.exporter.otlp.proto.logs | ||
""" | ||
|
||
""" | ||
v0.6.0.dev | ||
import time: self [us] | cumulative | imported package | ||
import time: 320 | 219479 | snowflake.telemetry._internal.exporter.otlp.proto.logs | ||
""" | ||
def main(): | ||
venv_path = ".benchmark-import-venv" | ||
create_venv(venv_path) | ||
install_package(venv_path, "./") | ||
print("Import time:") | ||
import_package(venv_path, "import snowflake.telemetry._internal.exporter.otlp.proto.logs") | ||
shutil.rmtree(venv_path) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from util import get_logs_data | ||
|
||
from snowflake.telemetry._internal.opentelemetry.exporter.otlp.proto.common._log_encoder import encode_logs | ||
|
||
from opentelemetry.exporter.otlp.proto.common._log_encoder import encode_logs as pb2_encode_logs | ||
|
||
|
||
# Run with pytest --memray tests/benchmark_memory.py | ||
|
||
""" | ||
===================================================================================== MEMRAY REPORT ====================================================================================== | ||
Allocation results for benchmark/benchmark_memory.py::test_pb2_encode_logs at the high watermark | ||
📦 Total memory allocated: 10.0MiB | ||
📏 Total allocations: 7 | ||
📊 Histogram of allocation sizes: |█ ▄▄█| | ||
🥇 Biggest allocating functions: | ||
- _encode_log:/Users/jopel/workspace/snowflake-telemetry-python/.venv/lib/python3.11/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py:52 -> 6.8MiB | ||
- _encode_resource_logs:/Users/jopel/workspace/snowflake-telemetry-python/.venv/lib/python3.11/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py:88 -> 2.3MiB | ||
- _encode_resource_logs:/Users/jopel/workspace/snowflake-telemetry-python/.venv/lib/python3.11/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py:82 -> 865.0KiB | ||
- _encode_resource_logs:/Users/jopel/workspace/snowflake-telemetry-python/.venv/lib/python3.11/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py:74 -> 34.4KiB | ||
- _encode_log:/Users/jopel/workspace/snowflake-telemetry-python/.venv/lib/python3.11/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py:58 -> 646.0B | ||
Allocation results for benchmark/benchmark_memory.py::test_encode_logs at the high watermark | ||
📦 Total memory allocated: 2.0MiB | ||
📏 Total allocations: 7 | ||
📊 Histogram of allocation sizes: |▅ ▂█| | ||
🥇 Biggest allocating functions: | ||
- __iter__:<frozen _collections_abc>:861 -> 1.0MiB | ||
- serialize_message:/Users/jopel/workspace/snowflake-telemetry-python/.venv/lib/python3.11/site-packages/snowflake/telemetry/_internal/serialize/__init__.py:95 -> 488.5KiB | ||
- serialize_bytes:/Users/jopel/workspace/snowflake-telemetry-python/.venv/lib/python3.11/site-packages/snowflake/telemetry/_internal/serialize/__init__.py:75 -> 367.1KiB | ||
- serialize_message:/Users/jopel/workspace/snowflake-telemetry-python/.venv/lib/python3.11/site-packages/snowflake/telemetry/_internal/serialize/__init__.py:95 -> 162.2KiB | ||
- _encode_log:/Users/jopel/workspace/snowflake-telemetry-python/.venv/lib/python3.11/site-packages/snowflake/telemetry/_internal/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py:56 -> 646.0B | ||
""" | ||
|
||
logs_data = [] | ||
for _ in range(1000): | ||
logs_data.extend(get_logs_data()) | ||
|
||
def test_encode_logs(): | ||
encode_logs(logs_data) | ||
|
||
def test_pb2_encode_logs(): | ||
pb2_encode_logs(logs_data).SerializeToString() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import google_benchmark as benchmark | ||
|
||
from util import get_logs_data, get_metrics_data, get_traces_data | ||
|
||
from snowflake.telemetry._internal.opentelemetry.exporter.otlp.proto.common._log_encoder import encode_logs | ||
from snowflake.telemetry._internal.opentelemetry.exporter.otlp.proto.common.metrics_encoder import encode_metrics | ||
from snowflake.telemetry._internal.opentelemetry.exporter.otlp.proto.common.trace_encoder import encode_spans | ||
|
||
from opentelemetry.exporter.otlp.proto.common._log_encoder import encode_logs as pb2_encode_logs | ||
from opentelemetry.exporter.otlp.proto.common.metrics_encoder import encode_metrics as pb2_encode_metrics | ||
from opentelemetry.exporter.otlp.proto.common.trace_encoder import encode_spans as pb2_encode_spans | ||
|
||
""" | ||
----------------------------------------------------------------------------- | ||
Benchmark Time CPU Iterations | ||
----------------------------------------------------------------------------- | ||
test_bm_serialize_logs_data 78590 ns 78590 ns 8893 | ||
test_bm_pb2_serialize_logs_data 96043 ns 96043 ns 7277 | ||
test_bm_serialize_metrics_data 132482 ns 132482 ns 5285 | ||
test_bm_pb2_serialize_metrics_data 163929 ns 163931 ns 4270 | ||
test_bm_serialize_traces_data 103523 ns 103524 ns 6656 | ||
test_bm_pb2_serialize_traces_data 132048 ns 132048 ns 5294 | ||
""" | ||
|
||
def sanity_check(): | ||
logs_data = get_logs_data() | ||
metrics_data = get_metrics_data() | ||
traces_data = get_traces_data() | ||
|
||
assert encode_logs(logs_data) == pb2_encode_logs(logs_data).SerializeToString() | ||
assert encode_metrics(metrics_data) == pb2_encode_metrics(metrics_data).SerializeToString() | ||
assert encode_spans(traces_data) == pb2_encode_spans(traces_data).SerializeToString() | ||
|
||
@benchmark.register | ||
def test_bm_serialize_logs_data(state): | ||
logs_data = get_logs_data() | ||
while state: | ||
encode_logs(logs_data) | ||
|
||
@benchmark.register | ||
def test_bm_pb2_serialize_logs_data(state): | ||
logs_data = get_logs_data() | ||
while state: | ||
pb2_encode_logs(logs_data).SerializeToString() | ||
|
||
@benchmark.register | ||
def test_bm_serialize_metrics_data(state): | ||
metrics_data = get_metrics_data() | ||
while state: | ||
encode_metrics(metrics_data) | ||
|
||
@benchmark.register | ||
def test_bm_pb2_serialize_metrics_data(state): | ||
metrics_data = get_metrics_data() | ||
while state: | ||
pb2_encode_metrics(metrics_data).SerializeToString() | ||
|
||
@benchmark.register | ||
def test_bm_serialize_traces_data(state): | ||
traces_data = get_traces_data() | ||
while state: | ||
encode_spans(traces_data) | ||
|
||
@benchmark.register | ||
def test_bm_pb2_serialize_traces_data(state): | ||
traces_data = get_traces_data() | ||
while state: | ||
pb2_encode_spans(traces_data).SerializeToString() | ||
|
||
if __name__ == "__main__": | ||
sanity_check() | ||
benchmark.main() |
Oops, something went wrong.