NAME

Gearman::Server - function call "router" and load balancer

DESCRIPTION

You run a Gearman server (or more likely, many of them for both high-availability and load balancing), then have workers (using Gearman::Worker from the Gearman module, or libraries for other languages) register their ability to do certain functions to all of them, and then clients (using Gearman::Client, Gearman::Client::Async, etc) request work to be done from one of the Gearman servers.

The servers connect them, routing function call requests to the appropriate workers, multiplexing responses to duplicate requests as requested, etc.

More than likely, you want to use the provided gearmand wrapper script, and not use Gearman::Server directly.

METHODS

new

$server_object = Gearman::Server->new( %options )

Creates and returns a new Gearman::Server object, which attaches itself to the Danga::Socket event loop. The server will begin operating when the Danga::Socket runloop is started. This means you need to start up the runloop before anything will happen.

Options:

  • port

    Specify a port which you would like the Gearman::Server to listen on for TCP connections (not necessary, but useful)

  • wakeup

    Number of workers to wake up per job inserted into the queue.

    Zero (0) is a perfectly acceptable answer, and can be used if you don't care much about job latency. This would bank on the base idea of a worker checking in with the server every so often.

    Negative One (-1) indicates that all sleeping workers should be woken up.

    All other negative numbers will cause the server to throw exception and not start.

  • wakeup_delay

    Time interval before waking up more workers (the value specified by wakeup) when jobs are still in the queue.

    Zero (0) means go as fast as possible, but not all at the same time. Similar to -1 on wakeup, but is more cooperative in gearmand's multitasking model.

    Negative One (-1) means that this event won't happen, so only the initial workers will be woken up to handle jobs in the queue.

create_listening_sock($portnum, %options)

Add a TCP port listener for incoming Gearman worker and client connections. Options:

accept_per_loop
local_addr

Bind socket to only this address.

new_client($sock)

init new Gearman::Server::Client object and add it to internal clients map

note_disconnected_client($client)

delete the client from internal clients map

return deleted object

clients()

return internal clients map

to_inprocess_server()

Returns a socket that is connected to the server, we can then use this socket with a Gearman::Client::Async object to run clients and servers in the same thread.

start_worker($prog)

$pid = $server_object->start_worker( $prog )

($pid, $client) = $server_object->start_worker( $prog )

Fork and start a worker process named by $prog and returns the pid (or pid and client object).

enqueue_job()

wake_up_sleepers($func)

on_client_sleep($client)

jobs_outstanding()

jobs()

jobs_by_handle($ahndle)

note_job_finished($job)

set_max_queue($func, $max)

  • $func

    function name

  • $max

    0/undef/"" to reset. else integer max depth.

new_job_handle()

job_of_unique($func, $uniq)

set_unique_job($func, $uniq, $job)

grab_job($func)

SEE ALSO

gearmand