Some months ago I was testing a fairly common setup in MySQL replicas, just a master and a slave. I was working on a couple of Vagrant boxes just to be quick and take some notes while experimenting. Everything got fine but I was curious to test the replica under load. Not particular heavy load, just a couple of queries per second, to mimic a production environment. Yes, I could have write a simple bash loop to run a SELECT * FROM some_table LIMIT 10 but at the end I decided it was not so important and passed over.
The idea stuck in my mind until some days ago, when with some evening spare time I’ve decided to write a simple module to do exactly this: plug into a MySQL instance, discover database schema and run some simple, meaningful, small queries. Actually a module is not the right word; it’s more a couple of files in a folder.
It works using a set of pre-written, generic queries in Jinja2 template that picks from a list of allowed verbs (so you can’t easily destroy your database with random DELETE and UPDATE queries) that are populated with random values of appropriate type. The SQL verbs are also weighted so you can, for example, decide to run a ratio of 10 SELECT and 2 UPDATE. I’ve also written a sample client that uses the module to demonstrate how to run it.
The project is indeed also a good workbench for me to test some things I’ve ever procrastinated, like Python3, sphinx autodoc to automatically generate documentation from modules/classes and so on. Probably in the future I’ll use also for acquire some practice with unittesting and other useful stuff.
You can find the module on GitHub with documentation and all. Note that is not finished yet and probably in the future I’ll improve the random values generation and database schema discovery to get rid of all errors and warnings while run the updates.