dont track workloads unless multiprocessing

This commit is contained in:
ed 2021-06-08 18:01:59 +02:00
parent b97a1088fa
commit acd8149479
5 changed files with 23 additions and 13 deletions

View file

@ -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,
@ -75,7 +75,7 @@ class MpWorker(object):
if self.args.log_conn:
self.log("%s %s" % addr, "|%sC-qpop" % ("-" * 4,), c="1;30")
self.httpsrv.accept(sck, addr)
with self.mutex:

View file

@ -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

View file

@ -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,13 +85,14 @@ class HttpSrv(object):
cli = HttpConn(sck, addr, self)
with self.mutex:
self.clients[cli] = 0
self.workload += 50
if not self.workload_thr_alive:
self.workload_thr_alive = True
thr = threading.Thread(target=self.thr_workload)
thr.daemon = True
thr.start()
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)
thr.daemon = True
thr.start()
try:
if self.args.log_conn:

View file

@ -852,13 +852,14 @@ 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:
actor.workload += 1
if actor.workload > u32_lim:
actor.workload = 100 # prevent overflow
if is_mp:
actor.workload += 1
if actor.workload > 2 ** 31:
actor.workload = 100 # prevent overflow
tlen += len(buf)
hashobj.update(buf)

View file

@ -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