Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^3: Send x% of the users to A, the rest to B

by Laurent_R (Abbot)
on Oct 27, 2012 at 08:58 UTC ( #1001172=note: print w/replies, xml ) Need Help??

in reply to Re^2: Send x% of the users to A, the rest to B
in thread Send x% of the users to A, the rest to B

If you have only two locations, you probably don't need to convert the full session ID into an integer, but just a small part or it. I recently had to build a kind of hashing function for splitting my processing of a very large data chunk into 10 sub-processes. One of the mandatory IDs of my data was a telephone number. I simply used the last digit of the phone number to decide to which process to allocate a given record and obtained an excellent load balancing. The advantage is that the simpler the splitting function is, the less performance overhead you get.

  • Comment on Re^3: Send x% of the users to A, the rest to B

Replies are listed 'Best First'.
Re^4: Send x% of the users to A, the rest to B
by ltp (Beadle) on Oct 28, 2012 at 11:30 UTC

    Alternately, you could use the IP address of the user (assuming it is available). There's several ways in which you could use the IP address for this, the easiest of which may be to take the modulo of any combination/all/one of the octets.

    You could even then ensure you get some sort of consistency in approach for users on the same network by determining the network class, and then taking the modulo of the network portion of the IP address only. Hence users on the same network (even those with DHCP addreses) would always go to the same destination.

    You'll never get a perfect 50/50 spread with this approach, but you'll get a fair spread.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001172]
[Corion]: hippo: At least for the German translation, the wordplay is translated as well
[Discipulus]: always! but if i can ask choroba why you always use the inverted (to me) form 1 == $.?
[choroba]: To avoid accidental overwriting of the variable in if ($x = 3)
[karlgoethebier]: Corion: Auch in hessisch? Mer wasses net.
[Corion]: Hmm - I'm not sure, I haven't read the mundart/slang translations ;)
[Eily]: $F[1] =~ s/^0//r could be written as (0+$F[1]). It's less explicit though
[Discipulus]: ah! seems wise choroba, you play safe
[shmem]: Eily: also -+-$F[1]
[shmem]: hmm... there should be a glyph for "bembel" in unicode "miscellaneous symbols"

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2017-05-24 08:42 GMT
Find Nodes?
    Voting Booth?