-
Notifications
You must be signed in to change notification settings - Fork 153
perf: Major performance optimizations - memory leak fix, SQLite tuning, and cache improvements #903
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
base: main
Are you sure you want to change the base?
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||
|
|
||
| await dataContext.SaveChangesAsync(); | ||
|
|
||
| await TorrentData.VoidCache(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the cache is managed automatically, it empties itself.
So I didn't find any use in forcing it to empty.
User description
This PR addresses critical performance issues causing high RAM consumption and database errors during concurrent downloads
Key Changes:
PR Type
Enhancement
Description
Remove aggressive cache invalidation calls (13 locations) causing cache thrashing
Fix memory leak in WebsocketsUpdater by properly disposing DbContext scopes
Add adaptive WebSocket polling interval (1s active, 5s idle) reducing CPU usage
Configure SQLite with WAL mode, connection pooling, and optimized PRAGMAs
Add AsSplitQuery() optimization for more efficient database queries
Diagram Walkthrough
File Walkthrough
DownloadData.cs
Remove aggressive cache invalidation callsserver/RdtClient.Data/Data/DownloadData.cs
TorrentData.VoidCache()calls from downloadupdate methods
UpdateFileName, UpdateDownloadStarted, UpdateDownloadFinished,
UpdateUnpackingQueued, UpdateUnpackingStarted,
UpdateUnpackingFinished, UpdateCompleted, UpdateError,
UpdateRetryCount, DeleteForTorrent, and Reset operations
operations
TorrentData.cs
Add AsSplitQuery optimization for queriesserver/RdtClient.Data/Data/TorrentData.cs
.AsSplitQuery()to the torrent retrieval queryentities
DiConfig.cs
Configure SQLite connection pooling and cachingserver/RdtClient.Data/DiConfig.cs
Cache=Shared;Pooling=True;Command Timeout=30parametershandling
Startup.cs
Configure SQLite WAL mode and PRAGMAsserver/RdtClient.Service/BackgroundServices/Startup.cs
journal_mode=WAL,synchronous=NORMAL,busy_timeout=5000,and
cache_size=-64000WebsocketsUpdater.cs
Fix scope leak and add adaptive pollingserver/RdtClient.Service/BackgroundServices/WebsocketsUpdater.cs
with
usingstatementseconds when idle
each iteration