-
Notifications
You must be signed in to change notification settings - Fork 2
Performance Tuning
Maximize agent throughput with Code Mode token savings, connection pool tuning, and sysschema diagnostics.
The mysql2 connection pool configuration directly impacts concurrent tool execution.
| Parameter | Default | CLI | Environment Variable | Effect |
|---|---|---|---|---|
connectionLimit |
10 | --pool-size |
MYSQL_POOL_SIZE |
Max simultaneous connections |
acquireTimeout |
configurable connection timeout | --pool-timeout |
MYSQL_POOL_TIMEOUT |
How long to wait for a free connection |
queueLimit |
0 (∞) | --pool-queue-limit |
MYSQL_POOL_QUEUE_LIMIT |
Max requests waiting in queue |
- stdio (single agent): Default 10 works well. AI agents usually issue queries sequentially.
-
Streamable HTTP (multiple agents): Increase to 20–50. Each tool call needs a connection. Monitor for
acquireTimeouterrors. - Short-lived queries: If your workload is mostly reads, a pool of 10–15 handles high throughput because connections are returned quickly.
- Long-running analytics: Increase the pool for complex aggregations holding connections. Consider using Code Mode. It batches work into a single connection.
Exposing all tools to an LLM increases the system prompt payload. This costs more tokens and slows response time.
The --tool-filter CLI flag selectively mounts only needed tools.
Avoid mounting all tools, as it incurs high latency and token costs. Use presets like starter or dba-monitor to streamline the agent's context.
# Mount only the tools your agent needs
npx -y @neverinfamous/mysql-mcp --tool-filter starterSee Tool Filtering for the complete list of groups and shortcuts.
Code Mode (mysql_execute_code) provides significant token savings over individual tool calls.
-
Single-step retrieval: "Get the schema for the
userstable." - Simple lookups: "Search for 'payment failed' in the logs."
- Low latency per step: Tool calls are fast. Multi-step reasoning requires multiple LLM roundtrips.
- Multi-step data pipelines: Query tables and process results in JavaScript.
- Token efficiency: Up to 90% token savings. The script returns only the final answer.
- Performance: Eliminates network latency of multi-step reasoning loops. The script runs in a V8 isolate.
- High Efficiency: Batching complex data pipelines reduces token usage and overhead.
Rule of Thumb: Use Code Mode if a question requires more than two sequential queries.
We include dedicated tools for diagnosing slow queries and optimizing execution plans.
| Tool | Purpose |
|---|---|
mysql_explain |
Analyze query execution plans (EXPLAIN / EXPLAIN ANALYZE) |
mysql_slow_queries |
Identify and analyze slow queries from the performance schema |
mysql_optimizer_trace |
Trace optimizer decisions for a specific query |
mysql_index_recommendation |
Suggest missing indexes based on query patterns. Supports database-wide audits |
mysql_buffer_pool_stats |
Monitor InnoDB buffer pool hit rates and memory usage |
mysql_sys_* |
Expose MySQL sysschema diagnostics (redundant indexes, unused indexes, statement analysis) |
-
Identify slow queries via
mysql_slow_queriesormysql_sys_statement_summary. -
Analyze the plan with the
mysql_explaintool for actual execution metrics. -
Check for missing indexes with
mysql_index_recommendation. -
Verify improvements by re-running
mysql_explainafter adding indexes.
| Setting | Recommendation | Tool to Monitor |
|---|---|---|
innodb_buffer_pool_size |
70–80% of available RAM on dedicated servers | mysql_buffer_pool_stats |
innodb_flush_log_at_trx_commit |
1 for durability, 2 for throughput (risk: 1s data loss on crash) |
mysql_show_variables |
innodb_log_file_size |
Large enough to hold 1–2 hours of writes | mysql_show_status |
| Buffer pool hit rate | Target ≥99% | mysql_buffer_pool_stats |
Note: Tune these server-level settings in your MySQL configuration file or via
SET GLOBAL.
Connection pool metrics, system latency, and active sessions can be monitored in real-time via the Prometheus /metrics endpoint and visualized in the Grafana dashboard.
Our benchmarks confirm microsecond-level overhead on critical paths:
| Area | Key Metric | Notes |
|---|---|---|
| Tool dispatch | High-throughput O(1) hash resolution | O(1) hash-based tool resolution |
| Schema validation | Sub-millisecond validation | Depends on schema complexity |
| Token estimation | Sub-millisecond validation | Content-type-aware |
| Code Mode sandbox init | Optimized cold start | isolated-vm cold start |
| Logger | High-throughput | Zero work when below minLevel
|
Run pnpm run bench locally for full results on your hardware.
Note: Zod schemas are defined statically for instant boot times.
Unlock autonomous database orchestration with an enterprise-grade MySQL MCP server. Featuring blazing-fast sandboxed Code Mode, uncompromising schema enforcement, and seamless ecosystem integrations to power secure, intelligent AI workflows.
- Installation
- Configuration
- Architecture
- HTTP Transport
- Tool Filtering
- Code Mode
- Tools
- Prompts
- Resources
- Observability & Telemetry