fix performance issue in proxywatchd

This commit is contained in:
rofl0r
2019-01-05 06:58:46 +00:00
parent 9ac3ed45d6
commit f45cd1190c

View File

@@ -158,16 +158,6 @@ class Proxywatchd():
self.mysqlite.execute(query, (job.failcount, job.nextcheck, 1, "unknown", job.proto, job.duration, job.proxy))
self.mysqlite.commit()
def find_best_thread(self):
least_jobs = 9999999999999999999
least_tid = 0
for i in range(len(self.threads)):
cnt = self.threads[i].jobcount()
if cnt < least_jobs:
least_jobs = cnt
least_tid = i
return least_tid
def run_background(self):
t = threading.Thread(target=self.run)
t.daemon = True
@@ -197,9 +187,12 @@ class Proxywatchd():
if len(self.jobs) == 0:
self.prepare_jobs()
while len(self.jobs):
tid = self.find_best_thread()
self.threads[tid].add_jobs([self.jobs.pop()])
if len(self.jobs):
jpt = len(self.jobs)/config.watchd_threads
if len(self.jobs)/float(config.watchd_threads) - jpt > 0.0: jpt += 1
for tid in range(config.watchd_threads):
self.threads[tid].add_jobs(self.jobs[tid*jpt:tid*jpt+jpt])
self.jobs = []
if config.watchd_threads == 1: # single_thread scenario
self.threads[0].workloop()