负载的方式
Job Server 可以开启多个实例,这样在其中一个发生故障的时候,可以 Failover 到其他的机器上。同时 Worker 也可以是多个实例进行运行,因为当前的服务器很多都是多核的
编译安装gearman的步骤和错误解决方法!
centos2.6 64位系统
1.安装 libevent-1.4.12-stable.tar.gz
2.安装gearmand-0.9.tar.gz
configure 报错 fatal error: uuid/uuid.h: No such file or directory
解决方法:
wget http://downloads.sourceforge.net/e2fsprogs/e2fsprogs-1.41.14.tar.gz
tar xvzf e2fsprogs-1.41.14.tar.gz
进入e2fsprogs-1.41.14目录后执行
/configure --prefix=/usr/local/e2fsprogs
make
make install
然后把uuid目录拷过去
cp -r lib/uuid/ /usr/include/
make时 报错 libgearman/.libs/libgearman.so: undefined reference to `uuid_generate'
libgearman/.libs/libgearman.so: undefined reference to `uuid_unparse'
解决方法: 重新编译e2fsprogs并加入参数
cd e2fsprogs-1.41.14
./configure --enable-elf-shlibs
make
make install
cp -rf lib/libuuid.so* /usr/lib
cd gearmand-0.29
make clean
./confugure --prefix=/usr/local/gearmand
make & make install
安装成功,此处最好重新configure,否则有可能还是报一样的错
3.安装php 的gearman 扩展 gearman-0.5.0.tgz
1234567891011121314151617181920212223Common options to both client and worker modes.-f <function> - Function name to useforjobs (can give many)处理任务的函数名-h <host> - Job server host (Job Server主机,默认是localhost)-H - Print thishelp menu-p <port> - Job server port (Job Server端口,默认是4730)-t <timeout> - Timeout inmilliseconds (执行多长时间超时,微秒)-i <pidfile> - Create a pidfile forthe process (创建进程的pid文件)Client部分参数Client options:-b - Run jobs inthe background (后台运行任务)-I - Run jobs ashigh priority (高优先级运行任务)-L - Run jobs aslow priority (低优先级运行任务)-n - Run one job per line (逐行执行任务)-N - Same as-n, but strip off the newline-P - Prefix all output lines withfunctions names (在输入结果前面加处理的函数名)-s - Send job without reading from standard input 执行任务不返回结果-u <unique> - Unique key to useforjob 任务的唯一标识Worker部分参数Worker options:-c <count> - Numberof jobs forworker to run before exiting (统计worker进程处理多少个任务后中止)-n - Send data packet foreachline-N - Same as-n, but strip off the newline-w - Run inworker mode 以worker模式运行 客户端的代码:
1234567from gearman importGearmanClientimportos,sysnew_client = GearmanClient(['10.2.20.115:7003'])current_request = new_client.submit_job('echo', sys.argv[1])new_result = current_request.resultprint new_result worker的代码:
12345678910111213importosimportgearmanimportmathclassCustomGearmanWorker(gearman.GearmanWorker):def on_job_execute(self, current_job):print "Job started"returnsuper(CustomGearmanWorker, self).on_job_execute(current_job)def task_callback(gearman_worker, job):print job.datareturnjob.datanew_worker = CustomGearmanWorker(['10.2.20.115:7003'])new_worker.register_task("echo", task_callback)new_worker.work() 这里再测试下 一次多task的发送
12345678910from gearman importGearmanClientimportos,sysnew_client = gearman.GearmanClient(['10.2.20.115:7003'])new_jobs = [dict(task='echo', data=sys.argv[1]),dict(task='echo', data=sys.argv[2]),]completed_requests = new_client.submit_multiple_jobs(new_jobs)forcurrent_request incompleted_requests:assert current_request.result == current_request.job.data http://rfyiamcool.blog.51cto.com/1030776/1243761
工作端
工作端
客户端
测试他的稳定行和执行的效率~ 一头往里扔数据,一头取数据。。。。
以前在r710集群中的监控中,表现还是不错的。能承担主的很大压力。。 但是个人总结,要是你做的东西过于多的话,还是自主开发,可以用mq消息系统,比如redis的pub sub 配合队列中的rpush rpop 。。。
cpu 流量 io 内存~~~