[statsd] Improve performance of telemetry serialization#641
Merged
Conversation
By precomputing the telemetry formatting string, we are able to gain 2-15% increase in throughput over the old code in both Python2 and Python3. Sample timing data: ``` $ ./time_flush.py Using Python3 _flush_telemetry_orig: 6.24254 (baseline) _flush_telemetry_new : 5.56866 (89.21%, 12.10% increase) _flush_telemetry_orig: 5.78443 (baseline) _flush_telemetry_new : 5.57556 (96.39%, 3.75% increase) $ ./time_flush.py Using Python2 _flush_telemetry_orig: 3.78670 (baseline) _flush_telemetry_new : 3.47990 (91.90%, 8.82% increase) _flush_telemetry_orig: 3.84288 (baseline) _flush_telemetry_new : 3.51469 (91.46%, 9.34% increase) ```
714ca87 to
55a8bd9
Compare
therve
reviewed
Mar 4, 2021
| @@ -559,16 +572,15 @@ def _reset_telemetry(self): | |||
|
|
|||
| def _flush_telemetry(self): | |||
| telemetry_tags = ",".join(self._add_constant_tags(self._client_tags)) | |||
Contributor
There was a problem hiding this comment.
Do you think we could potentially cache that as well, and then cache the resulting string ? So we end up only passing the numbers?
Contributor
Author
There was a problem hiding this comment.
Seems very reasonable and from a cursory look, I think we can precompute the stringified tags just like you said. Overall though it has been a bit quite a hit-or-miss for what seems like should improve the performance vs what actually gives better benchmarking results so I'll need to instrument it. For now I'm making tiny changes here-and-there in obvious places and as I get a bit more comfortable I'll see about these tags!
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
By precomputing the telemetry formatting string, we are able to gain
2-15% increase in throughput over the old code in both Python2 and
Python3.
Sample timing data:
Benchmark runner:
Description of the Change
Small optimization in string composition in a hot path that uses less CPU cycles
Alternate Designs
Experimented with various other ways to compose a string (
.format,.formatwith keyed data,StringIO, etc) - this one was the most performant.Possible Drawbacks
N/A
Verification Process
Tests already cover this functionality via unit tests
Additional Notes
Release Notes
Review checklist (to be filled by reviewers)
changelog/label attached. If applicable it should have thebackward-incompatiblelabel attached.do-not-merge/label attached.kind/andseverity/labels attached at least.