Summary
Problem
Based on v1.2.636-rc8.6 code, if I understand correctly, every new MySQL connection creates:
-
A dedicated OS thread
thread::spawn() is called for each incoming connection
- Thread creation/destruction overhead is significant under high concurrency
-
A dedicated Tokio runtime
|
let query_executor = |
|
Runtime::with_worker_threads(1, Some("mysql-query-executor".to_string()))?; |
Runtime::with_worker_threads(1, "mysql-query-executor") is created per connection
- Each runtime has its own thread pool and scheduler overhead
- Memory and CPU resources cannot be shared across connections
Impact (AI-generated)
- High memory consumption under concurrent connections
- Poor resource utilization due to isolated runtimes
- Potential resource exhaustion with many simultaneous connections
- Unnecessary thread context switching overhead
Suggested Solution (AI-generated)
- Use a shared Tokio runtime (or the global runtime) for all MySQL connections
- Replace
thread::spawn() with tokio::spawn() to leverage async task scheduling
- Consider using a connection pool or worker pool pattern for better resource management
Summary
Problem
Based on
v1.2.636-rc8.6code, if I understand correctly, every new MySQL connection creates:A dedicated OS thread
databend/src/query/service/src/servers/mysql/mysql_session.rs
Line 56 in f74b30b
thread::spawn()is called for each incoming connectionA dedicated Tokio runtime
databend/src/query/service/src/servers/mysql/mysql_session.rs
Lines 54 to 55 in f74b30b
Runtime::with_worker_threads(1, "mysql-query-executor")is created per connectionImpact (AI-generated)
Suggested Solution (AI-generated)
thread::spawn()withtokio::spawn()to leverage async task scheduling