diff --git a/proxywatchd.py b/proxywatchd.py index ae4aef7..7562657 100644 --- a/proxywatchd.py +++ b/proxywatchd.py @@ -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()