Alta carga de CPU mdl_grade_grades_history moodle 2.8

Alta carga de CPU mdl_grade_grades_history moodle 2.8

de Eduardo Miranda -
Número de respuestas: 3

Junto con saludar,


Quería comentar respecto a un problema que me apareció en esta nueva versión moodle 2.8, cada vez que los profesores acceden al historial de calificaciones la CPU de mi servidor de base de datos se va al 100% de uso, la query que se esta ejecutando es la siguiente:

MySQL mdl_grade_grades_history select

SELECT ggh.id, ggh.timemodified, ggh.itemid, ggh.userid, ggh.finalgrade, ggh.usermodified, ggh.source, ggh.overridden, ggh.locked, ggh.excluded, ggh.feedback, ggh.feedbackformat, gi.itemtype, gi.itemmodule, gi.iteminstance, gi.itemnumber, u.idnumber, u.email, u.firstnamephonetic,u.lastnamephonetic,u.middlename,u.alternatename,u.firstname,u.lastname, ug.firstnamephonetic AS graderfirstnamephonetic,ug.lastnamephonetic AS graderlastnamephonetic,ug.middlename...More...
SELECT ggh.id, ggh.timemodified, ggh.itemid, ggh.userid, ggh.finalgrade, ggh.usermodified, ggh.source, ggh.overridden, ggh.locked, ggh.excluded, ggh.feedback, ggh.feedbackformat, gi.itemtype, gi.itemmodule, gi.iteminstance, gi.itemnumber, u.idnumber, u.email, u.firstnamephonetic,u.lastnamephonetic,u.middlename,u.alternatename,u.firstname,u.lastname, ug.firstnamephonetic AS graderfirstnamephonetic,ug.lastnamephonetic AS graderlastnamephonetic,ug.middlename AS gradermiddlename,ug.alternatename AS graderalternatename,ug.firstname AS graderfirstname,ug.lastname AS graderlastname, (SELECT MAX(finalgrade) FROM mdl_grade_grades_history h WHERE h.itemid = ggh.itemid AND h.userid = ggh.userid AND h.timemodified < ggh.timemodified AND NOT EXISTS ( SELECT ? FROM mdl_grade_grades_history h? WHERE h?.itemid = ggh.itemid AND h?.userid = ggh.userid AND h?.timemodified < ggh.timemodified AND h.timemodified < h?.timemodified)) AS prevgrade, CASE WHEN gi.itemname IS NULL THEN gi.itemtype ELSE gi.itemname END AS itemname FROM mdl_grade_grades_history ggh LEFT JOIN mdl_grade_items gi ON gi.id = ggh.itemid JOIN mdl_user u ON u.id = ggh.userid LEFT JOIN mdl_user ug ON ug.id = ggh.usermodified WHERE gi.courseid = ? ORDER BY timemodified DESC, id DESC LIMIT ?, ?
Promedio de valoraciones: -
En respuesta a Eduardo Miranda

Re: Alta carga de CPU mdl_grade_grades_history moodle 2.8

de Ricardo Grandón -
saludos


bueno si bien la consulta es "grande" no debería de saturar el sistema, puedes probar con dos cosas


  1. Ejecuta la optimización de todas las tablas, limpieza y todo el arsenal que existe para eso
  2. Puedes ampliar los parametros de trabajo de tu servidor de mysql, si es mysql modifica los valores en el my.cfg existen un monton de tutos en google de como hacerlo cosa que que tenga más memoria de trabajo y la carga sea más parcializada.

En respuesta a Ricardo Grandón

Re: Alta carga de CPU mdl_grade_grades_history moodle 2.8

de Eduardo Miranda -

De ante mano muchas gracias por escribir, si la verdad de que antes de instalar moodle 2.8 se realizo un tunning a la base de datos, estoy trabajando con mariadb y puede ser que mi configuración del archivo my.cnf no se la adecuada o el tunning que realice no fue bien ejecutado, utilice mysqlturner para poder ajustar mis variables.


la configuración es la siguiente:

#

# The MySQL database server configuration file.

#

# You can copy this to one of:

# - "/etc/mysql/my.cnf" to set global options,

# - "~/.my.cnf" to set user-specific options.

# One can use all long options that the program supports.

# Run program with --help to get a list of available options and with

# --print-defaults to see which it would actually understand and use.

#

# For explanations see

# http://dev.mysql.com/doc/mysql/en/server-system-variables.html


# This will be passed to all mysql clients

# It has been reported that passwords should be enclosed with ticks/quotes

# escpecially if they contain "#" chars...

# Remember to edit /etc/mysql/debian.cnf when changing the socket location.

[client]

port= 3306

socket= /var/run/mysqld/mysqld.sock


# Here is entries for some specific programs

# The following values assume you have at least 32M ram


# This was formally known as [safe_mysqld]. Both versions are currently parsed.

[mysqld_safe]

socket= /var/run/mysqld/mysqld.sock

nice= 0


[mysqld]

#

# * Basic Settings

#

user= mysql

pid-file= /var/run/mysqld/mysqld.pid

socket= /var/run/mysqld/mysqld.sock

