mirror of https://github.com/9001/r0c.git
optimize
This commit is contained in:
parent
c7ba75d637
commit
e1abd08a25
|
@ -53,3 +53,10 @@ config.py: BENCHMARK = True
|
|||
/c/Users/ed/AppData/Local/Programs/Python/Python39/python.exe -um r0c 2323 1531 k | tee plog
|
||||
bash run-stress.sh 2323
|
||||
python resample-log.py /dev/shm/r0c.log | bash plot.sh
|
||||
|
||||
|
||||
# quick loadgen
|
||||
m() { sleep 0.2; printf '%s\n' "$*"; };
|
||||
cli() { (exec 147<>/dev/tcp/127.0.0.1/1531; timeout 10 cat >/dev/null <&147& (m n; m qwer asdf; m a; m y; m a; m '/join #g'; echo $$ >&2; for ((a=0;a<1000;a++)); do date; sleep 0.5; done) >&147); }
|
||||
cln() { ps -ef | awk '/bash$/{print$2}' | while read p; do [ -S /proc/$p/fd/147 ] && kill $p; done; }
|
||||
cln; for ((c=0;c<64;c++)); do cli & sleep 0.13; done
|
||||
|
|
|
@ -227,39 +227,50 @@ class Core(object):
|
|||
|
||||
def select_worker(self):
|
||||
self.selector_alive = True
|
||||
while not self.shutdown_flag.is_set():
|
||||
timeout = 69
|
||||
clients = self.telnet_server.clients + self.netcat_server.clients
|
||||
if clients:
|
||||
# TODO: every once in a while a packet isn't delivered
|
||||
# until the client sends us a packet or the timeout hits
|
||||
timeout = 0.34
|
||||
|
||||
srvs = {}
|
||||
clis = {}
|
||||
for iface in [self.telnet_server, self.netcat_server]:
|
||||
srvs[iface.srv_sck] = iface
|
||||
for cli in iface.clients:
|
||||
clis[cli.socket] = cli
|
||||
|
||||
want_rx = [k for k, v in clis.items() if v.readable()]
|
||||
want_tx = [k for k, v in clis.items() if v.writable()]
|
||||
srvs = {}
|
||||
for iface in [self.telnet_server, self.netcat_server]:
|
||||
srvs[iface.srv_sck] = iface
|
||||
|
||||
acli = []
|
||||
dcli = {}
|
||||
while not self.shutdown_flag.is_set():
|
||||
acli = self.telnet_server.clients + self.netcat_server.clients
|
||||
|
||||
if len(acli) != len(dcli):
|
||||
dcli = {}
|
||||
|
||||
for ic in [self.telnet_server.clients, self.netcat_server.clients]:
|
||||
if ic and ic[-1].socket not in dcli:
|
||||
dcli = {}
|
||||
break
|
||||
|
||||
if not dcli:
|
||||
for c in acli:
|
||||
dcli[c.socket] = c
|
||||
|
||||
# TODO: every once in a while a packet isn't delivered
|
||||
# until the client sends us a packet or the timeout hits
|
||||
timeout = 0.34 if acli else 69
|
||||
|
||||
want_rx = [c.socket for c in acli if c.readable()]
|
||||
want_tx = [c.socket for c in acli if c.writable()]
|
||||
want_rx += list(srvs.keys())
|
||||
|
||||
try:
|
||||
rxs, txs, _ = select.select(want_rx, want_tx, [], timeout)
|
||||
if self.stopping:
|
||||
break
|
||||
|
||||
|
||||
for s in rxs:
|
||||
if s in srvs:
|
||||
srvs[s].handle_accept()
|
||||
else:
|
||||
clis[s].handle_read()
|
||||
|
||||
dcli[s].handle_read()
|
||||
|
||||
for s in txs:
|
||||
clis[s].handle_write()
|
||||
|
||||
dcli[s].handle_write()
|
||||
|
||||
except Exception as ex:
|
||||
if "Bad file descriptor" in str(ex):
|
||||
# print('osx bug ignored')
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import runpy
|
||||
|
||||
sys.path.insert(0, ".")
|
||||
sys.argv = ["r0c", "2323", "1531", "k"]
|
||||
runpy.run_module("r0c", run_name="__main__")
|
||||
|
||||
|
||||
"""
|
||||
python3.9 -m pip install --user vmprof
|
||||
python3.9 -m vmprof --lines -o vmprof.log test/vmprof-target.py
|
||||
~/.local/bin/vmprofshow vmprof.log tree | grep -vF '[1m 0.'
|
||||
"""
|
Loading…
Reference in New Issue