viernes, 18 de febrero de 2011

Discusión sobre InnoDB Flush - MySQL

El parámetro de configuración innodb_flush_method puede tomar los valores O_DSYNC y O_DIRECT.
Es importante tunear la BBDD, y uno de los parámetros clave es innodb_buffer_pool_size, el cual debe rondar entre el 50% y el 80% de la RAM del sistema.
Leí en un post sobre performance de MySQL que explicaba que en algunos casos, era conveniente evitar el doble cacheo (uno por parte de MySQL y otro por parte del S.O).
Para evitar el cacheo del S.O, se puede especificar el método de flush como O_DIRECT, el cual dice al Kernel que haga el DMA directamente evitando overhead de cacheo.
Pero leyendo un artículo del mismísimo Linus Torvalds, no se si es buena idea realizar éste tipo de tuning. Supongo que dependerá de cada caso. Aquí lo dejo.

A thread on the lkml began with a query about using O_DIRECT when opening a file. An early white paper written by Andrea Arcangeli [interview] to describe the O_DIRECT patch before it was merged into the 2.4 kernel explains, "with O_DIRECT the kernel will do DMA directly from/to the physical memory pointed [to] by the userspace buffer passed as [a] parameter to the read/write syscalls. So there will be no CPU and memory bandwidth spent in the copies between userspace memory and kernel cache, and there will be no CPU time spent in kernel in the management of the cache (like cache lookups, per-page locks etc..)." Linux creator Linus Torvalds was quick to reply that despite all the claims there is no good reason for mounting files with O_DIRECT, suggesting that interfaces like madvise() and posix_fadvise() should be used instead, "there really is no valid reason for EVER using O_DIRECT. You need a buffer whatever IO you do, and it might as well be the page cache. There are better ways to control the page cache than play games and think that a page cache isn't necessary."

Linus went on to explain, "the only reason O_DIRECT exists is because database people are too used to it, because other OS's haven't had enough taste to tell them to do it right, so they've historically hacked their OS to get out of the way. As a result, our madvise and/or posix_fadvise interfaces may not be all that strong, because people sadly don't use them that much. It's a sad example of a totally broken interface (O_DIRECT) resulting in better interfaces not getting used, and then not getting as much development effort put into them."

No hay comentarios: