Trying to simulate constant byte rate. Confusion with time.sleep results

后端 未结 2 782
無奈伤痛
無奈伤痛 2020-12-22 01:49

Context

I\'m using windows 7 on my computer(the player) and linux(debian) on my college computer(the streamer), which I control using ssh.
I was trying to simu

2条回答
  •  失恋的感觉
    2020-12-22 02:05

    As you can read in the question you linked, there are no guarantees for sleep and it can vary widely depending on the OS. But 4 ms resolution seems sufficient if you want to send data every 20 ms. There should be no need to improve your sleep() accuracy.

    On Debian, at around 0.02 seconds input, your computer sleeps around 12 / 10 of the time you ask it to. 10 / 12 * 32 is 26.6, so it makes sense if you only receive 27 KB/s.

    Instead of sleeping 0.02 seconds, use an adaptive sleeping time. Measure how long the last iteration took (sleeping + sending the data), and shorten your sleeping time to make the whole iteration take 0.02 seconds.

提交回复
热议问题