January 22nd, 2013, 11:58 AM
Setting up simple load balancing
I'm putting up a beta site on a few VPS servers. Server 1 is for log in. When a user hits Server 1, a need to have a simple program to look at things like the CPU utilization, memory usage, and bandwidth utilization at that point on Server 2 and Server 3 and send the user to either Server 2 or Server 3 depending on which server has lower usage. I will have full root / administrative access to the servers.
> Does anyone have simple PHP programs similar to this that I could modify?
> Where is the best place for this to sit on Server 1?
Thanks for any suggestions!
January 22nd, 2013, 12:39 PM
Why not use an actual load balancer software? PHP is the wrong language for this.
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question
or you're a Help Vampire.
Trying to argue intelligently? Please read this.
January 22nd, 2013, 12:55 PM
I'm trying to keep costs down while I prove out the concept. If the load balancing software costs and implementation costs (since I'll need to pay someone to do this) aren't expensive, I would consider it.
If anyone has any suggestions on specific open-source or low-cost software, please let me know.
January 22nd, 2013, 01:04 PM
I have no first hand knowledge but Source Forge's Distributor might do what you want.
There are 10 kinds of people in the world. Those that understand binary and those that don't.
January 22nd, 2013, 01:19 PM
If you're just writing a script to decide whether or not to redirect the user to www2.site.com or www3.site.com PHP will work OK. If you're trying to balance the load transparently (ie: both servers at the same address), then don't use PHP for this.
For the first case, you might want to set up a cron job on servers 2 and 3 that runs every minute and transmits resource usage details to server 1. Server 1 can then use that information to determine which server to send new traffic to.
January 22nd, 2013, 02:12 PM
E-Oreo - If I am (a) doing a re-direct from Server 1 to Server 2 or 3, or (b) having users log in on Server 1 and then send them to Server 2 or 3, PHP would work. Is that right?
As I've researched a bit further, it looks like it could be done pretty easily in apache using mod_proxy_balancer (https://blogs.oracle.com/oswald/entry/easy_http_load_balancing_with), although this doesn't account for actual load on the servers; it just gives assignments based on counters. Have others used this method with success?
Also, I did see some options looking at Distriobutor, balance and pen.
January 23rd, 2013, 06:45 AM
you might be able to use haproxy also. Can't remember if it assesses system load on the 'backend' servers, or if it just does a basic layer 7 check off the top of my head though.