Distribution of load


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Distribution of load
# 1  
Old 09-03-2013
Distribution of load

I have load balancing requirement, where I need to do little arithmetic and get the results.
Code:
Server1 - OverLoad - 252
Server2 - OverLoad - 431
Server3 - AcceptLoad - 550
Server4 - AcceptLoad - 59
Server5 - AcceptLoad - 224
Server6 - OverLoad - 10
.....



Now I have a requirement to balance it. If it is overloaded then i need to know how much other server can accept.

As like, the script to evaluate and tell me
Code:
    Server1's load 252 can be moved to Server3 (all 252 since it has 550 has capacity)
    Server2's load 298 can be moved to Server3 (550- 252 = 298, since 252 is already occupied by server1's load)
    Server2's load 59 can be moved to Server4 (59, Maximum available is 59 only)
    Server2's load 74 can be moved to Server 5 (74 = 431 -298-59, after shared with Server3,4)
    Server6's load 10 can be moved to Server 5 (It has got more space to accommodate)

The number of servers may vary and script has to read all the lines and suggest a balancing limits.

or anyother suggestion to balance it well ? Any idea on this would be helpful
# 2  
Old 09-03-2013
Instead of balancing to numbers, balance to percent of load. Figure out what your allowable percentage is and balance to that percentage. Make sure to give yourself a little wiggle-room so you can assure that the servers run optimally until your next re-balance.
# 3  
Old 09-03-2013
can you provide a logic to achieve balancing using %?
# 4  
Old 09-03-2013
Best experience gained is through experience obtained. I'd suggest to at least give it a try yourself first. If you have, please post what you've tried. More than happy to review & suggest. Smilie
# 5  
Old 09-03-2013
This might serve as a starting point
Code:
awk     '                       {T[$1]=$3=="OverLoad"?-$5:$5}
         END{for (i in T)       {print i, T[i]}}
        ' file |
sort -n -k2 |
awk     '                       {T[NR]=$2
                                 S[NR]=$1
                                }
         END                    {D=NR; U=1
                                 while (T[U] < 0) {
                                   if (T[D] + T[U] >= 0) {print S[U] "->" S[D] ": " (-T[U]); T[D]+=T[U]; T[U++]=0}
                                   if (T[D] + T[U] <  0) {print S[U] "->" S[D] ": " ( T[D]); T[U]+=T[D]; T[D--]=0}
                                  }
                                }
        '
Server2->Server3: 431
Server1->Server3: 119
Server1->Server5: 133
Server6->Server5: 10

As my mawk does not have a builtin sort function, I had to fallback to the external sort. You can do this in one script if your awk provides a sort.
# 6  
Old 09-04-2013
Thanks RudiC. I will explore further based on your approach. Thanks again!
# 7  
Old 09-06-2013
hope below perl can help you some

Code:
my %overload;
my %idle;

sub handle{
	OUTER:
	foreach my $os (sort keys  %overload){
		foreach my $is (sort keys %idle){
			my $ol = $overload{$os};
			my $available = $idle{$is};
			if($available > $ol){
				print "$os ",$ol," can be done on $is\n";
				$idle{$is} = $available - $ol;
				delete $overload{$os};
				next OUTER;
			}
			elsif ($available == $ol){
				print "$os ",$ol," can be done on $is\n";
				delete $overload{$os};
				delete $idle{$is};
				next OUTER;
			}
			else{
				print "$os ",$available," can be done on $is\n";
				delete $idle{$is};
				$overload{$os} = $ol-$available;
				next;
			}
		}
	}
}

sub remain{
	my @ol = keys %overload;
	if($#ol>=0){
		print "Still have below to be accormodated\n";
		foreach(@ol){
			print $_,":",$overload{$_},"\n";
		}
	}
	
	my @id = keys %idle;
	if($#id>=0){
		print "Still have below idle\n";
		foreach(@id){
			print $_,":",$idle{$_},"\n";
		}
	}
}

while(<DATA>){
	chomp;
	my @arr = split("-",$_);
	@arr = map {s/\s+//g;$_} @arr;
	if($arr[1] eq 'OverLoad'){
		$overload{$arr[0]}=$arr[2];
	}
	else{
		$idle{$arr[0]} =  $arr[2];
	}		
}

handle();

remain();
__DATA__
Server1 - OverLoad - 252
Server2 - OverLoad - 431
Server3 - AcceptLoad - 550
Server4 - AcceptLoad - 59
Server5 - AcceptLoad - 224
Server6 - OverLoad - 1000

Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

VPS has load 200, httpd load no activity, netstat nothing

Hello, on my hostserver i see one VPS of mine got load of 200.00 and netstat nothing (not a single blank line on netstat command) after some time, netstat started showing connections, but i see no excessive IP connections. tail -f /var/log/httpd/access_log shows no activity /var/log/messages ;... (1 Reply)
Discussion started by: postcd
1 Replies

2. Shell Programming and Scripting

Need help in wrting Load Script for a Load-Resume type of load.

hi all need your help. I am wrting a script that will load data into the table. then on another load will append the data into the existing table. Regards Ankit (1 Reply)
Discussion started by: ankitgupta
1 Replies

3. UNIX for Dummies Questions & Answers

load Balance

Guys im trying to create a script that will load ballance 3 devices. Unix is still very alien to me having only been in this position for 3 months now. Not to mention the fact that i've been thrown in the deep end. Anyway so far i've managed to make a script that looks at all 4 devices and make a... (1 Reply)
Discussion started by: yorkyboy
1 Replies

4. UNIX for Dummies Questions & Answers

Load error

hi i am facing a problem when i run a shell script to load a table.the error is Record 1: Rejected - Error on table TRENDS."SHP_CUST_ORD_ITM". ORA-14400: inserted partition key is beyond highest legal partition key Record 2: Rejected - Error on table TRENDS."SHP_CUST_ORD_ITM", column... (4 Replies)
Discussion started by: musavir19
4 Replies

5. UNIX for Advanced & Expert Users

could not load hme

After installing Solaris patches, i faced this problem which the system could not load hme ( network interface). after booting up the system i try to configure the IP add. on hme (ifconfig hme inet ......),but it fails. the /etc/hostname.hme0 file exists & is ok & in Prom mode also after running... (1 Reply)
Discussion started by: nikk
1 Replies
Login or Register to Ask a Question