Database Platform Comparisons for Laravel Feature Tests

TL;DR: MySQL significantly outperforms MariaDB in my automated test suite.

The Problem

This Twitter thread prompted me to do a bit of research on database platforms for Laravel automated tests.

I’ve recently been building an ecommerce app based on Laravel. Partway through development, we added geometry fields to a couple of tables in order to determine distances. I’ve been using this spatial package, so SQLite was not an option for my test suite.

As soon as I switched the testing database driver from SQLite to MariaDB, my tests immediately took an extra 12–13 seconds to run, regardless of whether I ran the entire test suite, a single file, or just one test.

This significantly lengthened the feedback loop when making changes to code and re-running tests.

So when I saw Jack Ellis mention that he uses MySQL for his test suite, it made me curious if he had the same issue.

He said that one of his test files runs 39 tests in < 2 seconds, so apparently it’s not been a problem for him.

Context

  • I’m using the LazilyRefreshDatabase trait added in Laravel 8.62.0 on my entire test suite
  • I’m using squashed migrations
  • Many of my tables have constrained foreign keys referencing other tables

Comparisons

I decided to do some digging; here are comparisons using four different platforms for the same test in my application.

MariaDB

I’ve been using MariaDB as the main database platform on my development machine for years. Currently I’m on version 10.6.4.

In-Memory SQLite Database

I temporarily disabled the geometry features and tried the in-memory SQLite database (DB_CONNECTION=:memory:); it performed much better for the same tests:

SQLite File Database

I then tried with an SQLite file (DB_CONNECTION=sqlite), and it performed about the same:

MySQL 8

I have an installation of MySQL 8 set up for one app that uses some specific MySQL 8 and I figured why not give that a try too.

Here are the results:

Summary

For some reason, MariaDB takes approximately 12–13 seconds to tear down and recreate the database before starting to run tests, but MySQL is much faster.

While testing MariaDB, I opened the raw data directory for the database, and noticed chunks of files being removed and recreated at a time, so perhaps the foreign key constraints are (part of) the culprit here.

I do have 77 databases with ~3800 tables in my MariaDB installation built up from various projects over the years. It seems unlikely, but theoretically possible, that the server size could be part of the problem too.

I think I’ll experiment with switching back to MySQL as my development platform of choice.

Have you run into this same issue? Have any tips or tricks? Let me know in the comments.

Character Matters

Yesterday’s assault on the Capitol demonstrates clearly why the character of our leaders matters; why “the policies are the important thing” and “we’re not electing a pastor” are poor excuses to gain power.

President Trump for five years has shown nothing but disregard for laws and norms in his quest for power. He consistently encouraged those who support him to do the same.

Remember when he said he could shoot a person in public and still be elected? Or encouraged supporters at a rally to assault a protestor, adding that he would pay the legal fees?

This type of rhetoric, and countless other examples, all led to yesterday.

“I support his policies but wish he would tweet less” is a poor excuse for power. What we say comes first from our heart:

A good man out of the good treasure of his heart bringeth forth that which is good; and an evil man out of the evil treasure of his heart bringeth forth that which is evil: for of the abundance of the heart his mouth speaketh.

—Luke 6:45

The words we speak have consequences, and five years of Trump’s words led to yesterday’s actions by his supporters. (Yes, his supporters, not antifa.)

Months of claiming “the election will be rigged” and weeks of claiming rampant election fraud in public while offering little to no evidence in courts—where it actually mattered—have resulted in “different truths” for those who support Trump and those who do not, and led directly to yesterday’s events.

His quest for power led to this. But it was encouraged and enabled by Republican and “conservative” support.

Growing up during the Clinton presidency, I often heard “character matters in our leaders” and more than ever, I believe that is true.

I was also taught that “the end does not justify the means,” that “it’s never right to do wrong in order to get a chance to do right.”

Yet during the past five years, “conservatives” and the church have demonstrated time and again that all too often, those were just words.

“But he’s better than the alternative” is pragmatism, pure and simple. “But the left is going to destroy our country” is a poor excuse for failing to stand for convictions.

Christian and “conservative” support for Trump has enabled and emboldened him, at the cost of losing all credibility because of these double standards.

Thank God for people like David French and Phil Vischer who are not afraid to stand for truth.

Character matters. It always has, and always will, and we cannot afford to ignore it in our leaders.