How To Split Randomly But Unevenly – PHP Code For Load UNBalancing

Base It On A Percentage

Right now, you pick numbers that represent some ‘absolute’ value. If you can relate the capacity of each server to something absolute, that’s great, but what if you just want to decide the whole, rather than each value – for example, have them all share 100% of the load?

You just tweak the array to suit – so for example


would become


Which adds to 100, but keeps about the same ratios – and so if you want one server at 95% capacity, just make sure the rest of the entries add up to 5%.

Speed It Up More

Want it fast? Create a table like this:

$i=$server[ mt_rand(0,$range) ];

Now the array contains the server index, and we pick randomly and evenly – but the number of entries will skew it to a particular server. You’ll notice that Server #0 gets called 1/8 of the time, #1 is 5/8 and #2 is 2/8th of the time, exactly as the first example.

To use this, just add more entries for the more powerful servers, and less for the lesser ones.

And to speed it up more, precalculate and store $server and $range, and you’ll only need the third line called each time, at least until you adjust $server.

1602 Blue Display w IIc Serial Adapter and Dupont jumpers Arduino
End Date: Wednesday Jan-10-2018 15:20:34 PST
Buy It Now for only: $3.25
Buy It Now | Add to watch list
Ultimate Starter Kit UNO R3 Arduino LCD Stepper Servo Ultrasonic Motor 1602
End Date: Wednesday Jan-10-2018 12:57:36 PST
Buy It Now for only: $33.99
Buy It Now | Add to watch list
Elegoo Mega 2560 R3 Board Atmega6U2 + Usb Cable For Arduino
End Date: Wednesday Jan-10-2018 12:53:57 PST
Buy It Now for only: $20.97
Buy It Now | Add to watch list

Leave a Reply

Your email address will not be published. Required fields are marked *