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

Darren/feat/add subscription cache #866

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

darrenvechain
Copy link
Member

Description

This PR leverages an LRU cache for beat, beat2 and block subscription endpoints. It generates the messages, marshals them and caches the bytes against thor block ID.

This improves CPU performance a lot when:

  • There are a high amount of transactions, eg 90% gas utilization
  • There are high number of beat/ beat2 websocket connections

How Has This Been Tested?

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • New and existing E2E tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have not added any vulnerable dependencies to my code

@darrenvechain darrenvechain requested a review from a team as a code owner October 21, 2024 08:54
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 72.64957% with 32 lines in your changes missing coverage. Please review.

Project coverage is 60.57%. Comparing base (a0e5a44) to head (8f752a7).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
api/subscriptions/message_cache.go 55.88% 10 Missing and 5 partials ⚠️
api/subscriptions/beat_reader.go 85.71% 3 Missing and 1 partial ⚠️
api/subscriptions/beat2_reader.go 88.00% 2 Missing and 1 partial ⚠️
api/subscriptions/block_reader.go 75.00% 2 Missing and 1 partial ⚠️
api/subscriptions/event_reader.go 57.14% 2 Missing and 1 partial ⚠️
api/subscriptions/transfer_reader.go 57.14% 2 Missing and 1 partial ⚠️
api/subscriptions/subscriptions.go 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #866      +/-   ##
==========================================
- Coverage   62.63%   60.57%   -2.06%     
==========================================
  Files         209      210       +1     
  Lines       18952    22498    +3546     
==========================================
+ Hits        11870    13628    +1758     
- Misses       5982     7760    +1778     
- Partials     1100     1110      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

cacheSize = 1
}
cache, err := lru.New(int(cacheSize))
if err != nil {
Copy link
Member Author

@darrenvechain darrenvechain Oct 21, 2024

Choose a reason for hiding this comment

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

TODO: Can we handle this more gracefully? Currently subscriptions.New nor api.New return errors, so this would mess up the flow a little bit

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

Successfully merging this pull request may close these issues.

2 participants