1
0
mirror of https://github.com/facebook/zstd.git synced 2025-08-01 09:47:01 +03:00

rateLimiter does not "catch up" when input speed is slow

This commit is contained in:
Yann Collet
2018-08-13 11:38:55 -07:00
parent e7a49c6683
commit f3aa510738
3 changed files with 15 additions and 5 deletions

View File

@ -19,7 +19,7 @@ import time
MB = 1024 * 1024
rate = float(sys.argv[1]) * MB
rate *= 1.25 # compensation for excluding write time (experimentally determined)
rate *= 1.4 # compensation for excluding i/o time (experimentally determined)
start = time.time()
total_read = 0
@ -29,9 +29,14 @@ while len(buf):
to_read = max(int(rate * (now - start) - total_read), 1)
max_buf_size = 1 * MB
to_read = min(to_read, max_buf_size)
read_start = time.time()
buf = sys.stdin.buffer.read(to_read)
write_start = time.time()
write_start = read_end = time.time()
sys.stdout.buffer.write(buf)
write_end = time.time()
start += write_end - write_start # exclude write delay
wait_time = max(read_end - read_start, write_end - write_start)
start += wait_time # exclude delay of the slowest
total_read += len(buf)