This article briefly describes the method of gearman using mysql persistence and some problems caused by this. The specific analysis is as follows:
1. The way gearman creates Mysql persistence queue is as follows:
1. Log in to the mysql command line and run:
create database gearman;
2. Start gearman, the command is as follows:
/usr/local/gearman/sbin/gearmand -p 4730 -L 0.0.0.0 --log-file=/tmp/ --pid-file=/tmp/ -q MySQL --mysql-host=localhost --mysql-user=root --mysql-db=gearman --verbose DEBUG -d
The specific parameters can be modified according to your own server status.
3. Log in to the mysql command line again and execute:
use gearman; show tables;
You can see that there is an additional "gearman_queue" table below.
In this way, gearman becomes a way to persist.
2. After gearman uses mysql to persist, it will bring about the following problems:
1. Each task is written to the database, which will bring about disk IO loss, and there is another possibility of gearman's performance bottleneck, which is the performance problems caused by the database.
2. MySQL has a parameter of "wait_timeout" and run it in the mysql command line.
show variables like "%timeout%";
You can see the value of wait_timeout, the default is 28800. That is to say, if a connection with mysql will be disconnected if it exceeds 28800s.
3. The way gearman persists,If there is no response after the wait_timeouts of mysql, the connection to the database will be disconnected by mysql., and gearman currently does not have mysql reconnection, the result is that it will cause the following error, and gearman must be restarted to work normally again.
gearman reported an error:
ERROR 2014-04-01 02:10:02.897899 [ proc ] mysql_stmt_execute failed: -> libgearman-server/plugins/queue/mysql/:357 ERROR 2014-04-01 02:10:02.897910 [ proc ] gearman_server_job_add gearman_server_run_command(QUEUE_ERROR) -> libgearman-server/:301
Therefore, the disadvantages brought by gearman persistence are obvious. In this method,To avoid gearman's connection timeout disconnection to mysql, you can change the wait_timeout parameter of mysql to be larger。
Or, simply give up the persistence method of using mysql.