MaxScale Multiplexing and Caching – Part 4

Part 4 – Tuning MaxScale for Real Workloads

This multi-part series breaks down each section into easy logical steps.

Part 1 – Complete Guide for High-Concurrency Workloads

Part 2 – Understanding MaxScale Thread Architecture

Part 3 – Backend Sizing and Connection Pooling

Part 4 – Tuning MaxScale for Real Workloads

Part 5 – MaxScale Multiplexing

Part 6 – MaxScale Caching

Part 7 – Warnings & Caveats

Part 8 – Key Takeaways


Tuning MaxScale ensures it efficiently handles the expected workload while minimizing latency and resource consumption. Each parameter impacts how client connections are routed, processed, and pooled.

VariableDescriptionRecommendation / Tuning Guidance
threadsNumber of worker threads handling client connectionsAlign with number of CPU cores (or v-cores) to avoid contention. (MariaDB)
router_optionsOptions for routing logic (e.g., read/write split)Enable when using read/write split; ensures queries route correctly. (MariaDB)
max_sescmd_historyHow many session state–modifying commands (e.g., SET ...) MaxScale keeps in its historyDefault is 50, but increase if your application does many state commands or uses many prepared statements. (MariaDB)
prune_sescmd_historyWhether to prune session command history when it exceeds max_sescmd_historyLeave true (default) in many cases — it reduces memory use but still allows reconnections. (MariaDB)
multiplex_timeoutWhen multiplexing, how long a client waits for a pooled backend connectionDefault is 60 s; increase if clients are timing out waiting for a shared connection. (MariaDB)
idle_session_pool_timeHow long a session must be idle before its backend connections can be pooled for reuseDefault -1s (pooling disabled). To enable connection sharing, set to 0ms or more. Be mindful: reusing connections needs session replay (sescmd history). (MariaDB)
persistpoolmaxMaximum number of pooled backend connections per routing threadSet this based on expected concurrency. If using connection sharing, ensure this is large enough to hold idle connections. (MariaDB)
persistmaxtimeHow long to keep an unused (pooled) backend connection alive before closing itDefault is 0s (disabled). Tune to balance keeping connections for reuse vs freeing idle ones. (MariaDB)
wait_timeoutIdle timeout for client sessions (MaxScale will drop them)Default is 28800s (8 hours) in recent MaxScale versions. Lower it if you want MaxScale to close idle sessions earlier than the backend. (MariaDB)
net_write_timeoutMaximum duration a write to a client can stay buffered before closing the connectionDefault 0s (disabled). Useful if client network is slow and you want to avoid unbounded buffering. (MariaDB)
query_classifier_cache_sizeMax memory for MaxScale’s internal query-classifier cacheIncrease this if you have many unique SQL statement patterns. Defaults to ~15% of system memory. (MariaDB)

Additional Tuning Tips:

  • Start with these baseline values, then monitor MaxScale metrics (threads, connection pool usage, query latency).
  • Use idle_session_pool_time to control how long idle connections are kept for reuse, balancing reuse vs. backend saturation.
  • Adjust backend connections (persistpoolmax) per thread based on expected concurrency and server resources.

Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7 | Page 8

Kester Riley

Kester Riley is a Global Solutions Engineering Leader who leverages his website to establish his brand and build strong business relationships. Through his blog posts, Kester shares his expertise as a consultant, mentor, trainer, and presenter, providing innovative ideas and code examples to empower ambitious professionals.

backend connection reuse (1) backend sizing (1) best practices (1) caching (1) caching caveats (1) caching strategy (1) CentOS (15) concurrency (1) connection multiplexing (1) connection pooling (2) Connector (5) Cooperative Monitoring (3) CPU cores (1) database benchmarking (1) database proxy risks (1) diff router (5) High Availability (13) high concurrency (2) high concurrency databases (1) idle_session_pool_time (1) Java (3) load testing (1) MariaDB (27) MaxScale (29) MaxScale configuration (1) MaxScale multiplex_timeout (1) MaxScale threads (1) multi-threading (1) multiplexing (2) multiplex_timeout (1) OLTP (1) Performance Optimization (2) performance testing (1) performance tuning (2) performance tuning checklist (1) persistmaxtime (1) persistpoolmax (1) Python (2) Replica Rebuild (10) Rocky Linux (15) session sharing (1) Sysbench (1) thread architecture (1) tuning (1) upgrade (5)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.