perf: Resolves 100% CPU Database spike with User Listing and Dashboard load times#673
Open
retho-p wants to merge 2 commits intolirantal:masterfrom
Open
perf: Resolves 100% CPU Database spike with User Listing and Dashboard load times#673retho-p wants to merge 2 commits intolirantal:masterfrom
retho-p wants to merge 2 commits intolirantal:masterfrom
Conversation
- Refactored `mng-list-all.php` to decouple `radacct` from the base counting queries, preventing catastrophic Cartesian joins when calculating pagination. - Replaced the heavy base query with a fast uncorrelated subquery fetching `lastlogin`. - Introduced `contrib/db/update-performance-indexes.sql`, a fully idempotent migration script to deploy essential Covering Indexes for heavily aggregated tables. - Appended foundational performance indexes directly to the `mariadb-daloradius.sql` schema so new installations obtain them automatically. - Resolves severe MySQL 100% CPU spikes and multi-minute page hangs when scaling to >10,000 users and millions of accounting records.
Collaborator
Author
|
This PR will fix #634 also |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
This PR introduces vital database index definitions and refactors the underlying PHP logic to stabilize performance for large deployments.
Previously, instances with active accounting enabled and thousands of users (e.g., resulting in ~1,000,000+ rows in
radacct) experienced cascading, multi-minute UI hangs on the List Users and Dashboard pages. MySQL would hit 100% CPU while trying to perform full table scans across massive datasets just to configure pagination or calculate dashboard aggregations (Top 10 users last month, Currently Online, etc).Key Fixes
PHP Decoupling (
app/operators/mng-list-all.php):The
LEFT JOINtoradacctwas removed from the core session table structure. The row-count function now scales effortlessly, andlastlogintimestamps are queried independently post-LIMIT, significantly reducing memory consumption during$res->numRows().Dashboard Covering Indexes:
The MySQL schema now builds composite B-Tree indexes specifically targeting heavy dashboard OLAP queries. Operations that previously executed a
filesortover a million raw rows now resolve directly in RAM via index lookups.Idempotent Update Script:
Migrated systems will not encounter index collision errors. A robust stored-procedure update script ensures safe deployments in automated pipelines.
Testing & Verification
✅ Load tested successfully
The failure scenario was explicitly replicated in an isolated test environment by generating 10,000 mock users and scaling to 1,000,000
radacctsession records to emulate a long-running production system.Before the fix:
Accessing the endpoint triggered a massive CPU spike, locking MySQL at 100% and causing the UI to hang for several minutes.
After the fix:
Using the same dataset, the page renders in milliseconds.
🚀 Release Notes for Production Environments
If you are running an existing production instance of daloRADIUS, applying this update will resolve dashboard and user listing slowdowns.
Because new standard indexes were introduced to the SQL schema, you must update your existing database for the changes to take full effect. A fully safe, idempotent migration script is provided and can be executed on a live system without risk of data loss or index conflicts.
Apply the update
Note:
Please ensure you have a full backup of your environment and database before applying this update.
Depending on the size of your radacct table, this operation may take between 5–30 seconds. The system can remain online during execution.