Many clients at once
How the MySQL port behaved from 10 to 2,000 connected clients on a 16-core machine while the source took 400 writes a second, and how to size for your own load.
On a 16-core machine, once every worker was busy, the copy answered about 24 heavy queries a second, with 50 clients connected or with 2,000. Lookups by key went to MySQL and took 1.1 to 1.8 ms at every step, straight to the port. Past the ceiling nothing failed: heavy queries waited their turn, in the order they arrived.
These are the numbers of one test setup, described below. Your queries, tables and machine give other numbers. The shape of the curves is what carries over, and How to size for your load shows how to work out yours.
This test ran on 0.133.1. From 0.139.1 the router takes 256 connected clients unless you raise it, and 1024 at most, so the steps above 1,024 clients straight to the port cannot be repeated on a current version: How many clients can connect.
What was measured
| DBTrail | 0.133.1, on 16 vCPU and 64 GB (AWS Graviton, where one vCPU is one core). Defaults: fresh mode, 8 heavy queries on the copy at once. |
| Source | MariaDB 11.4, then MySQL 8.4, each on its own machine with 8 vCPU and 32 GB. |
| Table | accounts, 10 million rows. |
| Writes | 400 transactions a second on the source, the whole time. Each one moves an amount from one row to another. |
| Clients | 10, 50, 200, 1,000 and 2,000 connections. Each step: 20 seconds to connect them all, then 3 minutes measured. |
| Paths | Straight to port 3309 with Engine Routing on; through ProxySQL 3.1; straight with routing off. Both sources took all three. |
A client is one connection that asks a question, waits for the answer, then pauses about a second before the next one, like a person at a dashboard. So 2,000 clients would ask about 2,000 questions a second if every answer came back at once. Each client picked its next question from this mix:
| Share | Query | Answered by |
|---|---|---|
| 40% | SELECT balance, counter FROM accounts WHERE id = ? | MySQL: a lookup by primary key |
| 20% | SELECT SUM(balance), COUNT(*) FROM accounts | the copy |
| 20% | SELECT grp, COUNT(*), SUM(balance) FROM accounts GROUP BY grp | the copy |
| 20% | SELECT id, counter FROM accounts WHERE tag = ? | the copy: tag has no index, so this reads all 10 million rows |
Straight to the port, each client also asked the router after every query
who had answered it, to check the routing. Every SUM and every COUNT came
back exact, in every step.
How long an answer takes
MySQL 8.4, straight to the port, routing on. The heavy query drawn is the
SUM over all 10 million rows. From 200 clients on, the other two heavy
queries take within a few percent of it, because the wait is most of the
time. With few clients the scan on tag is quicker: 47 ms at 10 clients.
With 10 clients nothing waits, and the SUM takes a third of a second. The
ceiling comes between 10 and 50 clients. From there on, most of a heavy
query's time is its wait in line: 7 seconds at 200 clients, 40 at 1,000, 81
at 2,000. A lookup by key never joins that line. It goes to MySQL and,
straight to the port, stays between 1.1 and 1.8 ms, with a 99th percentile
under 14 ms even at 2,000 clients, straight or through ProxySQL.
Median time of the SUM over 10 million rows:
| Clients | MySQL 8.4, straight | MySQL 8.4, through ProxySQL | MariaDB, straight | MariaDB, through ProxySQL |
|---|---|---|---|---|
| 10 | 327 ms | 410 ms | 337 ms | 393 ms |
| 50 | 508 ms | 643 ms | 503 ms | 564 ms |
| 200 | 7.0 s | 7.6 s | 7.0 s | 7.0 s |
| 1,000 | 39.7 s | 29.3 s | 24.8 s | 43.7 s |
| 2,000 | 81.2 s | 87.1 s | 77.1 s | 88.6 s |
Two steps at 1,000 clients, MySQL 8.4 through ProxySQL and MariaDB straight,
answered more heavy queries a second than the ceiling (33 and 38), so their
SUM waited less. The cause is not known yet. Size with the ceiling the
other steps agree on, 24 a second.
Median time of a lookup by key. With routing off, the copy answers lookups too, and they wait in the same line as the heavy queries:
| Clients | MySQL 8.4, straight | MySQL 8.4, through ProxySQL | MariaDB, straight | MariaDB, through ProxySQL | MySQL 8.4, routing off |
|---|---|---|---|---|---|
| 10 | 1.6 ms | 1.7 ms | 1.1 ms | 1.3 ms | 79 ms |
| 50 | 1.7 ms | 1.9 ms | 1.3 ms | 1.4 ms | 446 ms |
| 200 | 1.8 ms | 2.0 ms | 1.4 ms | 1.5 ms | 5.2 s |
| 1,000 | 1.8 ms | 2.4 ms | 1.3 ms | 2.0 ms | 32.4 s |
| 2,000 | 1.8 ms | 3.2 ms | 1.4 ms | 2.8 ms | 67.6 s |
With routing off on MariaDB, a lookup took 51 ms at 10 clients and 31 seconds at 1,000.
How many answers a second
MySQL 8.4, straight to the port, routing on. Under the axis: how many heavy queries were waiting for their turn (the average over the step), and the errors clients got.
From 50 clients on, with routing on, the copy answered 23 to 25 heavy queries a second, and the total stayed at 39 to 42 answers a second. More clients did not bring more answers and did not bring errors. They made the line longer: about 4 heavy queries waiting at 50 clients, 150 at 200, 950 at 1,000, 1,950 at 2,000.
A heavy query waits about as long as the line ahead of it takes to clear at
24 a second. At 2,000 clients that is 1,953 ÷ 24, about 81 seconds, and the
measured median of the SUM was 81 seconds.
Clients got no errors in any step. The router counted 5 or 6 heavy queries as cancelled in each step from 1,000 clients up: they were still waiting when a step ended and the test closed their connections. Nothing was refused for load. The line holds up to 4,096 waiting queries, and the wait has no time limit unless you set one.
| Clients | Answers a second, all six setups | Heavy queries waiting, on average |
|---|---|---|
| 10 | 8.1 to 8.9 | 0 |
| 50 | 31.6 to 39.0 | 4 to 12 |
| 200 | 31.6 to 39.4 | 154 to 162 |
| 1,000 | 30.3 to 64.5 | 929 to 964 |
| 2,000 | 30.3 to 44.9 | 1,949 to 1,963 |
The lowest figures from 50 clients on are the runs with routing off, where lookups waited in the line too. The highest at 1,000 clients is one of the two steps above that passed the ceiling.
How far behind the source
The router reports, once a second, how far behind its source the data of its last answer was. MySQL 8.4, straight to the port, routing on:
In all six setups and at every step, the median was 2 to 3 seconds, the 95th percentile 3 to 4, and the highest single sample 4 seconds. A busier copy does not make its data older. Under load an answer comes late, not old: the query waits its turn, then reads data 2 to 3 seconds behind.
A second reader, checking a row the source rewrote every 200 ms, measured 0.8 to 1.5 seconds behind at the median whenever it got an answer. The router counts whole seconds, rounded up, so a median of 2 s means between 1 and 2 seconds.
How to size for your load
- The ceiling is CPU. From 50 clients on, the service that answers the port used 13 to 14.5 of the 16 cores, straight or through ProxySQL. Its memory peaked at 2.2 GiB of 64, so more memory would not have raised it.
- Find your own ceiling with your heaviest queries: the number of them the copy answers in a second when every worker is busy. Here, 24.
- How many clients wait for nothing: the ceiling divided by the heavy queries each client asks in a second. Here each client asked about 0.55 a second, so 24 ÷ 0.55 is about 45 clients, and the line did start between 10 and 50.
- How long a heavy query waits: the heavy queries in line divided by the ceiling. 150 waiting ÷ 24 is about 6 seconds.
- To raise the ceiling, give it more cores. DBTrail runs one heavy query for every two cores it may use (8 at once on these 16). Setting a higher number on the same cores runs more at once, each with fewer threads; this test did not try that. Both settings: When it is busy.
- If a quick error suits your application better than a long wait, set
ROUTER_MAX_WAIT(for example30s): a heavy query that waited longer gets error 1040, which drivers and pools retry. - Keep routing on. It is what keeps lookups under 2 ms straight to the port, and under 3.5 ms through ProxySQL. With it off, a lookup took 79 ms with 10 clients and 32 seconds with 1,000.
- ProxySQL in front adds no ceiling. Through it the copy answered the
same 22 to 24 heavy queries a second, and a lookup took 0.1 to 1.4 ms more
than going straight to the port. It holds one connection to DBTrail for
every client that waits. Give DBTrail's row in ProxySQL a
max_connectionsabove the most clients you expect to wait at once, and at or under the number the router takes (how). - Your MySQL keeps a connection per client too. Each connected client
also holds one connection to your MySQL, for the lookups. The sources here
ran with
max_connectionsat 5,000.
Next
- Capacity Planning: memory, CPU and disk for capture and the index.
- When it is busy: how many heavy queries run at once, and a limit on the wait.
- One connection, with ProxySQL