This paper briefly introduces the method of Gearman using MySQL, and some problems caused by it, the detailed analysis is as follows:
First, Gearman create a MySQL persistence queue in the following ways:
1. Log into the MySQL command line and run:
2. Start Gearman, order as follows:
/usr/local/gearman/sbin/gearmand-p 4730-l 0.0.0.0--log-file=/tmp/gearmand-4730.log--pid-file=/tmp/ Gearmand-4730.pid-q MySQL--mysql-host=localhost--mysql-user=root--mysql-db=gearman--verbose debug-d
Specific parameters, according to their own server situation to modify the line.
3. Log in again to the MySQL command line and execute:
Use Gearman;
Show tables;
You can see a table with a "gearman_queue" below it.
In this way, the Gearman becomes a persistent mode.
Second, Gearman with MySQL after the persistence, will bring some of the following problems:
1. Each task is written to the database, which can lead to loss of disk IO, and a gearman performance bottleneck that is caused by a database performance problem.
2. MySQL has a "wait_timeout" parameter, running in the MySQL command line
Show variables like "%timeout%";
You can see the value of Wait_timeout, which defaults to 28800. In other words, if a MySQL connection, more than 28800s without any response, will be disconnected.
3. Gearman persistent Way, if more than MySQL wait_timeouts time without any response, and the database connection will be MySQL disconnected , and Gearman is currently no MySQL reconnect, the result is, Causes the following error, you must restart Gearman to work again.
Gearman Error:
ERROR 2014-04-01 02:10:02.897899 [proc] Mysql_stmt_execute failed:-> libgearman-server/plugins/queue/mysql/ queue.cc:357
ERROR 2014-04-01 02:10:02.897910 [proc] gearman_server_job_add Gearman_server_run_command (QUEUE_ ERROR)-> libgearman-server/server.cc:301
Therefore, the disadvantages of Gearman persistence is obvious, in this way, to avoid gearman MySQL connection Timeout Disconnect, you can change the MySQL wait_timeout parameters large .
Or, simply give up the persistent way of using MySQL.