当前位置:网站首页>Distributed task distribution framework gearman
Distributed task distribution framework gearman
2022-07-03 17:49:00 【Brother Xing plays with the clouds】
Official documents :http://gearman.org/getting-started/ There are installation methods and examples , You can look at it in detail .
Gearman It's a framework for distributing tasks , It can be used in all kinds of situations , And Hadoop comparison ,Gearman More in favor of task distribution . Its task distribution is very simple , It's as simple as a script .Gearman Originally used for LiveJournal Pictures of the resize function , Due to pictures resize Need to consume a lot of computing resources , Therefore, it is necessary to schedule to multiple backend servers The server perform , After completing the task, return to the front end and present it to the interface .
Gearman What can be done
- Asynchronous processing : The image processing , The order processing , Bulk mail / Notice or something
- Demand is high CPU Or memory processing : Large capacity data processing ,MapReduce operation , Log aggregation , Video coding
- Distributed And parallel processing
- Timing processing : Incremental updating , Data replication
- Rate limiting FIFO Handle
- Distributed System monitoring task
1, Installation method
# install gearman
yum install gearmand
# install libgearman
yum install libgearman-devel
# install gearman php Expand
pecl install gearman
# add to gearman.so To php.ini
echo "extension=gearman.so" >> /etc/php.ini
No, pecl If so, pretend
yum install php-pear
If pecl If it cannot be installed , You can download the source code directly , Use phpize Compilation and installation
cd ~/software
wget http://pecl.php.net/get/gearman-1.1.2.tgz
cd gearman-1.1.2
phpize
./configure
make && make install
2, Simple use examples :( We use Gearman To asynchronously handle Baidu cloud push service )
First look at client.php Registration events ,client.php
<?php
// establish Gearman object
$client = new GearmanClient();
// addServer The default is localhost, The default port is 4730, If it is not the default, you can adjust
$client -> addServer();
// $client->addServer("192.168.0.0",4730);
echo "Sending job\n";
$username = "test";
$message = "message";
$data = array(
"username" => $username,
"message" => $message ,
);
// Registration events as well as Pass parameters , Multiple parameters use json_encode transformation
// Tasks can run in a blocking fashion , Priority can also be specified ; Of course , It can also be non blocking ( Run without waiting for results ) function
// You can refer to php Gearman api file : doNornal, doHigh, doLow,doBackground
$result = $client -> doBackground("testFunction", json_encode($data));
if ($result) {
echo "Success: $result\n";
}
?>
Look again worker To deal with , In fact, it is to register the event handler , worker.php
<?php
$worker = new GearmanWorker();
$worker->addServer();
// Register events and event handlers
$worker->addFunction("testFunction","handler");
// function worker
while ($worker->work());
function handler(GearmanJob $job) {
$workload = json_decode($job->workload());
echo "received: " . print_r($workload,1);
}
?>
It can be run from the command line php client.php , php worker.php , The best starting sequence here is to start first worker, In this way, the incident can be handled in time ; You can also start client, The event will be in Gearman In line , wait for worker Handle ;
You can also start multiple worker,Gearman Automatic load balancing , Assign to different worker To deal with .
You can explore more application scenarios ...
for example : adopt Gearman Realization MySQL To Redis Data synchronization for ( Asynchronous replication ) http://www.linuxidc.com/Linux/2015-01/111380.htm
Gearman Monitoring of :
have access to supervisor, You can also use gearman manager
Use supervisor monitor Gearman See :http://www.linuxidc.com/Linux/2015-01/111384.htm
边栏推荐
- Leetcode540: a single element in an ordered array
- Notes on problems -- watching videos on edge will make the screen green
- Applet setting multi account debugging
- Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026
- 毕业总结
- ArrayList分析3 : 删除元素
- Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
- 鸿蒙第三次培训
- Kubernetes resource object introduction and common commands (4)
- 聊聊支付流程的设计与实现逻辑
猜你喜欢
MySQL grouping query
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
微服务组件Sentinel控制台调用
Tensorboard quick start (pytoch uses tensorboard)
UE4 official charging resources, with a total price of several thousand
1164 Good in C
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
问题随记 —— 在 edge 上看视频会绿屏
[UE4] brush Arctic pack high quality Arctic terrain pack
Kubernetes resource object introduction and common commands (4)
随机推荐
1164 Good in C
[mathematical logic] equivalent calculus and reasoning calculus of predicate logic (individual word | predicate | quantifier | predicate logic formula | two basic formulas | proposition symbolization
[combinatorics] recursive equation (solution of linear non-homogeneous recursive equation with constant coefficients | standard form and general solution of recursive equation | proof of general solut
Talk about the design and implementation logic of payment process
Write a program to process a list container of string type. Find a special value in the container 9.27: and delete it if found. Rewrite the above procedure with deque container.
Golang单元测试、Mock测试以及基准测试
Investigation on the operation prospect of the global and Chinese Anti enkephalinase market and analysis report on the investment strategy of the 14th five year plan 2022-2028
Hongmeng fourth training
Kotlin's collaboration: Context
企业级自定义表单引擎解决方案(十一)--表单规则引擎1
Keepalived 设置不抢占资源
ArrayList analysis 3: delete elements
1147_ Makefile learning_ Target files and dependent files in makefile
Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13
Where is the monitoring page of RDS database?
How to purchase Google colab members in China
Servlet specification Part II
[UE4] brush Arctic pack high quality Arctic terrain pack
IntelliJ 2021.3 short command line when running applications
Managing multiple selections with MVVM - managing multiple selections with MVVM