client: chunked writes
This client-side code alone improves the typical transfer speed of a 51572-byte file from 91.85 seconds to 25.89 seconds. This appears to be heavily bottlenecked by the python side of the transfer--increasing the serial line speed has nearly zero affect on the total transfer time.
This commit is contained in:
parent
d912278afd
commit
328e9e18bd
15
client.py
15
client.py
@ -31,18 +31,25 @@ def sync(ser, b, wait=0.1):
|
|||||||
|
|
||||||
def symmetric(ser, b):
|
def symmetric(ser, b):
|
||||||
l = []
|
l = []
|
||||||
for i, c in enumerate(b):
|
mem = memoryview(b)
|
||||||
if i % 32 == 0:
|
i = 0
|
||||||
|
chunk_size = 16
|
||||||
|
|
||||||
|
while i < len(b):
|
||||||
|
if i % 128 == 0:
|
||||||
print(i, end=' ')
|
print(i, end=' ')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
while True:
|
while True:
|
||||||
if ser.in_waiting:
|
if ser.in_waiting:
|
||||||
res = ser.read(ser.in_waiting)
|
res = ser.read(ser.in_waiting)
|
||||||
l.extend(res)
|
l.extend(res)
|
||||||
if len(l) + 8 >= i:
|
if len(l) + chunk_size >= i:
|
||||||
break
|
break
|
||||||
|
|
||||||
ser.write(bytes([c]))
|
chunk_size = min(chunk_size, len(b) - i)
|
||||||
|
assert chunk_size > 0, chunk_size
|
||||||
|
ser.write(b[i:i+chunk_size])
|
||||||
|
i += chunk_size
|
||||||
|
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
res = ser.read(ser.in_waiting)
|
res = ser.read(ser.in_waiting)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user