DBTrail
Capacity Planning

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.

24heavy a secondThe ceiling on 16 cores, for full scans of a 10-million-row table. The limit is CPU.
1.1 to 1.8 msa lookup by keyThe median from 10 to 2,000 clients, straight to the port. Lookups go to MySQL and never wait behind heavy queries.
4 sat most behindThe most behind its source the router reported, in every step, under any load.
0client errorsIn every step of 3 minutes. Past the ceiling, heavy queries wait in line instead.

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

DBTrail0.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.
SourceMariaDB 11.4, then MySQL 8.4, each on its own machine with 8 vCPU and 32 GB.
Tableaccounts, 10 million rows.
Writes400 transactions a second on the source, the whole time. Each one moves an amount from one row to another.
Clients10, 50, 200, 1,000 and 2,000 connections. Each step: 20 seconds to connect them all, then 3 minutes measured.
PathsStraight 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:

ShareQueryAnswered by
40%SELECT balance, counter FROM accounts WHERE id = ?MySQL: a lookup by primary key
20%SELECT SUM(balance), COUNT(*) FROM accountsthe copy
20%SELECT grp, COUNT(*), SUM(balance) FROM accounts GROUP BY grpthe 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.

Heavy: the SUM, answered by the copyLookup by key, answered by MySQLLine: median. Band: up to the 95th percentile. Log scale.
1 ms10 ms100 ms1 s10 s100 s10502001,0002,000clients connectedheavy, the copyby key, MySQL10 clientsHeavy, the copymedian 327 ms, p95 379 msBy key, MySQLmedian 1.6 ms, p95 1.7 ms50 clientsHeavy, the copymedian 508 ms, p95 986 msBy key, MySQLmedian 1.7 ms, p95 3.9 ms200 clientsHeavy, the copymedian 7.0 s, p95 7.8 sBy key, MySQLmedian 1.8 ms, p95 4.5 ms1,000 clientsHeavy, the copymedian 39.7 s, p95 44.5 sBy key, MySQLmedian 1.8 ms, p95 4.3 ms2,000 clientsHeavy, the copymedian 81.2 s, p95 89.3 sBy key, MySQLmedian 1.8 ms, p95 4.7 ms

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:

ClientsMySQL 8.4, straightMySQL 8.4, through ProxySQLMariaDB, straightMariaDB, through ProxySQL
10327 ms410 ms337 ms393 ms
50508 ms643 ms503 ms564 ms
2007.0 s7.6 s7.0 s7.0 s
1,00039.7 s29.3 s24.8 s43.7 s
2,00081.2 s87.1 s77.1 s88.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:

ClientsMySQL 8.4, straightMySQL 8.4, through ProxySQLMariaDB, straightMariaDB, through ProxySQLMySQL 8.4, routing off
101.6 ms1.7 ms1.1 ms1.3 ms79 ms
501.7 ms1.9 ms1.3 ms1.4 ms446 ms
2001.8 ms2.0 ms1.4 ms1.5 ms5.2 s
1,0001.8 ms2.4 ms1.3 ms2.0 ms32.4 s
2,0001.8 ms3.2 ms1.4 ms2.8 ms67.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.

Heavy queries, answered by the copyLookups by key, answered by MySQL
0102030405060a secondthe copy's ceiling,about 24 a second91000395040392001540421,0009510422,0001,9530clientsin lineerrors10 clientsHeavy, the copy5.4 a secondBy key, MySQL3.5 a second0 waiting, 0 errors50 clientsHeavy, the copy23.3 a secondBy key, MySQL15.8 a second4 waiting, 0 errors200 clientsHeavy, the copy23.4 a secondBy key, MySQL16.0 a second154 waiting, 0 errors1,000 clientsHeavy, the copy24.8 a secondBy key, MySQL16.8 a second951 waiting, 0 errors2,000 clientsHeavy, the copy24.9 a secondBy key, MySQL16.9 a second1,953 waiting, 0 errors

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.

ClientsAnswers a second, all six setupsHeavy queries waiting, on average
108.1 to 8.90
5031.6 to 39.04 to 12
20031.6 to 39.4154 to 162
1,00030.3 to 64.5929 to 964
2,00030.3 to 44.91,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:

Seconds behind the source, as the router reports it once a second. Line: median. Band: up to the 95th percentile.
0 s2 s4 s6 s8 s10502001,0002,000clients connectedmedian 2 s10 clientsmedian 2 s, p95 3 s50 clientsmedian 2 s, p95 3 s200 clientsmedian 2 s, p95 3 s1,000 clientsmedian 2 s, p95 3 s2,000 clientsmedian 2 s, p95 3 s

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 example 30s): 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_connections above 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_connections at 5,000.

Next

On this page