InnoDB storage engine for MySQL has some benefits regarding different database workloads but also has some negative impact which should be taken care of with other services and/or tools. Presentation will also compare significant differences between the two major engines for MySQL - InnoDB and MyISAM and best-practice scenarios for both.
ZgPHP Meetup #39
http://www.meetup.com/ZgPHP-meetup/events/205928622/
Video:
http://zgphp.org/videos/tomislav-raseta-mysql-engines/ (http://vimeo.com/117263231)
2. me
scribbling and doodling on *IX operating systems for 10+ years
working as sysadmin/DevOps with a hint of networking
tools of the trade
nginx httpd tomcat (ugh!)
python php java (ugh!)
postgresql mysql
memcached redis mongo
3. PHP & MySQL
part of the original LAMP
Linux
Apache
MySQL
PHP
default database for most PHP developers
MySQL - used by many, understood by few
4. MySQL storage engine
stores, handles and retrieves information from a table
most developers just go with the default in phpMyAdmin (ugh!)
default engine is set in MySQL configuration file
[mysqld]
default-storage-engine=InnoDB
Up to MySQL 5.1 default engine was MyISAM, 5.5+ is InnoDB
mysql -uroot -p
Password:
mysql> show engines;
5. concurrency
MyISAM does table-level locking
each query waits for its turn to run (ugh!)
(SELECT * from table anyone?)
very fast but very dangerous due to the nature of Web transactions
(query pile-up)
InnoDB does row-level locking
parallel SELECT/INSERT/UPDATE/DELETE
does caching for data in indexes in memory
COUNT(*) is slow (uses full table scan or full index scan if you use WHERE)
6. reliability
InnoDB is fully ACID compliant
COMMIT
ROLLBACK
referential integrity
transactions
crash-recovery capabilities
MyISAM
these aren’t the droids you’re looking for, move along now
7. full text search
MyISAM supports it
InnoDB supports it from MySQL 5.6
Don’t use it.
Using database as a search engine is a BAD IDEA
Elasticsearch
Sphinx
Lucene
Solr
8. real life examples
server crash
InnoDB – data is safe, automatic recovery
MyISAM – foobar
high volume* traffic
InnoDB – row data stored in Primary Key order, data and indexes in
memory, maximum performance, row-level locking
MyISAM – three separate files, table locking – foobar
*not your homepage, but something more than 5req/sec
9. tips n tricks
MOAR Memory
Databases love it
Memory is cheap
innodb_buffer_pool set to 80% of total memory works wonders for InnoDB
key_buffer set to high amount in MyISAM just means you’re going to lose a
lot more data if server crashes – but blazing fast!
MOAR Cores
new generation processors use less energy, less clock speed but more cores
Getting cheaper every day
Aim for the ones with big L2/L3 cache and high clock / more cores
ultimate decision depends on your database workload
10. tips n tricks
MOAR IOPS
SSDs (be careful!)
A bunch of rotational disks (Storage array)
Ideally
Dual/Quad Multi-core high-clock CPU’s (Intel Xeon E3/E5/E7 v3)
A bunch of memory
Enterprise-level SSDs (no Desktop SSDs!)
14. MySQL forks
don’t use the original
Percona (nice tools and XtraDB)
MariaDB
Drizzle
MySQL Enterprise
$$$$$$$
15. DO NOT
combine MyISAM and InnoDB on same database server
too much hassle to find the optimum ratio of buffers
JOIN’s between tables with different storage engines fallbacks to the
less featured (MyISAM)
there be dragons
use full text search
just don’t do it, please
rely on database only
memcached
16. migrating to InnoDB
ALTER TABLE table1 ENGINE=InnoDB;
locks table
Dump SQL, search/replace MyISAM -> InnoDB, Restore SQL
timely process
if using Percona MySQL fork
pt-online-schema-change --alter "ENGINE=InnoDB" D=database,t=table
doesn’t work if you use triggers on tables
try to adapt to your requirements (downtime, server speed etc.)
17. monitor all the things!
slow query logs
http://mysqltuner.pl
cacti graphs
newrelic
MONyog
don’t blame database if your queries are stupid
don’t blame database if your application stupid