Skip to content

perf(rc): improve performance of subprocess service sharing #13651

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

Merged
merged 12 commits into from
Jun 17, 2025

Conversation

brettlangdon
Copy link
Member

@brettlangdon brettlangdon commented Jun 11, 2025

This change will only write service names to the shared file queue only if we have not shared that service name yet.

This improvement avoids locking and writing to disk every time we call Pin.onto which can happen a lot when database connections are cycled/recreated frequently.

It also helps ensure that the same process doesn't continually write the same service name to the same file over and over again.

I also updated the tests to use subprocesses/forking as is expected with it's behavior for RC.

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

This change will only write service names to the shared file queue only if
we have not shared that service name yet.

This improvement avoids locking and writing to disk every time we call Pin.onto
which can happen a lot when database connections are cycled/recreated frequently.

It also helps ensure that the same process doesn't continually write the same service
name to the same file over and over again.
@brettlangdon brettlangdon added the changelog/no-changelog A changelog entry is not required for this PR. label Jun 11, 2025
@brettlangdon brettlangdon requested a review from a team as a code owner June 11, 2025 18:53
@brettlangdon brettlangdon requested a review from juanjux June 11, 2025 18:53
Copy link
Contributor

github-actions bot commented Jun 11, 2025

CODEOWNERS have been resolved as:

ddtrace/settings/_config.py                                             @DataDog/apm-core-python
tests/internal/service_name/test_extra_services_names.py                @DataDog/apm-core-python

Copy link
Contributor

github-actions bot commented Jun 11, 2025

Bootstrap import analysis

Comparison of import times between this PR and base.

Summary

The average import time from this PR is: 282 ± 5 ms.

The average import time from base is: 286 ± 7 ms.

The import time difference between this PR and base is: -3.4 ± 0.3 ms.

Import time breakdown

The following import paths have shrunk:

ddtrace.auto 2.075 ms (0.73%)
ddtrace.bootstrap.sitecustomize 1.390 ms (0.49%)
ddtrace.bootstrap.preload 1.390 ms (0.49%)
ddtrace.internal.remoteconfig.client 0.656 ms (0.23%)
ddtrace 0.685 ms (0.24%)
ddtrace.internal._unpatched 0.033 ms (0.01%)
json 0.033 ms (0.01%)
json.decoder 0.033 ms (0.01%)
re 0.033 ms (0.01%)
enum 0.033 ms (0.01%)
types 0.033 ms (0.01%)

@pr-commenter
Copy link

pr-commenter bot commented Jun 11, 2025

Benchmarks

Benchmark execution time: 2025-06-16 19:21:19

Comparing candidate commit 4848444 in PR branch brettlangdon/perf.extra_services with baseline commit 5692392 in branch main.

Found 0 performance improvements and 4 performance regressions! Performance is the same for 474 metrics, 2 unstable metrics.

scenario:iastaspectsospath-ospathnormcase_aspect

  • 🟥 execution_time [+344.743ns; +394.705ns] or [+9.928%; +11.367%]

scenario:iastaspectsospath-ospathsplit_aspect

  • 🟥 execution_time [+624.233ns; +807.635ns] or [+12.941%; +16.743%]

scenario:iastaspectsospath-ospathsplitdrive_aspect

  • 🟥 execution_time [+352.788ns; +403.078ns] or [+9.697%; +11.079%]

scenario:telemetryaddmetric-flush-1-metric

  • 🟥 execution_time [+305.681ns; +456.522ns] or [+7.378%; +11.018%]

@brettlangdon
Copy link
Member Author

I have to fix up the multiple_os_tests which use this test.

@juanjux juanjux merged commit b686305 into main Jun 17, 2025
811 of 812 checks passed
@juanjux juanjux deleted the brettlangdon/perf.extra_services branch June 17, 2025 09:14
github-actions bot pushed a commit that referenced this pull request Jun 17, 2025
This change will only write service names to the shared file queue only
if we have not shared that service name yet.

This improvement avoids locking and writing to disk every time we call
Pin.onto which can happen a lot when database connections are
cycled/recreated frequently.

It also helps ensure that the same process doesn't continually write the
same service name to the same file over and over again.

I also updated the tests to use subprocesses/forking as is expected with
it's behavior for RC.

## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)

(cherry picked from commit b686305)
brettlangdon added a commit that referenced this pull request Jun 18, 2025
… 3.9] (#13685)

Backport b686305 from #13651 to 3.9.

This change will only write service names to the shared file queue only
if we have not shared that service name yet.

This improvement avoids locking and writing to disk every time we call
Pin.onto which can happen a lot when database connections are
cycled/recreated frequently.

It also helps ensure that the same process doesn't continually write the
same service name to the same file over and over again.

I also updated the tests to use subprocesses/forking as is expected with
it's behavior for RC.

## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)

Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com>
Co-authored-by: Christophe Papazian <114495376+christophe-papazian@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog A changelog entry is not required for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants