THE WORLD DISCUSSES #PYTHIAN ON TWITTER. HAVE A QUESTION? USE OUR HASHTAG AND ASK AWAY.

Enhancing performance in WordPress by moving from MyISAM to Innodb

Recently I was dealing with some locking issues in databases supporting WordPress. For those who don’t know it yet WordPress is a really cool open source tool for easy blogging. This tool is really easy to install (just drag and dropping in your home directory) and making it really easy for you to get up and running.

As a part of this easy installation there are some things that aren’t best practices for good performance and scalable sites. These limitations are related to the use of MyISAM as a storage engine. This engine was for many years the default storage engine in MySQL. It changed, fortunately, with 5.5, but in previous installations MyISAM will be there for use.

MyISAM storage engine is really good at retrieving data but:
- it doesn’t support concurrency
- all operations causes table level locking (this is not entirely true but mostly)
- it’s not crash-safe (you’ll hate it during a crash)
Read the rest of this entry . . .

What happens when InnoDB fails to start

Today I’ve spent some time (more than this issue was worth, actually) on a client’s system trying to
find out why table was not accessible and failed with the following error:

mysql> SHOW CREATE TABLE test_table;
ERROR 1033 (HY000): Incorrect information in file: './test/test_table.frm'

Read the rest of this entry . . .

Testing TokuDB – Faster and smaller for large tables

For the past two months, I have been running tests on TokuDB in my free time. TokuDB is a storage engine put out by Tokutek. TokuDB uses fractal tree indexes instead of B-tree indexes to improve performance, which is dramatically noticeable when dealing with large tables (over 100 million rows).

For those that like the information “above the fold”, here is a table with results from a test comparing InnoDB and TokuDB. All the steps are explained in the post below, if you want more details, but here’s the table:

Action InnoDB TokuDB
Importing ~40 million rows 119 min 20.596 sec 69 min 1.982 sec
INSERTing again, ~80 million rows total 5 hours 13 min 52.58 sec 56 min 44.56 sec
INSERTing again, ~160 million rows total 20 hours 10 min 32.35 sec 2 hours 2 min 11.95 sec
Size of table on disk 42 Gb 15 Gb
COUNT(*) query with GROUP BY 58 min 10.11 sec 5 min 3.21 sec
DELETE query 2 hours 46 min 18.13 sec 1 hour 14 min 57.75 sec
Size of table on disk 42 Gb 12 Gb
OPTIMIZE TABLE 1 day 2 hours 19 min 21.96 sec 21 min 4.41 sec
Size of table on disk 41 Gb 12 Gb
TRUNCATE TABLE 1 min 0.13 sec 0.27 sec
Size of table on disk 41 Gb 193 Mb (after waiting 60 seconds before doing an ls -l)
OPTIMIZE TABLE 23.88 sec 0.03 sec
Size of table on disk 176 Kb 193 Mb

Read the rest of this entry . . .

Video and Slides: How InnoDB works

This presentation was done by Sheeri Cabral of The Pythian Group and went into how to use SHOW ENGINE INNODB STATUS to get more information about your Innodb tables, foreign keys and transactions. This is a great presentation to learn how InnoDB works.

It also went through how to use SHOW ENGINE INNODB STATUS to tune several InnoDB variables:

innodb_adaptive_hash_index
innodb_commit_concurrency
innodb_concurrency_tickets
innodb_file_io_threads
innodb_log_buffer_size
innodb_max_purge_lag
innodb_sync_spin_loops
innodb_thread_concurrency
innodb_thread_sleep_delay

The slides can be downloaded from:

http://technocation.org/files/doc/ShowEngineInnoDBStatus.pdf

(Note that the slides open up to the middle section, which has slides plus notes, but if you just want the slides without notes, that starts on page 1 of the PDF.)

The video can be watched below, or directly on YouTube at http://www.youtube.com/watch?v=ocdjspoLM58

Taste test: Innobackup vs. Xtrabackup

Firstly, I have to thank my co-workers Singer Wang and Gerry Narvaja for doing a lot of the work that resulted in this comparison.

