DEV Community

Cover image for Boost MySQL Write Performance
Ruan Bekker
Ruan Bekker

Posted on

2

Boost MySQL Write Performance

I increased my write performance to a mysql database from 48s down to 3s writing 100,000 records at once.

I am no DBA, but I got curious when I noticed sluggish write performance on a mysql database, and I remembered somewhere that you should always use batch writes over sequential writes (when you have a lot of writes to be dine at once)

So I decided to test it out, using a python script and a mysql server.

For the sequential writes, I generated random data and in the for loop, I made a write to the mysql database every time I generated data for the record.

For the batch write, I defined a list/array and for every record that I generated, I appended the record to the list and once I exited the loop, I write to the database using executemany and including the list.

The scripts I used, the results and more info can be viewed on my blog:

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay