Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping data plus index-data in memory - InnoDB vs. MyISAM

Assume a database consisting of 1 GB of data and 1 GB of index data.

To minimize disk IO and hence maximize performance I want to allocate memory to MySQL so that the entire dataset including indexes can be kept in RAM (assume that the machine has RAM in abundance).

The InnoDB parameter innodb_buffer_pool_size is used to specify the size of the memory buffer InnoDB uses to cache data and indexes of its tables. (Note: The memory is used for data AND indexes.)

The MyISAM parameter key_buffer_size is used to specify the size of the memory buffer MyISAM uses to cache indexes of its tables. (Note: The memory is used ONLY for indexes.)

If I want the 2 GB database (1 GB data and 1 GB index) to fit into memory under InnoDB, I'd simply configure the innodb_buffer_pool_size to be 2GB. The two gigabytes will hold both the data and the index.

However, when setting the MyISAM key key_buffer_size to 2GB that space will be used for the index, but not for the data.

My questions are:

  • Can MyISAM's "data buffer size" (not index data) be configured explicitly?
  • When will MyISAM read table data (excluding index data) from disk and when will it read from memory?
like image 733
knorv Avatar asked Feb 07 '10 18:02

knorv


People also ask

Which is better InnoDB or MyISAM?

The performance of InnoDB for large volumes of data is better as compared to MyISAM. MyISAM doesn't support transactional properties and is faster to read. As compared to InnoDB, the performance for a high volume of data is less.

What is a major difference between MyISAM and InnoDB storage engines?

The main differences between MyISAM and InnoDB Overall, MyISAM is an older and less efficient storage engine than InnoDB. The most commonly noted differences between these two engines are as follows: InnoDB is more stable, faster, and easier to set up; it also supports transactions.

What are the advantages of MyISAM over InnoDB?

- MyISAM is faster than InnoDB in most of the cases. - MyISAM table is stored as a separate file which can be compressed. - This means that MyISAM has a better storage management. - MyISAM supports full indexing that is not supported by InnoDb.

Why is MyISAM faster than InnoDB?

MyISAM will out-perform InnoDB on large tables that require vastly more read activity versus write activity. MyISAM's readabilities outshine InnoDB because locking the entire table is quicker than figuring out which rows are locked in the table.


1 Answers

  • No MyISAM has no general purpose data cache. This is documented in the "key_buffer_size" description from the official documentation: This is because MySQL relies on the operating system to perform file system caching for data reads, so you must leave some room for the file system cache.

Modern OSes, especially Linux, tend to have very smart virtual memory subsystems that will keep frequently accessed files in the page cache, so disk I/O is kept at a bare minimum when the working set fits in available memory.

  • So to answer your second question: never.

It's important not to fall into "buffer oversizing" too for the various myisam variables such as read_buffer_size, read_rnd_buffer_size, sort_buffer_size, join_buffer_size, etc as some are dynamically allocated, so bigger doesn't always mean faster - and sometimes it can even be slower - see this post on mysqlperformanceblog for a very interesting case.

If you're on 5.1 on a posix platform, you might want to benchmark myisam_use_mmap on your workload, it's supposed to help high contention cases by reducing the quantity of malloc() calls.

like image 84
ggiroux Avatar answered Sep 24 '22 14:09

ggiroux