db-io-reduce
Database service containers and ad-hoc docker run commands in CI write to disk by default. On GitHub Actions hosted runners, this causes unnecessary I/O overhead that can significantly slow down test suites.
Optimise by either:
- Using
--tmpfsto mount the database data directory as an in-memory filesystem. - Configuring the database to reduce disk I/O (disk flushes are a major source of I/O overhead on CI runners):
- MySQL: Set
innodb_flush_log_at_trx_commit=2. - PostgreSQL: Set
fsync=off(acceptable for ephemeral CI environments).
- MySQL: Set
Scope
This rule checks three patterns:
- Service containers:
jobs.<id>.services.*.imagematching MySQL or PostgreSQL. - Direct
docker run: Steps that calldocker runwith a MySQL or PostgreSQL image. docker compose: Steps that calldocker compose up/start/runwhen the step name or command mentions MySQL/PostgreSQL.
Examples
Not optimal
services:
mysql:
image: mysql:8
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
steps:
- run: docker run -d -p 3306:3306 mysql:8
Optimal (tmpfs)
services:
mysql:
image: mysql:8
options: --tmpfs /var/lib/mysql
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
Optimal (config flag)
services:
postgres:
image: postgres:14
env:
POSTGRES_PASSWORD: password
PGOPTIONS: "-c fsync=off"