8000 How do I weight servers? · Issue #7 · phpredis/phpredis · GitHub
[go: up one dir, main page]

Skip to content

How do I weight servers? #7

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

Closed
asuth opened this issue Apr 11, 2011 · 2 comments
Closed

How do I weight servers? #7

asuth opened this issue Apr 11, 2011 · 2 comments

Comments

@asuth
Copy link
asuth commented Apr 11, 2011

Hi,

I can see you can weight servers in the php session config settings, but how do you weight servers yourself? Sorry if I'm missing something, I don't see this documented.

It would be nice to do something like this:

    $redis = new Redis();
    foreach ($connection as $ip => $weight)
        $redis->pconnect($ip, $port, $timeout, $weight);
@nicolasff
Copy link
Member

Hello Andrew,

There is no way to do this other than by hand, but it isn't that complicated.

The session handler creates a "connection pool", where each server has a weight. Let's say that server A has weight 1, B has weight 2, and C weight 3. The sum of these weights is 6, so when a session is created, the session ID is transformed into a number (you can use crc32 for instance), and this number is reduced modulo 6 (the sum of our weights).
With $pos = crc32($sessid) % 6, if $pos == 0 then the session is stored on server A, if $pos = 1 or 2 on B, if $pos =3,4, or 5 then it's on C.

The reason why phpredis doesn't implement this for the key/value interface is that some of Redis' commands can map several keys (see sUnion for example, or sort). These wouldn't work as well in a multi-server environment, while the GET/SET interface for sessions doesn't have any ambiguity.

There will be a way to do it directly from phpredis in the future when part of the key is reserved for this specific purpose, but that's not the case at the moment.

@asuth
Copy link
Author
asuth commented Apr 12, 2011

Got it. I'll have to think about the best way to abstract this out. It seems it would be pretty easy to implement the server-key matching, even in a lightweight php script.

@bigfg bigfg mentioned this issue Aug 9, 2016
@liupdhc liupdhc mentioned this issue Apr 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0