Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specifying multiple servers for client #3

Closed
kdar opened this issue Dec 30, 2012 · 3 comments
Closed

specifying multiple servers for client #3

kdar opened this issue Dec 30, 2012 · 3 comments
Assignees

Comments

@kdar
Copy link

kdar commented Dec 30, 2012

It seems other gearman libraries have the capability to specify multiple job servers. It would be nice to maintain the same API gearman-go has, just in case we want to implement our own client connection strategies, but it would also be nice if gearman had one of its own.

The python gearman seems to poll the connections and wait until it gets a status back from the job server that it's been accepted. But some other libraries just pick a random server from the list. The official ruby gearman libraries just does a round robin.

@ghost ghost assigned mikespook Dec 30, 2012
@mikespook
Copy link
Owner

A ClientPool would be a good idea.

pool := client.NewPool()
pool.Add("127.0.0.1:4730")
pool.Do("ToUpper", []byte("abcdef"), JOB_LOW|JOB_BG)

Assign selection strategy:

pool.SelectionHandler = func(clients []client.Client) (index int)  {
    return rand.Intn(len(clients))
}

@kdar
Copy link
Author

kdar commented Dec 30, 2012

The only problem I see with this solution is it wouldn't work if a job server is currently offline while this process starts, since client.New will return nil if it cannot connect. The python library keeps a list of job servers, and only tries to connect them when a job is sent. It also attempts to reconnect to a job server if it was lost. It also keeps a history of lost connections and rotates the list so that it won't keep using broken servers over and over.

Let me know your thoughts.

@mikespook
Copy link
Owner

Ja, Changed!

Let the pool managing client's connections now.

mikespook added a commit that referenced this issue Jan 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants