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

ref(spans): Write payloads outside of eval #88453

Merged
merged 8 commits into from
Apr 2, 2025

Conversation

jan-auer
Copy link
Member

@jan-auer jan-auer commented Apr 1, 2025

Based on our timings and monitoring, we notice a lot of the CPU load in Redis comes from the large pipeline that runs the add-buffer.lua script. It combines three bad aspects: Sends large payloads, runs many commands, and executes in a long, batched pipeline.

To understand and isolate its impact better, this PR splits the large script into two phases:

  1. Push payloads into Redis using SADD under the top-most parent key determined by the current in-memory batch.
  2. Run the pipelined script to restructure the partial trees

Additionally, this PR contains a few optimizations:

  • Avoid redundant set merges (SUNIONSTORE) when there's no subsegment to merge
  • Use UNLINK to defer large blocking deletes
  • Use EVALSHA to speed up script invocation

This prepares for batched calls to the script, which should result in even fewer writes.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 1, 2025
Copy link

codecov bot commented Apr 2, 2025

Codecov Report

Attention: Patch coverage is 96.66667% with 2 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/spans/buffer.py 96.66% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #88453       +/-   ##
===========================================
+ Coverage   33.08%   87.74%   +54.65%     
===========================================
  Files        8464    10015     +1551     
  Lines      472987   567419    +94432     
  Branches    22294    22247       -47     
===========================================
+ Hits       156477   497860   +341383     
+ Misses     316090    69141   -246949     
+ Partials      420      418        -2     

@jan-auer jan-auer marked this pull request as ready for review April 2, 2025 13:47
@jan-auer jan-auer requested a review from a team as a code owner April 2, 2025 13:47
* master: (96 commits)
  fix(autofix): fix highlight popup behavior (#88552)
  🔧 chore: introduce workflow engine ui links ff (#88569)
  feat(pipeline): Add CoveragePageWrapper component and tests for it (#88519)
  feat(taskworker):Make sdk tasks taskworker compatible (#88488)
  chore(flamegraph): Updating wording to trace (#88516)
  feat(shared-views): Create `GET` `group-search-view/starred` endpoint (#88398)
  DI-612: print flaky pytest errors to log (v2) (#88512)
  chore(nav): Update banner copy (#88566)
  feat(sentryapps): add RPC method to get all installation component contents (#88179)
  chore(issue summary): Add limit to query (#88563)
  fix(dashboards): Add limit suggestion to validation (#88436)
  feat(checkout): show starting PAYG prices (#88510)
  ✨ feat(aci): add workflow_id when creating an ephemeral rule in noa (#88520)
  fix(billing): hide pay now button for self serve partners (#88504)
  chore(HC): Re-adds logging with a low sample rate for cache hits/misses on options (#88464)
  fix(logs): Upgrade sentry log integration to fix dogfooding issues (#88561)
  chore(issue summary): Remove dividers from AI summary alert (#88554)
  feat(insights): Enable bubbles in full-screen mode (#88445)
  fix(explore): Update search bar query on filter change (#88473)
  chore(dependencies): Upgrade drf-spectacular (#88459)
  ...
@untitaker untitaker merged commit 89c00d5 into master Apr 2, 2025
47 checks passed
@untitaker untitaker deleted the ref/spans-separate-payload branch April 2, 2025 18:37
@jan-auer jan-auer added the Trigger: Revert Add to a merged PR to revert it (skips CI) label Apr 3, 2025
@getsentry-bot
Copy link
Contributor

PR reverted: de9a709

getsentry-bot added a commit that referenced this pull request Apr 3, 2025
@jan-auer jan-auer restored the ref/spans-separate-payload branch April 3, 2025 07:32
untitaker added a commit that referenced this pull request Apr 3, 2025
Based on our timings and monitoring, we notice a lot of the CPU load in
Redis comes from the large pipeline that runs the `add-buffer.lua`
script. It combines three bad aspects: Sends large payloads, runs many
commands, and executes in a long, batched pipeline.

To reduce the time Redis is blocked on slow operations, this PR splits
the large script into two phases:
1. Push payloads into Redis using `SADD` under the top-most parent key
determined by the current in-memory batch.
2. Run the pipelined script to restructure the partial trees

Additionally, this PR contains a few optimizations:
- Avoid redundant set merges (`SUNIONSTORE`) when there's no subsegment
to merge
- Use `UNLINK` to defer large blocking deletes
- Use `EVALSHA` to speed up script invocation 

This prepares for batched calls to the script, which should result in
even fewer writes.

Second attempt of #88453

---------

Co-authored-by: Markus Unterwaditzer <[email protected]>
adrian-codecov pushed a commit that referenced this pull request Apr 3, 2025
adrian-codecov pushed a commit that referenced this pull request Apr 3, 2025
Based on our timings and monitoring, we notice a lot of the CPU load in
Redis comes from the large pipeline that runs the `add-buffer.lua`
script. It combines three bad aspects: Sends large payloads, runs many
commands, and executes in a long, batched pipeline.

To reduce the time Redis is blocked on slow operations, this PR splits
the large script into two phases:
1. Push payloads into Redis using `SADD` under the top-most parent key
determined by the current in-memory batch.
2. Run the pipelined script to restructure the partial trees

Additionally, this PR contains a few optimizations:
- Avoid redundant set merges (`SUNIONSTORE`) when there's no subsegment
to merge
- Use `UNLINK` to defer large blocking deletes
- Use `EVALSHA` to speed up script invocation 

This prepares for batched calls to the script, which should result in
even fewer writes.

Second attempt of #88453

---------

Co-authored-by: Markus Unterwaditzer <[email protected]>
andrewshie-sentry pushed a commit that referenced this pull request Apr 8, 2025
Based on our timings and monitoring, we notice a lot of the CPU load in
Redis comes from the large pipeline that runs the `add-buffer.lua`
script. It combines three bad aspects: Sends large payloads, runs many
commands, and executes in a long, batched pipeline.

To understand and isolate its impact better, this PR splits the large
script into two phases:
1. Push payloads into Redis using `SADD` under the top-most parent key
determined by the current in-memory batch.
2. Run the pipelined script to restructure the partial trees

Additionally, this PR contains a few optimizations:
- Avoid redundant set merges (`SUNIONSTORE`) when there's no subsegment
to merge
- Use `UNLINK` to defer large blocking deletes
- Use `EVALSHA` to speed up script invocation 

This prepares for batched calls to the script, which should result in
even fewer writes.
andrewshie-sentry pushed a commit that referenced this pull request Apr 8, 2025
andrewshie-sentry pushed a commit that referenced this pull request Apr 8, 2025
Based on our timings and monitoring, we notice a lot of the CPU load in
Redis comes from the large pipeline that runs the `add-buffer.lua`
script. It combines three bad aspects: Sends large payloads, runs many
commands, and executes in a long, batched pipeline.

To reduce the time Redis is blocked on slow operations, this PR splits
the large script into two phases:
1. Push payloads into Redis using `SADD` under the top-most parent key
determined by the current in-memory batch.
2. Run the pipelined script to restructure the partial trees

Additionally, this PR contains a few optimizations:
- Avoid redundant set merges (`SUNIONSTORE`) when there's no subsegment
to merge
- Use `UNLINK` to defer large blocking deletes
- Use `EVALSHA` to speed up script invocation 

This prepares for batched calls to the script, which should result in
even fewer writes.

Second attempt of #88453

---------

Co-authored-by: Markus Unterwaditzer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components Trigger: Revert Add to a merged PR to revert it (skips CI)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants