Magento Chile Desarrolladores Magento

¿Tienes una pregunta?

Si usted tiene cualquier pregunta, escriba a continuación lo que está buscando!

MySQLTuner – Optimizando MySQL para Magento!


Cada vez que los clientes entran a tu tienda Magento y navegan por productos o categorías, están consultando tu base de datos en sql. Entonces si no tienes bien configurada MyQSL en tu servidor… tu tienda no estará riendiendo la velocidad que debería.

La solución se llama MySQLTuner que analiza tu MySQL y te dice exactamente lo que debes ir haciendo para aumentar la velocidad y rendimiento de tu servidor. Es como llevar el automovil a un afinamiento…

Ejemplo realizado para (dv) Server Extreme de Media Temple, plesk 8.6, arquitectura de 32 bit.

1.- bajar MySQLTuner por ssh así:

CÓDIGO:

wget mysqltuner.pl

2.- Luego dar permisos a lo bajado

CÓDIGO:

chmod 775 mysqltuner.pl

3.- Ejecuta MySQLTuner

CÓDIGO:

perl mysqltuner.pl

4.- Verás una pantalla parecida a esta, con el resultado del análisis que a realizado MySQLTuner y las recomendaciones a seguir (la pantalla a continuación es uno de los primeros análisis que realicé a mi servidor, al final entregaré la configuración de mi “my.cnf”) :

 >>  MySQLTuner 1.0.1 - Major Hayden
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.0.45
[!!] Switch to 64-bit OS - MySQL cannot currently use all of your RAM

-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 773M (Tables: 1051)
[--] Data in InnoDB tables: 741M (Tables: 16696)
[--] Data in MEMORY tables: 0B (Tables: 272)
[!!] Total fragmented tables: 73

-------- Performance Metrics -------------------------------------------------
[--] Up for: 1h 21m 47s (69K q [14.202 qps], 1K conn, TX: 111M, RX: 15M)
[--] Reads / Writes: 88% / 12%
[--] Total buffers: 91.0M global + 2.7M per thread (100 max threads)
[OK] Maximum possible memory usage: 359.7M (10% of installed RAM)
[OK] Slow queries: 0% (0/69K)
[OK] Highest usage of available connections: 23% (23/100)
[!!] Key buffer size / total MyISAM indexes: 8.0M/100.9M
[!!] Key buffer hit rate: 91.5% (22K cached / 1K reads)
[OK] Query cache efficiency: 78.1% (46K cached / 59K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 2K sorts)
[OK] Temporary tables created on disk: 15% (598 on disk / 3K total)
[!!] Thread cache is disabled
[!!] Table cache hit rate: 0% (64 open / 16K opened)
[OK] Open file limit used: 0% (2/1K)
[OK] Table locks acquired immediately: 100% (22K immediate / 22K locks)
[!!] InnoDB data size / buffer pool: 741.9M/2.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    MySQL started within last 24 hours - recommendations may be inaccurate
    Enable the slow query log to troubleshoot bad queries
    Set thread_cache_size to 4 as a starting value
    Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
    key_buffer_size (> 100.9M)
    thread_cache_size (start at 4)
    table_cache (> 64)
    innodb_buffer_pool_size (>= 741M)

5.- Como verán MySQLTuner me recomienda que ajuste algunos valores para aumentar el rendimiento de mi servidor. Entonces edité mi “my.cnf” así:

a) Primero hacer un backup de su “my.cnf”

CÓDIGO:

cp /etc/my.cnf /etc/my.cnf.bak

b) Copia este código a tu “my.cnf”

CÓDIGO:
###############################################################################
### /etc/my.cnf - MySQL configuration
### For: MySQL 5.0 on a server which is not dedicated to MySQL
###
### Esta fila fue rediseñada por Magento Chile basada en un ejemplo de (mt) Media Temple
###     para (dv) Dedicated-Virtual Extreme (2GB)
###
### Version 1.01
###
### This configuration will use up to approximately 40% of the system
### resources in a "worst-case" / maximum connetions scenario.
###
### Any line with configuration after a '#' indicates the default setting,
### but is included in this way for easy modification (and for reference).
###
##############################################################################
###
### To activate this configuration, you must first create the slow query log
### file and then restart mysql.  You only need to do this once after you
### begin using this configuration file.
###
### Copy and paste this command:
###     touch /var/log/mysql.slow-queries.log && chown mysql:mysql /var/log/mysql.slow-queries.log && /etc/init.d/mysqld restart
###
##############################################################################

[mysqld]
local-infile = 0
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock
user = mysql

# Disable Berkley DB functionality, saving memory
skip-bdb

#max_connections = 100

# tmp_table_size/max_heap_table_size: Default is 16MB, but this causes many
# temporary tables to be written to disk, and is ineffecient.
# Keep tmp_table_size and max_heap_table_size the same!
tmp_table_size = 128M # was 64M
max_heap_table_size = 128M # was 64M

### query-cache settings ###
query-cache-type = 1
query-cache-size = 84M # was 32M was 64M
query_cache_limit = 16M # was 1M was 8M

### Buffer size settings ###
#sort_buffer_size = 2M

# key_buffer_size is important for MyISAM tables.
key_buffer_size = 150M # was 16M
#join_buffer_size = 16M # was 2M

thread_cache_size = 8

# table_cache: Approximate by taking max_connections and multiplying by the
# largest number of tables that can be open for any join.
table_cache = 2048 # was 256 was 512 was 1024

