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

Optimize the spotlight_cache implementation #532

Closed
1 of 4 tasks
nullpointer0x00 opened this issue Aug 20, 2024 · 1 comment · Fixed by #559
Closed
1 of 4 tasks

Optimize the spotlight_cache implementation #532

nullpointer0x00 opened this issue Aug 20, 2024 · 1 comment · Fixed by #559

Comments

@nullpointer0x00
Copy link
Contributor

Summary

Optimize the spotlight_cache implementation by replacing the current database storage approach with an in-memory synchronized singleton to improve performance and reduce database load.

Problem Definition

The current implementation of the spotlight_cache involves a scheduled job that runs every 5 seconds, inserting a new record into the spotlight_cache table each time. The corresponding endpoint retrieves and serves only the most recent record, meaning the historical data is not being utilized.

This approach is inefficient for several reasons:

  • The database currently holds around 18 million rows, taking up 15GB of space on mainnet.
  • Every time the endpoint is called, a database query is made, which could be avoided if the latest spotlight data was stored in memory.
  • The current implementation results in unnecessary storage use and increased database load, slowing down the system.

Proposal

  • Replace the current implementation that inserts records into the spotlight_cache table with an in-memory synchronized singleton that stores only the most recent spotlight data.
  • Before removing the spotlight_cache table from the database, confirm that the history of this data is not being utilized by any other part of the system.
  • Implement the necessary logic to replace the old spotlight data in memory with the latest, avoiding the creation of new database records.
  • The expected improvements include:
    • Reduced calls to the database for every endpoint request.
    • Faster access to the spotlight data since it will be retrieved from memory.
    • Significant space savings by removing the large and growing spotlight_cache table from the database.

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@nullpointer0x00
Copy link
Contributor Author

I decided to go with an in memory cache. This will remove the need to store records in the database.

I will drop the whole database table in a different PR.

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 a pull request may close this issue.

1 participant