Segmentazione della Cache degli Indici

Stai visualizzando una vecchia versione di questo article. Visualizza la versione più recente.

Informazioni generali

Una chiave degli indici segmentata (Segmented Key Cache) è una collezione di strutture per le normali cache degli indici di MyISAM, chiamate segmenti di cache. Le cache segmentate mitigano uno dei maggiori problemi della cache semplice: la contenzione dei thread per i lock sulla cache degli indici (mutex). Con le consuete cache degli indici, ogni chiamata ad una funzione dell'interfaccia della cache deve acquisire un lock. Perciò i thread competono per ottenere questo lock, anche nel caso in cui hanno acquisito dei lock condivisi sul file e le pagine che vogliono leggere si trovano nei buffer della cache degli indici.

Quando si lavora con una cache degli indici segmentata, le funzioni dell'interfaccia della cache che accedono a una certa pagina devono acquisire il lock solo su quei segmenti a cui la pagina è assegnata. Questo diminuisce le probabilità che i thread debbano competere per lo stesso lock.

Tutte le pagine di un file possono essere poste in un buffer composto da un solo segmento. Il numero dei segmenti è dato dal numero di file e dalla posizione della pagina nel file, ed è sempre lo stesso per ogni pagina. Le pagine sono distribuite in maniera uniforme tra i segmenti.

L'idea e il codice originale della cache degli indici segmentata sono di Fredrik Nylander di Stardoll.com. Il codice è stato pesantemente modificato, migliorato e infine unito a MariaDB da Igor Babaev di Monty Program.

Alcuni risultati dei benchmark, che comparano le varie configurazioni della key_cache_segments, sono disponibili alla pagina Segmented Key Cache Performance,

Segmented Key Cache Syntax

New global variable: key_cache_segments. This variable sets the number of segments in a key cache. Valid values for this variable are whole numbers between 0 and 64. If the number of segments is set to a number greater than 64 the number of segments will be truncated to 64 and a warning will be issued.

A value of "0" means the key cache is a regular (i.e. non-segmented) key cache. This is the default. If key_cache_segments is "1" (or higher) then the new key cache segmentation code is used. In practice there is no practical use of a single-segment segmented key cache except for testing purposes. For all practical purposes setting key_cache_segments = 1 should be slower than any other option and should not be used in production.

Other global variables used when working with regular key caches also apply to segmented key caches: key_buffer_size, key_cache_age_threshold, key_cache_block_size, and key_cache_division_limit. See the Server System Variables page for more on these variables.

Segmented Key Cache Statistics

Statistics about the key cache can be found by looking at the KEY_CACHES table in the INFORMATION_SCHEMA database. Columns in this table are:

Column NameDescription
KEY_CACHE_NAMEThe name of the key cache
SEGMENTStotal number of segments (set to NULL for regular key caches)
SEGMENT_NUMBERsegment number (set to NULL for any regular key caches and for rows containing aggregation statistics for segmented key caches)
FULL_SIZEmemory for cache buffers/auxiliary structures
BLOCK_SIZEsize of the blocks
USED_BLOCKSnumber of currently used blocks
UNUSED_BLOCKSnumber of currently unused blocks
DIRTY_BLOCKSnumber of currently dirty blocks
READ_REQUESTSnumber of read requests
READSnumber of actual reads from files into buffers
WRITE_REQUESTSnumber of write requests
WRITESnumber of actual writes from buffers into files

See Also

Commenti

Sto caricando i commenti......
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.