After running both InnoDB Hot Backup and Xtrabackup, we have found that there is a measurable but not large difference between the resources that Xtrabackup and InnoDB Hot Backup consume.

Xtrabackup:

  • Free
  • takes 1.1% longer (2 min during a 3 hour backup)
  • uses 1.4% more space (1G more in a 70G backup — this was for uncompressed backups)
  • uses 1.115% more cpu overall
  • split as 0.12% user, 0.66% nice, 0.025% system, 0.31% more iowait, 0% more steal
  • Read the rest of this entry . . .

Upcoming Boston MySQL User Group: SHOW ENGINE INNODB STATUS demystified

On Monday, October 12, 2009* from 7-9 pm at MIT, I will be giving a presentation explaining SHOW ENGINE INNODB STATUS for the Boston MySQL User Group. There is information about foreign keys, transactions, deadlocks and mutexes just waiting to be discovered, and I will show how to decipher the information.

For all those in the Boston area, I hope to see you there! For those who cannot be there, we will video this presentation and make it available online, and post here when the video/slides are up.

*Yes, I realize that this is a bank holiday in the US.

There is more than one way to do it….

I spent Friday examining the systems for a more traditional consulting gig (in case you did not know, Pythian has offered more traditional consulting and emergency services in addition to our remote DBA offering for our entire 12 year history). It is a familiar story to many people — the database performance was unacceptable.

The company had a few log tables that had huge amounts of inserts and foreign keys, so they used InnoDB. Unfortunately, they also used a GUID as a primary key (which is getting more and more common these days, but long primary keys with InnoDB slow down INSERT, UPDATE and DELETE commands a great deal) — varchar(32) and utf8.

That’s right — their primary key for many of these tables was 96 bytes long (32 characters * 3 bytes per character), and as an InnoDB table, the primary key is clustered with every other index. One of the more frequently used tables had 8 indexes other than the PRIMARY KEY — 7 were indexes on varchar(32) fields, the other was on an int(11) field (signed integer).

The query load on the server was 99% writes, 1% reads. The log tables only had rows inserted, not deleted or updated. Thus, we offered a few different solutions (in no particular order):

1) Use a BLACKHOLE table on the master and replicate to a slave server. This would make the INSERTs to the master fast, though the slave would lag behind. The slave could be changed to MyISAM or ARCHIVE or some other storage engine.

2) Use MyISAM on the master and slave. This was the solution we went to, because the log tables could be re-created with no data and moved into place, and the loss of foreign keys was not a big deal, since the application checked for them anyway. ARCHIVE could also be used, it is faster than MyISAM on inserts because it only allows one index, the PRIMARY KEY. concurrent_insert was set at the default of 1, but we changed it to 2 just in case there was an errant UPDATE or DELETE causing a gap in the MyISAM table.

3) Add a PRIMARY KEY that is AUTO_INCREMENT, keeping the GUID a UNIQUE KEY. This would speed up the writes without sacrificing any data. This can be combined with dropping unnecessary foreign keys to make the inserts faster.

4) Move the log tables to a different machine entirely. This would require the application to have two different database handlers.

5) Use INSERT DELAYED into the logging tables.

We discussed these scenarios and the pros and cons, and eventually we chose to do #2, which we could do right away, and indeed, we had an immediate positive impact. Almost all the unnacceptable performance went away.

We were also able to audit the system and provide several good recommendations for ways they can improve their system. It is exciting for me to be able to help people out in a very tangible way — often we do not see some of the really crazy problems that affect few people (such as slave lag getting further and further behind) because our remote DBA clients have the benefit of ongoing help from us, and we generally find the smaller degradations in performance before they become a large issue.

Being able to spend a few hours with a new environment and really help them out was extremely fulfilling for me. I love that MySQL has many different options (and there are likely more that I did not think of) that all would work to achieve better performance. I think people like to have a choice, too, so they do not feel they were forced to do something they did not want to do. Especially when there are solutions on both the DBA and developer side.

MySQL 5.1 and InnoDB Hot Backup Gotcha

Recently while we were building a slave with a newer version of MySQL 5.1 from an InnoDB Hot backup, the following error occurred when we ran mysql_upgrade:

