Gearman (Part 1): Setup Gearmand

Other posts in this series

Gearman has occupied my thoughts and time lately. Gearman is a “generic application framework to farm out work to other machines or processes that are better suited to do the work”.

In short, it’s a job-queue system. You send it jobs you want done, it delegates those tasks to workers who know how to handle that work. Workers connect to the server and announce what jobs it can handle; The server doesn’t care about “how” they handle that job, just that they can. The server passes the job off to the worker and can then (conditionally) pass messages back to the client for messages like status, completions, or failures.

Classic usage examples for websites are image resizing or video conversion. Instead of the user waiting for the server to re-size or convert, you redirect them elsewhere with a message saying it will be done soon. This lets the user go about their business, and you can delegate the work to another machine, leaving your web server to serve webpages instead hog memory converting things.

##Setup If you’re on a Mac, I highly recommend Homebrew, an excellent package manager for installing all kinds of software with ease. Getting Gearmand (the daemon process and client libraries) is easy:

~$ brew install gearman

If you’re using MacPorts

~$ (sudo) port install gearmand

If you’re on Ubuntu you can use


~$ sudo aptitude install gearman-job-server (gearman-dev)

Check your favorite Linux Distro’s package manager for their equivalent.

Finally, you can always compile from source

~$ tar xzf gearmand-X.Y.tar.gz  
~$ cd gearmand-X.Y  
~$ ./configure  
~$ make  
~$ (sudo) make install  

Once that finishes, you should have Gearman all setup

~$ gearmand --version
gearmand 0.15 -

##Running Gearmand is typically run as a daemon in the background

~$ gearmand -d

This causes Geramand to run to detach from the current shell and run in the background. While developing, it may be helpful to run in debugging mode

~$ gearmand -vvv
 INFO Starting up
 INFO Listening on :::4730 (6)
 INFO Listening on (7)
 INFO Creating wakeup pipe
 INFO Creating IO thread wakeup pipe
 INFO Adding event for listening socket (6)
 INFO Adding event for listening socket (7)
 INFO Adding event for wakeup pipe
 INFO Entering main event loop

By default, Geramand listens on

and port
. There are many other options you can choose to add.

So now you have Geramand setup. Go forth, and write clients and workers. Other documentation can be found here, including an incomplete list of libraries (for instance, it’s missing gearman-ruby).



My name is Clint Shryock. I develop things in Go and Ruby. I live in central Missouri, where the weather is beautiful 4 months of the year.
|                       |
|      (ノ^_^)ノ      |
|                       |
|   ☜(゚ヮ゚☜)    |
|                       |
|     ౿(ఠ_ఠఎ)    |
|                       |
|        ಠ_ಠ         |
x                      x
  xxx           xxx
       xx    xx