Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
P is for Practical
 
PerlMonks  

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

by choroba (Abbot)
on Oct 26, 2012 at 10:24 UTC ( #1001035=note: print w/ replies, xml ) Need Help??


in reply to Send x% of the users to A, the rest to B

Cannot you just decide based on rand 100 < $percentage ?

لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Send x% of the users to A, the rest to B
Download Code
Re^2: Send x% of the users to A, the rest to B
by DreamT (Monk) on Oct 26, 2012 at 11:47 UTC
    It would work - But I need to remember the choice per user. As I think of it, I could of course store the selection for the current session(user) instead:)

      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.

        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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001035]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-04-18 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (460 votes), past polls