Speeding Up Laravel Tests with tmpfs (MySQL in RAM)
If your Laravel test suite is painfully slow and does a lot of database work (multi-tenancy, migrations, seeding), the bottleneck is almost…
Is your Docker-based development environment sluggish? Do your fans spin up for no reason? If you run docker stats, do you see your MySQL container writing gigabytes of data under the BLOCK I/O column?
If so, you've likely encountered the MySQL binary log (binlog). The binlog is a set of files that records every change made to your database. It's essential for replication and point-in-time recovery on production servers, but it's often a major performance killer in a local development environment.
For every INSERT, UPDATE, or DELETE your app performs, MySQL also performs a write operation to the binlog. On systems like WSL2, this constant I/O can bottleneck your entire machine.
Run this command in your terminal while your application is running:
docker stats
Look for the BLOCK I/O column. If you see a massive write number for your mysql container, the binlog is the culprit.
CONTAINER ID NAME CPU % MEM USAGE / LIMIT BLOCK I/O
0251fff5e872 my-project-mysql-1 2.23% 684.5MiB / 31.2GiB 133MB / 13.3GB <-- Problem!
You can disable the binary log by adding a single startup command to your docker-compose.yml file.
sail down
Edit docker-compose.yml:
Find the service definition for mysql and add the command: --disable-log-bin line.
# docker-compose.yml
services:
# ... other services
mysql:
image: 'mysql/mysql-server:8.0'
+ command: --disable-log-bin
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
# ... rest of the file
After applying the fix, the old, multi-gigabyte log files will still exist inside your Docker volume. You have two options to clean them up.
This is the easiest method. It destroys the MySQL volume, deleting the old logs and all of your data.
# This will completely WIPE your development database
sail down -v
# Start fresh and migrate
sail up -d
sail artisan migrate --seed
If you have custom data you don't want to lose, you can log into the container and surgically remove just the binlog files.
sail up -dsail exec mysql bashmysql -u root -p (Use your DB_PASSWORD)RESET MASTER;
Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.
Take a look at vroni.com