port= 3306

basedir= /usr

datadir= /var/lib/mysql

tmpdir= /tmp

lc-messages-dir= /usr/share/mysql

skip-external-locking

#

# Instead of skip-networking the default is now to listen only on

# localhost which is more compatible and is not less secure.

bind-address= 127.0.0.1


# * Fine Tuning

#

#key buffer 256M actualmente utiliza 191M SP

#indexes en memoria

key_buffer= 256M

key_buffer_size= 256M

#almancenar archivos mysql con un tamaño maximo

max_allowed_packet= 16M

#tamaño asignado para cada hilo 256K para sistemas de 64bits

#limita las complejidad de las sentencias que el servidor pueda manejar

#thread_stack= 192K

thread_stack           = 256K

#hasta el momento hay un 99% de hit rate por lo que no es necesario

#modificar este valor

thread_cache_size       = 32

#almacenamiento de la informacion transaccional (insert,update)

#tamaño bd ocupado el disco 11G

innodb_buffer_pool_size = 12G

# This replaces the startup script and checks MyISAM tables if needed

# the first time they are touched

myisam-recover         = BACKUP

#max_connections        = 200

#table_cache            = 131072

#promedio SP 170 se aumento a 230 rango de nuevas conexiones

max_connections        = 200

table_cache            = 41670

#hilos concurrentes, se recomienda tener entre 8 y 20 hilos concurrentes

thread_concurrency     = 16

#tmp_table_size= 4096M

#max_heap_table_size= 4096M

#tamaño de tablas temporales

#en caso de que las consultas no esten beneficiadas por indexes

#se recomienda establecer un tamaño con la siguiente formula

#tamaño memoria total / conexiones maximas

tmp_table_size         = 144M

max_heap_table_size    = 144M

#

# * Query Cache Configuration

#

query_cache_type= 1

query_cache_limit= 4096M

query_cache_size        = 1024M

query_cache_min_res_unit = 2K

#

# * Logging and Replication

#

# Both location gets rotated by the cronjob.

# Be aware that this log type is a performance killer.

# As of 5.1 you can enable the log at runtime!

#general_log_file        = /var/log/mysql/mysql.log

#general_log             = 1

#

# Error log - should be very few entries.

#

log_error = /var/log/mysql/error.log

#

# Here you can see queries with especially long duration

log_slow_queries= /var/log/mysql/mysql-slow.log

long_query_time = 2

#log-queries-not-using-indexes

#

# The following can be used as easy to replay backup logs or for replication.

# note: if you are setting up a replication slave, see README.Debian about

#       other settings you may need to change.

#server-id= 1

#log_bin= /var/log/mysql/mysql-bin.log

expire_logs_days= 10

max_binlog_size         = 100M

#binlog_do_db= include_database_name

#binlog_ignore_db= include_database_name

#

# * InnoDB

#

# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.

# Read the manual for more InnoDB related options. There are many!

#

sort_buffer_size= 16M

read_buffer_size= 16M

read_rnd_buffer_size= 16M

join_buffer_size= 16M


# * Security Features

#

# Read the manual, too, if you want chroot!

# chroot = /var/lib/mysql/

#

# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".

#

# ssl-ca=/etc/mysql/cacert.pem

# ssl-cert=/etc/mysql/server-cert.pem

# ssl-key=/etc/mysql/server-key.pem


skip-character-set-client-handshake

character_set_server = utf8

collation_server = utf8_unicode_ci


[mysqldump]

quick

quote-names

max_allowed_packet= 16M


[mysql]

#no-auto-rehash# faster start of mysql but no tab completition


[isamchk]

key_buffer= 16M


#

# * IMPORTANT: Additional settings that can override those from this file!

#   The files must end with '.cnf', otherwise they'll be ignored.

#

!includedir /etc/mysql/conf.d/


En respuesta a Eduardo Miranda

Re: Alta carga de CPU mdl_grade_grades_history moodle 2.8

de Ricardo Grandón -

hola nuevamente



tengo una duda y una recomendación


uno es que capacidades de ram/procesador tiene tu equipo así  te puedo indicar mejor cuales son los campos que tienes que optimizar si esa fuera la necesidad.


lo otro es que en moodle esta una configuración que ataca directamente este problema que tienes mira en 

y reduce un poco el número así lograras un mejo desempeño (Yo lo deje en 20).


y en

yo tengo de 30 usuarios no de 100 como es por defecto.


y por ultimo si con esos dos cambios aún la cosa sigue sobrecargando el sistema

esta esta opción

en la parte de


Deshabilitar historial de calificacionesdisablegradehistory

lo puedes habilitar para que se genere un poco de espacio que ya no esta siendo usado pero si procesado en la base de datos sobre el historial de los cambios en las calificaciones.


ya sin con eso (pero no recomendado)  es disminuir el tiempo que se mantiene el historial en la misma parte de "limpieza"


está la opción

Duración del historial de calificacionesgradehistorylifetim

lo puedes dejar en un año o 1000 días su es que tienen cursos que ya no necesites mantener el historial, pero repito esta opción es como el último recurso.