Frank DENIS random thoughts.

Improving MyISAM read/write concurrency

If you are running MySQL with MyISAM tables, you must have faced those damn locked tables.

By default, MySQL tries to fill holes (delete data) in a table. If a table has a hole, a new row will lock the table in order to safely fill the hole. It there is no hole, MySQL will insert the new row at the end of the table, without locking pending SELECT queries.

For a table that always has holes (because of frequent DELETE), this default behavior can be a showstopper under high load.

Before considering a move to PostgreSQL or to another MySQL engine like InnoDB or Primebase XT, here’s a simple line you can add to your /etc/my.cnf file that can help a bit:

<pre>concurrent_insert = 2</pre>

Of course you need a modern MySQL server for this (at least 5.0.3). With that setting, if a table lock would be usually required in order to fill a hole, MySQL will just insert the new row at the end of the table. The hole will still be there, but the table won’t need to be locked any more.

For tables storing sessions or other dynamic data, this is a big win.