Selecting a Server by Job Unique

SYNOPSIS

#include <libgearman/gearman.h>

void gearman_client_set_server_selection_by_unique(gearman_client_st *client, bool enable)
bool gearman_client_server_selection_by_unique(const gearman_client_st *client)

DESCRIPTION

By default, when a client with more than one server added via gearman_client_add_server() submits a job, it is sent to the first idle server in the order the servers were added – the job’s unique identifier plays no part in the choice.

gearman_client_set_server_selection_by_unique() opts a client into choosing the destination server by hashing the job’s unique instead, using a ketama consistent-hash ring built from the client’s current server list. The practical effect is that submissions sharing the same unique (from this client, or from any other client configured with the same server list and this option enabled) consistently land on the same server, and adding or removing a server only reshuffles the jobs that server itself was responsible for.

This only affects job submission (gearman_client_do(), gearman_client_do_background(), and their variants, plus gearman_client_add_task() and friends); commands such as status lookups are unaffected. A job submitted with an empty unique falls back to the default selection, since there is no meaningful value to hash.

If the hash-selected server cannot be reached, the client fails over to the next server in ring order rather than failing the submission outright, the same way the default selection falls through the server list on a connection failure.

This option is disabled by default. It can also be enabled or disabled with the GEARMAN_CLIENT_SERVER_SELECTION_BY_UNIQUE flag via gearman_client_add_options() / gearman_client_remove_options() (and queried with gearman_client_has_option()), which is useful for language bindings that pass an options bitmask through to libgearman. Both ways change the same setting. It is copied by gearman_client_clone() like the client’s other persistent settings.

gearman_client_server_selection_by_unique() returns whether the option is currently enabled.

RETURN VALUE

gearman_client_server_selection_by_unique() returns a bool; it returns false for a NULL client.

HOME

To find out more information please check: https://gearman.org/gearmand/

See also

gearmand(8) libgearman(3) gearman_client_st gearman_client_add_server