Gearman에 대해 자세히 알아보려면 gearman 공식 웹사이트(gearman.org/
++++++++++++++++++++++++++++)를 방문하세요. ++ +++++++++++++++
Gearman 설치:
++++++++++++++++++++ ++ ++++++++++++++++++++++++++
기본 종속성 라이브러리:
yum install boost-devel libevent-devel sqlite-devel libuuid-devel wget https://launchpad.net/gearmand/trunk/0.33/+download/gearmand-0.33.tar.gz tar xzvf gearmand-0.33.tar.gz cd gearmand-0.33 ./configure make make install
++++++ +++ +++++++++++++++++++++++++++++++++++
Gearman Python 클라이언트 설치
++++++++++++++++++++++++++++++++++++++++++++
wget http://pypi.python.org/packages/source/g/gearman/gearman-2.0.2.tar.gz#md5=3847f15b763dc680bc672a610b77c7a7 tar xvzf gearman-2.0.2.tar.gz python setup.py install
직접 자동 설치 받기: easy_install gearman
서비스 시작: gearmand -d
작업자 시작: gearman -w -f wc -- wc -l &
-w는 작업자 시작을 의미하고, -f wc는 wc라는 작업을 시작한다는 의미이며, -- wc -l은 이 작업이 행 수를 계산하기 위해 wc -l을 수행한다는 것을 의미합니다.
클라이언트 시작: gearman -f wc < /etc/passwd
+++++++++++++++++++++++++ + +++++++++++++++++++
Python 작업 코드:
++++++++++++++++ ++++++++++++++++++++++++++++
import os import gearman import math class MyGearmanWorker(gearman.GearmanWorker): def on_job_execute(self, current_job): print "Job started" return super(MyGearmanWorker, self).on_job_execute(current_job) def task_callback(gearman_worker, gearman_job): print gearman_job.data return gearman_job.data my_worker = MyGearmanWorker(['192.168.0.75:4730']) my_worker.register_task("echo", task_callback) my_worker.work()
++++++++++++++ ++++++++++++++++++++++++++++++
Python 클라이언트 코드:
++ ++ ++++++++++++++++++++++++++++++++++++++++
from gearman import GearmanClient gearman_client = GearmanClient(['192.168.0.75:4730']) gearman_request = gearman_client.submit_job('echo', 'foo') result_data = gearman_request.result print result_data