### Timing options ###
interactive_timeout = 100
wait_timeout = 20
connect_timeout = 15

### Log slow queries ###
# Make sure you create this file before you start mysql or it will not work!
# Use the this command:   touch /var/log/mysql.slow-queries.log && chown mysql:mysql /var/log/mysql.slow-queries.log
log-slow-queries=/var/log/mysql.slow-queries.log

# Duration a query must run (in seconds) to get logged
long_query_time = 1

### InnoDB settings ###
# See http://dev.mysql.com/doc/refman/5.0/en/innodb-configuration.html
# for InnoDB settings; They largely depend on your application.
innodb_buffer_pool_size = 1G

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
open_files_limit = 8192

[isamchk]
key_buffer = 64M
sort_buffer = 64M
read_buffer = 16M
write_buffer = 16M

[myisamchk]
key_buffer = 64M
sort_buffer = 64M
read_buffer = 16M
write_buffer = 16M

6.- Crear un log para los resultados así:

CÓDIGO:

touch /var/log/mysql.slow-queries.log && chown mysql:mysql /var/log/mysql.slow-queries.log && /etc/init.d/mysqld restart

7.- Reiniciar MySQL, si quieres nuevamente (aunque ya lo hiciste en el punto 6 al crear el log):

CÓDIGO:

service mysqld restart

8.- Mi resultado es el siguiente, al volver arrancar MySQLTuner, con muchas mejoras, solo con algunos variables que se deben de ir ajustando, cada 24 horas, para ir testeando como va el desempeño (visitas, clientes alojados, tráfico, etc):

CÓDIGO:

 >>  MySQLTuner 1.0.1 - Major Hayden 
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering

-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.0.45-log
[!!] Switch to 64-bit OS - MySQL cannot currently use all of your RAM

-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 776M (Tables: 1053)
[--] Data in InnoDB tables: 742M (Tables: 16696)
[--] Data in MEMORY tables: 0B (Tables: 272)
[!!] Total fragmented tables: 76

-------- Performance Metrics -------------------------------------------------
[--] Up for: 3h 46m 54s (65K q [4.833 qps], 5K conn, TX: 154M, RX: 29M)
[--] Reads / Writes: 75% / 25%
[--] Total buffers: 1.4G global + 2.7M per thread (100 max threads)
[OK] Maximum possible memory usage: 1.6G (47% of installed RAM)
[OK] Slow queries: 0% (3/65K)
[OK] Highest usage of available connections: 5% (5/100)
[OK] Key buffer size / total MyISAM indexes: 150.0M/101.5M
[OK] Key buffer hit rate: 98.6% (50K cached / 710 reads)
[OK] Query cache efficiency: 68.2% (33K cached / 48K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 3K sorts)
[!!] Joins performed without indexes: 56
[OK] Temporary tables created on disk: 19% (1K on disk / 5K total)
[OK] Thread cache hit rate: 99% (5 created / 5K connections)
[!!] Table cache hit rate: 3% (2K open / 55K opened)
[OK] Open file limit used: 5% (216/4K)
[OK] Table locks acquired immediately: 100% (35K immediate / 35K locks)
[OK] InnoDB data size / buffer pool: 742.5M/1.0G

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    MySQL started within last 24 hours - recommendations may be inaccurate
    Adjust your join queries to always utilize indexes
    Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
    join_buffer_size (> 128.0K, or always use indexes with joins)
    table_cache (> 2048)

Sin dudas, MySQLTuner es una excelente herramienta para darle mas rendimiento a nuestro Magento.

*Información adicional

Cómo comprobar si el almacenamiento en caché de consultas está habilitado:

Entrar a MySQL:

CÓDIGO:

my

Luego escribir esto:

CÓDIGO:

SHOW VARIABLES LIKE 'have_query_cache';

Y debe desplegar esto:

+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| have_query_cache | YES   | 
+------------------+-------+
1 row in set (0.00 sec)

Para comprobar que la caché de consultas es realmente operativo, puede ejecutar el siguiente comando para el servidor MySQL:

CÓDIGO:

SHOW VARIABLES LIKE 'query_cache_size';

Y debe desplegar esto:

+------------------+----------+
| Variable_name    | Value    |
+------------------+----------+
| query_cache_size | 88080384 | 
+------------------+----------+
1 row in set (0.00 sec)

Para supervisar el rendimiento de caché de las consultas, use SHOW STATUS para ver las variables del estado de la caché:

CÓDIGO:

SHOW STATUS LIKE 'Qcache%';

Y debe desplegar al como esto:

+-------------------------+---------+
| Variable_name           | Value   |
+-------------------------+---------+
| Qcache_free_blocks      | 663     | 
| Qcache_free_memory      | 2480024 | 
| Qcache_hits             | 304811  | 
| Qcache_inserts          | 82853   | 
| Qcache_lowmem_prunes    | 17760   | 
| Qcache_not_cached       | 42740   | 
| Qcache_queries_in_cache | 37996   | 
| Qcache_total_blocks     | 78581   | 
+-------------------------+---------+
8 rows in set (0.01 sec)

Atte

Boris D.

Resumen
Fecha de Opinión
Wiki Opinado
Good!
Evaluación Lector
51star1star1star1star1star
MySQLTuner – Optimizando MySQL para Magento!
5 (100%) 6 votos

Comentarios

Comentarios

Leave a Reply

You must be logged in to post a comment.