Reuse reset MySQL connections per worker

This commit is contained in:
udo
2026-07-16 17:00:28 +00:00
parent b04ce3d005
commit 6a02c07bcb
11 changed files with 185 additions and 10 deletions
+16 -1
View File
@@ -8,7 +8,7 @@
// actual close at request end, including exception/fatal recovery paths.
static void mysql_register_request_connection(MySQL* db)
{
if(!context || !db)
if(!context || !db || db->worker_persistent)
return;
auto& connections = context->resources.mysql_connections;
if(std::find(connections.begin(), connections.end(), (void*)db) == connections.end())
@@ -57,6 +57,21 @@ bool MySQL::connect(String host, String username, String password)
return(true);
}
bool MySQL::reset_connection()
{
if(!connection || mysql_reset_connection((MYSQL*)connection) != 0)
return(false);
_preload_next_error_code = 0;
affected_rows = 0;
field_count = 0;
row_count = 0;
insert_id = 0;
statement_info = "reset";
field_info.clear();
request_leases = 0;
return(true);
}
String MySQL::escape(String raw, char quote_char)
{
return(mysql_escape(raw, quote_char));
+2
View File
@@ -22,6 +22,7 @@ struct MySQL {
String statement_info = ""; //
bool request_cleanup_delete = false;
bool request_pooled = false;
bool worker_persistent = false;
u32 request_leases = 0;
String request_host;
String request_username;
@@ -30,6 +31,7 @@ struct MySQL {
std::vector<MySQLFieldInfo> field_info;
bool connect(String host = "localhost", String username = "root", String password = "");
bool reset_connection();
void disconnect();
String error();
String escape(String raw, char quote_char = '\'');