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

fix: optimize sql query used for the signer_state_count metric #73

Merged
merged 1 commit into from
Mar 3, 2025

Conversation

zone117x
Copy link
Member

@zone117x zone117x commented Mar 3, 2025

Closes #72

The sql query used for the signer_state_count prometheus metric was taking several minutes. This PR reduces it down to less than 1000ms, even for bucket ranges in the thousands.

The main problem was caused by the size of the block_responses table, which is ~16 million rows. This is too slow to query using only (block_hash, signer_key), even with an optimal composite index and query planner hinting.

The solution in this PR is simple: first filter for the latest N block_responses responses using a fast receive_at timestamp comparison. A buffer time of 1 hour is used in the filter to account for timing discrepancies between block_proposal and block_response receipt times.

Copy link

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Copy link
Collaborator

@rafaelcr rafaelcr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Genius 🧠

@zone117x zone117x merged commit 6394e58 into main Mar 3, 2025
5 of 6 checks passed
@zone117x zone117x deleted the fix/prom-metrics-optimizations branch March 3, 2025 22:53
blockstack-devops pushed a commit that referenced this pull request Mar 3, 2025
## [0.12.7](v0.12.6...v0.12.7) (2025-03-03)

### Bug Fixes

* optimize sql query used for the `signer_state_count` metric ([#73](#73)) ([6394e58](6394e58))
@blockstack-devops
Copy link

🎉 This PR is included in version 0.12.7 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

/metrics endpoint slow
3 participants