문제

I'm using Gearman Job server in my project. I use 'gearman-ruby' gem. There is a queue of tasks in app. One task have 4 parts.
Appropriately I have 4 workers to solve this parts of task.

My system solve 1 task in 10minutes without gearman. But when I use gearman, time to solve 10 tasks are 2-3 hours :(
Gearman queue are located in mysql. The queue are overflows.

Cron starts clients, which set tasks. one task - parse one page. 1st worker - get page(init), 2nd - get photos(images), 3rd - get comments(text), 4rd - get characteristics(text). 1st worker get pages, other workers parse different data from this pages.

gearman configs:



    $cat /etc/sysconfig/gearmand 
    ## Settings for gearmand
    OPTIONS="--listen=127.0.0.1
             --job-retries=3 \
             --log-file=/var/log/gearman.log \
             --queue-type=MySQL \
             --mysql-host=localhost \
             --mysql-port=3306 \
             --mysql-db=gearman \
             --mysql-table=queue"

    $gearmand --version
    gearmand 0.35

Help me please to setup gearman for speed working

도움이 되었습니까?

해결책

  1. I found an event in my code, through which task doesn't return 'true'. In gearman protocol, compleated task must return 'true'.
  2. I setup gearman config without persistance storage.


    OPTIONS="--listen=127.0.0.1
                 --job-retries=3 \
                 --log-file=/var/log/gearman.log \
                 --threads=12"

З. I add more threads for gearman job-server with '--threads=threds_count' parameter.

And now my system works fast and stable! :)


If you using persistance storage and your queue are overflowing: you can periodically run script to clean gearman_queue. I solved it with periodically calling sh script ( I use cron for this ):



    # stop gearman
    sudo /etc/init.d/gearman stop
    # delete tasks from DB
    mysql -Bse 'DELETE FROM queue' gearman -u root
    # start gearmand back
    sudo /etc/init.d/gearman start
    echo '*** gearman queue cleaned. ***'

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top