Gearman create a MySQL persistence queue in the following ways:
1. Log in to the MySQL command line and run:
Create Database Gearman;
2. Start Gearman with the following command:
/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 conditions to modify the line.
3. Log in to the MySQL command line again to execute:
Use gearman;show tables;
You can see a more "gearman_queue" table below.
In this way, the Gearman becomes a persistent way.
=============================================================================
After Gearman is persisted with MySQL, it will actually bring some problems.
1. Each task is written to the database, which leads to loss of disk IO, and one more possibility of gearman performance bottleneck, which is the performance problem caused by the database.
2. MySQL has a "wait_timeout" parameter that runs on the MySQL command line
Show variables like "%timeout%";
You can see the value of Wait_timeout, which is 28800 by default. That is, if a MySQL connection is more than 28800s without any response, it will be disconnected.
3. Gearman persistent Way, if more than the MySQL wait_timeouts time does not have any response, and the database connection will be disconnected by MySQL, and Gearman currently does not have MySQL reconnect, the result is, will cause the following error, Gearman must be restarted to re-operate.
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 disadvantage of Gearman persistence method is obvious, in this way, to avoid gearman to MySQL connection timeout, you can change the MySQL wait_timeout parameters.
Or, simply discard the persistence mode with MySQL.
http://www.ttlsa.com/gearman/gearman-mysql/
http://huoding.com/2012/10/30/196
Http://www.linuxeye.com/database/mysql-replication-to-redis-by-gearman.html
Gearman MySQL Persistence