mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 01:22:13 -06:00
dont track workloads unless multiprocessing
This commit is contained in:
parent
b97a1088fa
commit
acd8149479
|
@ -35,7 +35,7 @@ class MpWorker(object):
|
|||
signal.signal(signal.SIGINT, self.signal_handler)
|
||||
|
||||
# instantiate all services here (TODO: inheritance?)
|
||||
self.httpsrv = HttpSrv(self)
|
||||
self.httpsrv = HttpSrv(self, True)
|
||||
self.httpsrv.disconnect_func = self.httpdrop
|
||||
|
||||
# on winxp and some other platforms,
|
||||
|
|
|
@ -35,6 +35,7 @@ class HttpConn(object):
|
|||
|
||||
self.args = hsrv.args
|
||||
self.auth = hsrv.auth
|
||||
self.is_mp = hsrv.is_mp
|
||||
self.cert_path = hsrv.cert_path
|
||||
|
||||
enth = HAVE_PIL and not self.args.no_thumb
|
||||
|
@ -174,6 +175,11 @@ class HttpConn(object):
|
|||
self.sr = Unrecv(self.s)
|
||||
|
||||
while True:
|
||||
if self.is_mp:
|
||||
self.workload += 50
|
||||
if self.workload >= 2 ** 31:
|
||||
self.workload = 100
|
||||
|
||||
cli = HttpCli(self)
|
||||
if not cli.run():
|
||||
return
|
||||
|
|
|
@ -35,8 +35,9 @@ class HttpSrv(object):
|
|||
relying on MpSrv for performance (HttpSrv is just plain threads)
|
||||
"""
|
||||
|
||||
def __init__(self, broker):
|
||||
def __init__(self, broker, is_mp=False):
|
||||
self.broker = broker
|
||||
self.is_mp = is_mp
|
||||
self.args = broker.args
|
||||
self.log = broker.log
|
||||
|
||||
|
@ -84,8 +85,9 @@ class HttpSrv(object):
|
|||
cli = HttpConn(sck, addr, self)
|
||||
with self.mutex:
|
||||
self.clients[cli] = 0
|
||||
self.workload += 50
|
||||
|
||||
if self.is_mp:
|
||||
self.workload += 50
|
||||
if not self.workload_thr_alive:
|
||||
self.workload_thr_alive = True
|
||||
thr = threading.Thread(target=self.thr_workload)
|
||||
|
|
|
@ -852,12 +852,13 @@ def yieldfile(fn):
|
|||
|
||||
|
||||
def hashcopy(actor, fin, fout):
|
||||
u32_lim = int((2 ** 31) * 0.9)
|
||||
is_mp = actor.is_mp
|
||||
hashobj = hashlib.sha512()
|
||||
tlen = 0
|
||||
for buf in fin:
|
||||
if is_mp:
|
||||
actor.workload += 1
|
||||
if actor.workload > u32_lim:
|
||||
if actor.workload > 2 ** 31:
|
||||
actor.workload = 100 # prevent overflow
|
||||
|
||||
tlen += len(buf)
|
||||
|
|
|
@ -116,6 +116,7 @@ class VHttpConn(object):
|
|||
self.addr = ("127.0.0.1", "42069")
|
||||
self.args = args
|
||||
self.auth = auth
|
||||
self.is_mp = False
|
||||
self.log_func = log
|
||||
self.log_src = "a"
|
||||
self.lf_url = None
|
||||
|
|
Loading…
Reference in a new issue