parent
2abf94d46c
commit
44022fe895
|
@ -316,19 +316,19 @@ def getBestServer(servers):
|
||||||
|
|
||||||
results = {}
|
results = {}
|
||||||
for server in servers:
|
for server in servers:
|
||||||
cum = 0
|
cum = []
|
||||||
url = os.path.dirname(server['url'])
|
url = os.path.dirname(server['url'])
|
||||||
for i in range(0, 3):
|
for i in range(0, 3):
|
||||||
uh = urlopen('%s/latency.txt' % url)
|
uh = urlopen('%s/latency.txt' % url)
|
||||||
start = time.time()
|
start = time.time()
|
||||||
text = uh.read().strip()
|
text = uh.read(9).strip()
|
||||||
total = time.time() - start
|
total = time.time() - start
|
||||||
if int(uh.code) == 200 and text == 'test=test'.encode():
|
if int(uh.code) == 200 and text == 'test=test'.encode():
|
||||||
cum += total
|
cum.append(total)
|
||||||
else:
|
else:
|
||||||
cum += 3600
|
cum.append(3600)
|
||||||
uh.close()
|
uh.close()
|
||||||
avg = round((cum / 3) * 1000000, 3)
|
avg = round((sum(cum) / 3) * 1000000, 3)
|
||||||
results[avg] = server
|
results[avg] = server
|
||||||
|
|
||||||
fastest = sorted(results.keys())[0]
|
fastest = sorted(results.keys())[0]
|
||||||
|
|
Loading…
Reference in New Issue