Troubleshooting

Performance problems

A checklist for slow statements, slow writes, high CPU use, memory growth and slow start-up in Raft DB, with the settings and the tools Raft DB provides.

Measure before you change anything. Tools Raft DB gives you: RAFTDB_MYSQL_TRACE=1 (every statement and its outcome), RAFTDB_MYSQL_PROF=1 (where each statement's time goes), GET /v1/server and GET /v1/stats, the watcher's latency check, and the benchmark programs of the project (not part of the download).

Slow reads#

CauseCheckFix
No index for the WHEREA comparison or range on an unindexed column scans the tableCREATE INDEX on the column (tutorial). A primary key (integer especially) is indexed already.
The index is not selectiveAn index is used when it points to at most about 3% of the rows; otherwise a scan is fasterNothing to fix.
A condition the engine cannot compare exactly like MySQLOnly comparisons Raft DB makes exactly as MySQL does are pushed to the engine; the rest is evaluated in the front-endRewrite with plain comparisons on columns.
Reading wide rowsThe front-end reads only the columns a statement namesName columns, avoid SELECT *.
A deep OFFSETOFFSET 500000 took about 0.9 s on 1 million rows (every shard returns m + page rows)Page by key (WHERE id > last ORDER BY id LIMIT n).
Two processesEvery row operation pays a round trip (about 60 microseconds on the test PC)Use embed (one process) (architecture).
A join over a big tableJoins run in the front-end; key lists are used to narrow the second tableIndex the join column; filter the first table in WHERE.

Slow writes#

CauseFix
One statement per row in autocommitGroup rows in INSERT ... VALUES (...), (...) or one transaction (the front-end waits for the disk once, at COMMIT).
Unique indexes and foreign keysRows with unique indexes or foreign keys are written one by one, each with its claims and checks. Keep only the indexes you need.
A slow diskEvery write waits for an fsync. Check the disk's flush latency. A drive that does not flush honestly is fast and unsafe.
sync-replicas without a healthy replicaEach write waits sync-timeout-ms (Replication problems).
A checkpoint or compaction runningA checkpoint on demand stops the table. On lsm, level-0 files over lsm-l0-slowdown delay writes and over lsm-l0-stop stop them. Raise compaction capacity, or in a managed cluster use the watcher's resource control.
Too few shardsWriters of different keys use different shards; shards defaults to the cores, at most 4.

High CPU use with few clients#

  • spin_us: a busy connection looks for its next message for up to 150 microseconds before it sleeps. On a shared or CPU-starved machine set spin_us = 0 (both raftdb-server and raftdb-mysql). The spin is off for idle connections and when more than a quarter of the processors' worth of connections are busy.
  • The watcher's checks are small; check that interval_seconds is not set very low.
  • The first minutes after a start: replaying logs and rebuilding indexes.

Memory#

  • The memory engine keeps every document in RAM. GET /v1/stats shows rows per database; compare with the size of the process. A table that is overwritten a lot grows its log (disk), not its memory.
  • alloc_cache (on by default) keeps freed blocks per thread: memory may look higher than the live data. alloc_cache = off returns blocks to the system.
  • The lsm engine: lsm-memtable-mb and lsm-block-cache-mb per shard bound its memory.
  • Each connection has two threads and buffers.

Slow start-up#

Replay of the logs (about 3.2 million records a second) takes time on a big history. Let the start-time rewrite shrink a mostly dead log (checkpoint-min-mb), or use engine = lsm for tables you expect to be large.

Disk growth#

The memory engine's logs grow until a checkpoint (at start, or on demand with POST .../checkpoint). Free space is watched by the watcher's disk check.

Compare with the numbers of the project#

The performance chapter lists the project's measurements and the machines they came from; compare like with like, and expect your hardware, disk and workload to differ. If your numbers are far below them on comparable hardware, report it with the statement and RAFTDB_MYSQL_PROF=1 output.

See also#