Skip to content

Prevent unnecessary VACUUM executions for SQLite3 stats database - Closes #4856#4859

Merged
renecannao merged 4 commits intov3.0from
v3.0-4856
Mar 12, 2025
Merged

Prevent unnecessary VACUUM executions for SQLite3 stats database - Closes #4856#4859
renecannao merged 4 commits intov3.0from
v3.0-4856

Conversation

@JavierJF
Copy link
Collaborator

@JavierJF JavierJF commented Mar 8, 2025

Description / Main work

This PR introduces a generic approach for performing VACUUM operations over stats database, performing them only when these operations could result in space optimization for the database. The PR also introduces other optimization, substituting simple query executions with prepared statements for SQLite. These optimizations alone should be enough to solve the increase on CPU usage that was affecting test reg_test_3765_ssl_pollout-t, described in issue #4828, other changes required in that issue description are also included in this PR.

The load used for getting the perf data was just a loop of the query SELECT Variable_Name, Variable_Value FROM stats_mysql_global. After the two main optimizations introduced, we can see how perf report has changed:

original:

-   94.28%     0.02%  Admin            proxysql              [.] void admin_session_handler<MySQL_Session>(MySQL_Session*, void*, _PtrSize_t*)
   - 94.26% void admin_session_handler<MySQL_Session>(MySQL_Session*, void*, _PtrSize_t*)
      + 45.66% ProxySQL_Admin::vacuum_stats(bool)
      - 34.65% SQLite3DB::execute_statement(char const*, char**, int*, int*, SQLite3_result**)
         + 33.72% sqlite3_prepare_v2
         + 0.93% SQLite3_result::SQLite3_result(sqlite3_stmt*)
      + 13.39% ProxySQL_Admin::GenericRefreshStatistics(char const*, unsigned int, bool)

patched:

-   84.69%     0.05%  Admin            proxysql              [.] void admin_session_handler<MySQL_Session>(MySQL_Session*, void*, _PtrSize_t*)                                                                                                                                             
   - 84.63% void admin_session_handler<MySQL_Session>(MySQL_Session*, void*, _PtrSize_t*)                                                                                                                                                                                                  
      + 63.83% ProxySQL_Admin::GenericRefreshStatistics(char const*, unsigned int, bool)                                                                                                                                                                                                   
      - 13.67% SQLite3DB::execute_statement(char const*, char**, int*, int*, SQLite3_result**)                                                                                                                                                                                             
         + 12.34% SQLite3_result::SQLite3_result(sqlite3_stmt*)                                                                                                                                                                                                                            
         + 1.24% sqlite3_prepare_v2                                                                                                                                                                                                                                                        
      + 3.86% SQLite3_result::~SQLite3_result()                                                                                                                                                                                                                                            
      + 2.77% MySQL_Session::SQLite3_to_MySQL(SQLite3_result*, char*, int, MySQL_Protocol*, bool, bool)

These optimizations are enough to keep most of the CPU time on the actual query result computation.

JavierJF added 2 commits March 8, 2025 15:17
Introduced generic approach based on the potential benefits for 'VACUUM'
over the 'stats' database instead of the previous selective, table
based, approach.
Measurements ('perf') revealed that 'prepare' from 'execute' where
taking roughtly half the execution time of the queries used for table
generation.
@renecannao renecannao merged commit a9bdf54 into v3.0 Mar 12, 2025
6 of 7 checks passed
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