11

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?
4

1 に答える 1

12
  • いいえ MyISAM には汎用データ キャッシュはありません。これは、公式ドキュメントの「key_buffer_size」の説明に記載されています。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.

最新の OS、特に Linux は、頻繁にアクセスされるファイルをページ キャッシュに保持する非常にスマートな仮想メモリ サブシステムを備えている傾向があるため、ワーキング セットが使用可能なメモリに収まる場合、ディスク I/O は最小限に抑えられます。

  • 2 番目の質問に答えるには、「決して」ではありません。

一部は動的に割り当てられるため、read_buffer_size、read_rnd_buffer_size、sort_buffer_size、join_buffer_size などのさまざまな myisam 変数についても、「バッファーのオーバーサイジング」に陥らないことが重要です。非常に興味深いケースについては、mysqlperformanceblog のこの投稿を参照してください。

posix プラットフォームで 5.1 を使用している場合は、ワークロードでmyisam_use_mmapのベンチマークを実行することをお勧めします。これは、malloc() 呼び出しの量を減らすことで競合の多いケースに役立つはずです。

于 2010-02-12T21:45:39.667 に答える