mysql.time_zone                                    OK
mysql.time_zone_leap_second                        OK
mysql.time_zone_name                               OK
mysql.time_zone_transition                         OK
mysql.time_zone_transition_type                    OK
mysql.user                                         OK
Running 'mysql_fix_privilege_tables'...
ERROR 13 (HY000) at line 311: Can't get stat of './mysql/general_log.CSV' (Errcode: 2)
ERROR 13 (HY000) at line 316: Can't get stat of './mysql/slow_log.CSV' (Errcode: 2)
FATAL ERROR: Upgrade failed

The problem is that in MySQL 5.1, it is possible to log the slow query log and general log to tables in the mysql schema (source: Selecting General Query and Slow Query Log Output Destinations). These tables are created by default as CSV tables for performance reasons, and are created even if MySQL is set not to log to tables.

CSV tables, however, are not copied as part of the InnoDB Hot Backup process (by the wrapper script innobackupex.pl), thus creating this error. The fix to get the slave working Read the rest of this entry . . .

2009 MySQL Conference/Camp Videos

It’s been just over three months since the April 2009 MySQL Users Conference and Expo. It took a while for the files to be processed, and then uploaded to www.technocation.org, and then I found out that the online streaming was not working properly. So I started playing with things, re-encoding some videos, updating the software, but to no avail.

Just as I was about to give up I got notification that Technocation, Inc. was accepted into YouTube‘s not-for-profit program, which allows movies larger than 10 minutes to be uploaded and viewed advertisement-free.

So then I had to upload the videos to YouTube and add descriptions.

So with no *further* delay, here are all the videos from the 2009 MySQL Conference and 2009 MySQL Camp:

The brief description — just the playlists:
Conference playlist (16 videos):
http://www.youtube.com/view_play_list?p=0F93B7A29807C4F7

Camp playlist (6 videos):
http://www.youtube.com/view_play_list?p=5EE4B7EC2F257251

The longer description – each video with title, presenter(s) and link:
MySQL Camp:
Keynote: The State of Open Source Databases
Brian Aker (Sun Microsystems)
http://www.youtube.com/watch?v=m2V-hvD_icA

Read the rest of this entry . . .

Concerns and What Does Not Work in XtraDB Backup

A short time ago I posted how I was Using XtraDB Backup to backup InnoDB. Overall, the blog post was positive, but experiences that others have had (and commented to on that blog post) have made me want to put out another short article about using XtraDB backup.

The first few points remain the same — the backup process is stable, we were able to use the binaries without compiling, and using Innobackupex as the wrapper script, analogous to Innobackup.pl.

However, we did figure out why Xtrabackup had to be run as the mysql user:

Xtrabackup writes to the data dictionary file (ibdata1, for example). We have not examined if it also writes to the data and index files (still ibdata1 by default, or the .ibd files when using innodb_file_per_table). [EDIT: The authors of Xtrabackup have commented below as to why the write occurs:

xtrabackup is kind of very small and restricted instance of InnoDB, and reuses a lot of InnoDB code.

InnoDB by default requires O_RDWR option on ibdata1 files at start, and xtrabackup therefore also did that. In the latest push to trunk it was fixed, now xtrabackup opens file with O_RDONLY flag.

When the new version is released, we will be sure to test it so that we can run the backup as a read-only user, and report back.]

On the one hand, Xtrabackup is a free tool. On the other hand, modifying InnoDB’s underlying files risks corrupting all the InnoDB tables in the system. Which is a tricky situation when it is your backup tool that might cause corruption that is beyond repair, as you do not know if you can trust your backups.
Read the rest of this entry . . .

Start NowWith Pythian - database design, management and emergency handling capabilities...

Live Updates

pythian: RT @FN_Press2: Schooner Information Technology Teams with Pythian to Deliver Advanced Support and High... http://finanznachrichten.de/20
more



Testimonials

  • Serge Racine

    DBA, Brookfield Energy

    We are very satisfied by the service given to us by Andre and Shakir in support of our recent data quality and reorganization initiative.... more