`

What is Gearman?Gearman是什么?

阅读更多

Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work.

Gearman提供了能把任务分发(承包)给其他更适合做该任务的机器或程序来处理的一个通用应用程序框架。

 It allows you to do work in parallel, to load balance processing, and to call functions between languages.

它允许你并行操作,负载均衡处理以及在不同的语言调用函数。

 It can be used in a variety of applications, from high-availability web sites to the transport of database replication events.

它可以应用到诸如高性能网站,数据库复制事件传输等多类应用程序中。

 In other words, it is the nervous system for how distributed processing communicates.

换句话说,它就是分布式处理赖以交互的神经系统。

A few strong points about Gearman:

以下是几个关于Geaman的要点:

  • Open Source It’s free! (in both meanings of the word) Gearman has an active open source community that is easy to get involved with if you need help or want to contribute. Worried about licensing? Gearman is BSD.
  • 开源 It's free! (包括free的两个意思,自由和免费) Gearman有一个活跃的开源社区,不论你用寻求帮助或共享资源,你都可以很容易的加入其中。担心版权问题吗?Gearman是BSD开源模式的。
  • Multi-language - There are interfaces for a number of languages, and this list is growing. You also have the option to write heterogeneous applications with clients submitting work in one language and workers performing that work in another.
  • 多语言支持 它有支持很多语言的应用接口,并且还在不断强化中。你可以使用一种语言编写不同的客户端应用程序,而处理端的处理平台用另一种语言来编写。
  • Flexible - You are not tied to any specific design pattern. You can quickly put together distributed applications using any model you choose, one of those options being Map/Reduce.
  • 灵活的 - 不必局限于某种设计模式。你可以用你选择的模型很快的把分散的程序合并起来,众多方法中有一种就是Map/Reduce。
  • Fast - Gearman has a simple protocol and interface with an optimized, and threaded, server written in C/C++ to minimize your application overhead.
  • 快速的 - Gearman有一个简单的协议和用C/C++编写的线程优化的服务来减少你应用程序的开销。
  • Embeddable - Since Gearman is fast and lightweight, it is great for applications of all sizes. It is also easy to introduce into existing applications with minimal overhead.
  • 可嵌入式的 - 因其高效和轻量级的,Gearman对各种体积的程序都是极适用的。它也可以积小的开销嵌入到已存在的程序中。
  • No single point of failure - Gearman can not only help scale systems, but can do it in a fault tolerant way.
  • No limits on message size - Gearman supports single messages up to 4gig in size. Need to do something bigger? No problem Gearman can chunk messages.
  • 数据信息大小不限 - Gearman可以支持达4G的信息。需要更大吗?没问题,Gearman可以分块化。
  • Worried about scaling? - Don’t worry about it with Gearman. Craig’s List, Tumblr, Yelp, Etsy,… discover what others have known for years.

 

How Does Gearman Work?

Gearman如何工作?


A Gearman powered application consists of three parts: a client, a worker, and a job server. The client is responsible for creating a job to be run and sending it to a job server. The job server will find a suitable worker that can run the job and forwards the job on. The worker performs the work requested by the client and sends a response to the client through the job server. Gearman provides client and worker APIs that your applications call to talk with the Gearman job server (also known as gearmand) so you don’t need to deal with networking or mapping of jobs. Internally, the gearman client and worker APIs communicate with the job server using TCP sockets. To explain how Gearman works in more detail, lets look at a simple application that will reverse the order of characters in a string. The example is given in PHP, although other APIs will look quite similar.
 基于Gearman的程序包括三部分:一个client(发起者),一个worker(处理者),一个job server(分派者)。client端负责运行一个job并把它传送到server端。job server 端。job server端找到可以处理传送过来的job的worker,并且让worker处理该job。 worker处理client的请求并通过job server把处理结果返回给client。Gearman提供了可以和job server(也叫gearmand)交互的woker和client的API, 因而你不必处理网络或映射问题。在内部,client和worker的api通过TCP socket和job server进行交互。我们通过一个反转字串顺序的程序来加以解释Gearman的详细工作过程。该例子用PHP语言,其它的语言API也是大概如此。

 

We start off by writing a client application that is responsible for sending off the job and waiting for the result so it can print it out. It does this by using the Gearman client API to send some data associated with a function name, in this case the function reverse. The code for this is (with error handling omitted for brevity):

我们从写一个小client程序开始,这个程序负责发送一job(任务)并等待结果然后把结果打印出来。通过使用Gearman的client API来发送一些关联函数名的数据, 在这个小例子中函数名为"reverse"。代码如下:

 

 

<?php
// Reverse Client Code
$client = new GearmanClient();
$client->addServer();
print $client->do("reverse", "Hello World!");

 This code initializes a client class, configures it to use a job server with add_server (no arguments means use 127.0.0.1 with the default port), and then tells the client API to run the reversefunction with the workload “Hello world!”. The function name and arguments are completely arbitrary as far as Gearman is concerned, so you could send any data structure that is appropriate for your application (text or binary). At this point the Gearman client API will package up the job into a Gearman protocol packet and send it to the job server to find an appropriate worker that can run the reverse function. Let’s now look at the worker code:

 

这段代码初始化了一个client,用add_server设置它使用一个job server(没有参数表示用127.0.0.1默认端口),然后告诉client的API调用reverse函数来处理"Hello world!"数据。对Gearman来说,函数名和参数都都是任意的,所以你可以发送任何适合你应用程序的的数据结构(可以是文本或二进制数据)。在这里,Gearman client API 将把这个任务打包到一个Gearman协议包的job然后把它发送到job server来找个合适的可以运行reverse函数的worker。下面我们看看worker的代码:

 

<?php
// Reverse Worker Code
$worker = new GearmanWorker();
$worker->addServer();
$worker->addFunction("reverse", "my_reverse_function");
function my_reverse_function($job)
{
  return strrev($job->workload());
}
while ($worker->work());

 This code defines a function my_reverse_function that takes a string and returns the reverse of that string. It is used by a worker object to register a function named reverse after it is setup to connect to the same local job server as the client. When the job server receives the job to be run, it looks at the list of workers who have registered the function name reverse and forwards the job on to one of the free workers. The Gearman worker API then takes this request, runs the function my_reverse_function, and sends the result of that function back through the job server to the client.

代码定义了一个my_reverse_function函数来接收字串并返回该字串的的倒序。当以client方式连接到本地的job server后,worker就把它注册到本身且命名为reverse。当job server接收到请求的job包, 它就搜索那些已经注册reverser函数的worker,然后选择空闲的worker来处理请求的job包。Gearman worker API获取job请求,根据job请求的参数运行my_reverse_function,然后通过job server把函数的处理结果发送给client端。

 



 

As you can see, the client and worker APIs (along with the job server) deal with the job management and network communication so you can focus on the application parts. There a few different ways you can run jobs in Gearman, including background for asynchronous processing and prioritized jobs. See the documentation available for the various APIs for details.

如你所见,client和worker的APIs(通过job server)已经处理工作(job)管理和网络交互, 这样你可以把重点放到程序开发上来. 有几种方式可以运行工作(job), 包括异步处理和分期作业. 详细请看相关文档.

 

 

How Is Gearman Useful?

用途

The reverse example above seems like a lot of work to run a function, but there are a number of ways this can be useful. The simplest answer is that you can use Gearman as an interface between a client and a worker written in different languages. If you want your PHP web application to call a function written in C, you could use the PHP client API with the C worker API, and stick a job server in the middle. Of course, there are more efficient ways of doing this (like writing a PHP extension in C), but you may want a PHP client and a Python worker, or perhaps a MySQL client and a Perl worker. You can mix and match any of the supported language interfaces easily, you just need all applications to be able to understand the workload being sent. Is your favorite language not supported yet? Get involved with the project, it’s probably fairly easy for either you or one of the existing Gearman developers to put a language wrapper on top of the C library.

上面倒序字串的例子好像很多工作是运行一个函数,但还有许多其他可以用法。一个最简单的例子就是可以把Gearman当作不同语言之间的接口。如果你想让你的PHP web程序调用C语言写的函数,你可以用PHP的client API写client端, 用C写worker端,定一个job server在两者之间。当然,还有更多不同的方式来实现类似的功能,如可以用一个PHP client端和一个Python的worker端,或者可能是MySQL client端和一个Perl worker端。。。。

 

  • 大小: 24.8 KB
  • 大小: 13.3 KB
分享到:
评论

相关推荐

    gearman下载gearman下载

    gearman下载gearman下载gearman下载gearman下载gearman下载

    Gearman中文手册,Gearman中文详解,gearman手册chm

    Gearman中文手册,gearman手册chm,Gearman中文详解,分享gearman技术心得,主要是为了分享技术,所以不要大家的资源分。

    Gearman中文手册最新完整版chm

    Gearman中文手册,gearman手册chm,Gearman中文详解,分享gearman技术心得,主要是为了分享技术,所以不要大家的资源分。

    gearman 文档

    gearman 文档,gearman 是个集群计算框架,通过对其扩展能够充分利用集群计算

    GearMAN讲解及所带来的变革

    GearMAN讲解及所带来的变革 全面介绍Gearman原理、应用

    java-gearman-service-0.6.6.zip

    java-gearman-service-0.6.6.zip 包,gearman分为3部分,client - server - worker,创建 java 版本的client和worker部分。 其实在gearman中,client和worker的编写不复杂,但是不同厂商提供的API是不大相同的,本...

    Gearman环境搭建资料

    Gearman环境搭建可能会用到的资料. gearmand-1.1.12.tar.gz libevent-2.0.22-stable.tar.gz libuuid-1.0.3.tar.gz

    Laravel开发-php-gearman

    Laravel开发-php-gearman Gearman作业服务器工人助手

    Gearman C# API和示例

    Gearman 的C#开发API和一个简单自带demo,vs2008.

    java-gearman-service(gearman-java-service)

    java实现gearman的job实现的jar包,包括gearman server,client和work客户端API

    java-gearman-service jar

    gearman的java库有两个,一个是gearman service ,一个是gearman java,相比来说service版本更好用一些,并且网上的教程一般是用的这个版本。因此我打好了gearman service的包提供给需要的开发者使用。

    Laravel开发-laravel-gearman-rpc

    Laravel开发-laravel-gearman-rpc Laravel/Lumen Gearman RPC。基于https://github.com/mhlavc/gearman

    Gearman安装可能涉及到的安装包

    该资源包括安装Gearman时可能涉及到的软件包 具体包括gearmand、gearman、php、gperf、libevent

    Gearman java APIs和一个小Demo

    Gearman java API和一个小Demo

    gearman安装包 rpm

    安装gearman 如果没有mysql客户端,需要安装mysql客户端 yum install -y libevent-devel 上传gearman.zip,解压unzip gearman.zip rpm -ivh uuid-1.5.1-3.el5.x86_64.rpm rpm -ivh libgearman-1.1.8-2.el5.x86_64...

    Gearman PHP Extension

    Gearman是一个分发任务的程序框架,可以用在各种场合,与Hadoop相比,Gearman更偏向于任务分发功能。它的 任务分布非常 简单,简单得可以只需要用脚本即可完成。Gearman最初用于LiveJournal的图片resize功能,由于...

    gearman-1.1.2

    1)软件资源列表:《gearmand-1.1.12.tar.gz》,《gearman-1.1.2.tgz》。 2)安装操作系统环境:CentOS-6.5,(其它linux操作系统请自行尝试)。 3)本软件安装步骤详解:...

    GearmanManager, 用于管理gearman员工的PHP守护进程.zip

    GearmanManager, 用于管理gearman员工的PHP守护进程 PHP的 PHP需求PHP 5.5.9 ( 使用这里版本测试)POSIX扩展过程控制扩展pecl/gearman或者 Net_Gearman为什么使用 GearmanManager运行Gearman工作者可能是一个乏味的任

    gearman-mysql-udf-0.6.tar.gz

    Gearman 的 MySQL 插件

    gearmand, golang gearman作业服务器克隆.zip

    gearmand, golang gearman作业服务器克隆 gearmandgolang gearman-job-server克隆 :为什么要创建克隆?i like gearmand, but it lacks of monitor maintainability

Global site tag (gtag.js) - Google Analytics