load balancing
Moderator: General Moderators
load balancing
I have a very power-hungry dynamic sig in a very popular forum. My host gives me 4 gigs transfer a month and I've used 400 megs in a couple of hours. So I want to register four or five paralell hosts that all have the same files... then have a single, fast host that handles load balancing. Is there an easy way to do this in PHP, perhaps code that would cycle through hosts as they're used? Thanks in advance.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
maybe you should fix your sig so it's not so power-hungry.
Switching hosts to a larger bandwidth may be cheaper and better. Load balancing is best done in a closed environment, where the servers don't exist on the internet, but server through a gateway that does the load-balancing.
Although you can, technically load balance across multiple domains.. it's not practical most of the time.
There are many many hosts that offer 100GB or more of bandwidth for very low sums. But first, I'd suggest you fix your sig. You may need to switch to a slightly different model of creation where you only update the actual image every 10 minutes, in-between the script just tosses the last one it created via storing it on the server in some fashion.
Switching hosts to a larger bandwidth may be cheaper and better. Load balancing is best done in a closed environment, where the servers don't exist on the internet, but server through a gateway that does the load-balancing.
Although you can, technically load balance across multiple domains.. it's not practical most of the time.
There are many many hosts that offer 100GB or more of bandwidth for very low sums. But first, I'd suggest you fix your sig. You may need to switch to a slightly different model of creation where you only update the actual image every 10 minutes, in-between the script just tosses the last one it created via storing it on the server in some fashion.
re
The problem is that the sig has to query several quickly-updating pages across the internet... and the content in the sig (which is a gd-generated image) usually changes every second or two because of the updates in the source. So basically just what I'm looking for is code that will redirect to server 1 on the first request, server 2 on the second request, server 3 on the third request, server 1 on the foruth request, server 2 on the fifth request, and so on... merely to keep bandwidth use down. Purchasing more bandwith is not an option (i get multiple accounts free) so I need a software solution.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
why is it so important the image is absolutely up to date?
You can locally save the last created file, and only run out and get the data every minute or so.. at least then, you'll use a LOT less bandwidth because you're constantly going out of your server and fetching remote information.. all of that external communication costs time and bandwidth.
As I said, consider getting the script under control.
You can locally save the last created file, and only run out and get the data every minute or so.. at least then, you'll use a LOT less bandwidth because you're constantly going out of your server and fetching remote information.. all of that external communication costs time and bandwidth.
As I said, consider getting the script under control.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
store the last "server" tossed at in a database, or some other record.. toss to the next available one.. I'd suggest storing the list of urls in a database, along with the last one tossed to.. it'll make managment of them easier..
You should then be able to return a header() HTTP redirect to that server.
You should then be able to return a header() HTTP redirect to that server.
trouble
I'm having some trouble writing the code... i'm not very good with mysql. I've set up a database named frother_load and a one-field table called lastbounce. the field is called num and is a tiny int. this is what i have so far:
I really don't know how to read the contents of num (a single number: 1 2 3 4 or 5) to a php variable.
Code: Select all
$conn = mysql_connect("thehost.com","frother_load","xxxxxx");
mysql_select_db("frother_load",$conn);
mysql_query("update lastbounce set num = num+1",$conn);- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
SELECT num FROM lastbounce LIMIT 1Code: Select all
UPDATE lastbounce SET num = ((num + 1) % 5)reading
OK but that only increments it. How do I check the current status of the number? When I use this:
it prints "Resource id #2". How do I see what the number is at the time of script running?
Code: Select all
$conn = mysql_connect("thehost.com","frother_load","xxxxxx");
mysql_select_db("frother_load",$conn);
$curnum = mysql_query("SELECT num FROM lastbounce LIMIT 1",$conn);
print $curnum;
mysql_query("UPDATE lastbounce SET num = ((num + 1) % 5)",$conn);- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
mysql_fetch_*

Code: Select all
$result = mysql_query(...);
$record = mysql_fetch_assoc($result);
print_r($record);