MySQL front-end performance
Decisions from the measured performance steps of the MySQL front-end against MySQL 9.7 (D62, D63, D65 to D69).
These entries are a sequence: each one measures, finds the cost, changes it and measures again. The figures are in the log and in the benchmark results log; they are not repeated here because they depend on the machine and the tool named in each entry.
D62 First measurement against MySQL 9.7 and the definition cache#
The first measurement showed single-row insert ahead of MySQL and reads, ranges and joins far behind. The cheap part of the cause was that every statement made four round trips to Raft DB around the row. The change is a process-wide cache of table definitions, dropped when this connector changes a definition and in any case after 2 seconds, which means another connector's change is seen that late.
D63 Second step: bounds on one field are one index range; an integer primary key is indexed#
Two findings. The planner took one comparison per query to fetch candidates, so k BETWEEN a AND b read every row above a or below b; two or more bounds on one ordered field are now intersected into one index range. A table whose primary key is one whole-number column had no index on it, so range and join access scanned the table; it now gets an ordered index. The entry also records that mysqlslap was wrong in absolute terms and that the stock JDBC driver is the measuring tool from here on.
D65 Third step: the planner no longer lists half the table; rows are read in binary#
Leaves that a combined range already covers are skipped, which cut range scans and counts. Rows now come back in Raft DB's binary form and are decoded straight into values instead of being made as JSON text and parsed. Field ids are asked once per table and kept, and a session keeps a connection bound to each table it uses, so alternating between tables costs no round trip per switch.
D66 Fourth step: reads on the connection's thread, the server inside the front-end, rows sent together#
The requirement was to be equal to or faster than MySQL 9.7 on common application workloads. Measurement showed that a blocking loopback round trip between two processes (about 60 us on the test PC) is a large part of what MySQL needs for a whole key read, so reads cannot reach MySQL in two processes whatever the server does. The decision is to run the server inside the front-end process, serve reads on the connection's thread, send the rows of a statement together, and cut allocations in the executor.
D67 The one-process mode (embed) is the default way to run the MySQL front-end#
After D66 the speed exists only when the server runs inside the connector. The documentation therefore leads with embed, and two processes are documented as the way to put the front-end on a different machine from the data. The raftdb-server program and the binary protocol are unchanged.
D68 Fifth step: allocation cache per thread, bounded look before a blocking receive, a join's tables read at once#
The requirement widened to every workload and every way of running the front-end. The causes found, in the order found: the system allocator's cost on Windows (a request makes tens to hundreds of allocations), the wake-up cost of a blocking receive, and a join that read its tables one after another. Each was addressed and the results were measured for one and two processes.
D69 Sixth step: protocol version 2, shared connections for reads by key#
This step asked for a connection design in which many sessions' requests travel together over few sockets and work over a real network, with one process and all writes not slower. Protocol version 2 sends streams and fields instead of rows and waits once for the disk, and the sessions' reads by key share a connection. The log gives the before and after figures for two processes at one and sixteen connections.