Commit feda3a6f authored by Yoshinori Okuji's avatar Yoshinori Okuji

Updated to the latest.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@642 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 467b9d97
...@@ -96,7 +96,7 @@ class Balancer: ...@@ -96,7 +96,7 @@ class Balancer:
t.start() t.start()
if self.debug: if self.debug:
print "Beginning the mail loop to accept clients" print "Beginning the main loop to accept clients"
while 1: while 1:
conn, addr = self.socket.accept() conn, addr = self.socket.accept()
if self.debug: if self.debug:
...@@ -111,22 +111,27 @@ class Balancer: ...@@ -111,22 +111,27 @@ class Balancer:
time.sleep(60) time.sleep(60)
try: try:
self.lock.acquire() self.lock.acquire()
cur_time = time.clock() cur_time = time.time()
count_dict = {} count_dict = {}
for addr in self.server_list:
if addr not in self.disabled_server_dict:
count_dict[addr] = 0
expired_server_list = [] expired_server_list = []
for key,value in self.sticked_server_dict.items(): for key,value in self.sticked_server_dict.items():
if self.debug:
print 'cur_time = %f, value.atime = %f' % (cur_time, value.atime)
if cur_time > value.atime + 60 * 10: if cur_time > value.atime + 60 * 10:
expired_server_list.append(key) expired_server_list.append(key)
else: else:
if value.addr in count_dict: if value.addr in count_dict:
count_dict[value.addr] += 1 count_dict[value.addr] += 1
else:
count_dict[value.addr] = 1
for key in expired_server_list: for key in expired_server_list:
if self.debug: if self.debug:
print "Expiring %s" % str(key) print "Expiring %s" % str(key)
del self.sticked_server_dict[key] # Expire this entry. del self.sticked_server_dict[key] # Expire this entry.
# Find the max and the min. # Find the max and the min.
if self.debug:
print 'count_dict = %s, sticked_server_dict = %s, disabled_server_dict = %s' % (str(count_dict), str(self.sticked_server_dict), str(self.disabled_server_dict))
max = -1 max = -1
min = len(self.sticked_server_dict) + 1 min = len(self.sticked_server_dict) + 1
for addr,count in count_dict.items(): for addr,count in count_dict.items():
...@@ -138,7 +143,7 @@ class Balancer: ...@@ -138,7 +143,7 @@ class Balancer:
min_addr = addr min_addr = addr
# If the max is significantly greater than the min, move some clients. # If the max is significantly greater than the min, move some clients.
if max > min + 1: if max > min + 1:
num = max - min num = max - min - 1
for key,value in self.sticked_server_dict.items(): for key,value in self.sticked_server_dict.items():
if value.addr == max_addr: if value.addr == max_addr:
if self.debug: if self.debug:
...@@ -237,7 +242,7 @@ class Balancer: ...@@ -237,7 +242,7 @@ class Balancer:
self.lock.acquire() self.lock.acquire()
if self.debug: if self.debug:
print 'Disabling %s' % addr print 'Disabling %s' % addr
cur_time = time.clock() cur_time = time.time()
self.disabled_server_dict[addr] = cur_time self.disabled_server_dict[addr] = cur_time
finally: finally:
self.lock.release() self.lock.release()
...@@ -264,7 +269,7 @@ class Balancer: ...@@ -264,7 +269,7 @@ class Balancer:
self.lock.acquire() self.lock.acquire()
if self.debug: if self.debug:
print 'Registering %s with %s' % (signature, addr) print 'Registering %s with %s' % (signature, addr)
cur_time = time.clock() cur_time = time.time()
if signature in self.sticked_server_dict: if signature in self.sticked_server_dict:
info = self.sticked_server_dict[signature] info = self.sticked_server_dict[signature]
info.atime = cur_time info.atime = cur_time
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment