-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues with Windows timeout behavior #55
Comments
After some review, I have determined that the read size is set by the And behold, if I modify this to
The discrepency between 8192 and 8191 bytes is now well within measurement error. I can't see any obvious way to modify this value without changing |
Thanks for the detailed report. This is ... awful. |
@estokes No problem, maybe this will help some other poor soul someday. To that end, I have one additional note for anyone (like me) who is attempting to implement a Decoder on a Windows serialport. Because If you don't want your decoder to shutdown on timeouts, you could disable read timeouts entirely: ReadIntervalTimeout: 0, But if you do this reads will not complete, until they have read enough data to fill the buffer requested by loop { while let Some(item) = stream.next().await {
// code goes here
} } The |
This is still an issue. For those who need a solution, I just updated the hack to get windows serial running smoothly to tokio [patch.crates-io]
mio = { git = 'https://github.com/vadixidav/mio.git', branch = 'issue#1582_named_pipe_set_buffer_size' }
tokio = { git = 'https://github.com/vadixidav/tokio.git', branch = 'mio#1608_hack' } If you depend on this, please upload the branches elsewhere. I may update them to a newer version of |
Windows has weird serial port behavior, workarounds are discussed for the other serialport-rs crate. With some judicious settings you can make windows behave more sanely. |
I'm seeing what might be related, also on Windows: All reads take a minimum of 27-30 milliseconds to complete, no matter how fast the serial device is. This severely impacts my performance to the point of being unusable since I need to send a reply quickly to maintain throughput on my device (USB serial, with no actual UART, so 12 MBps USB speeds are theoretically possible). |
I believe that is a different issue. This issue is that until the buffer is filled, Windows will not send you the data for a very long time, which I have found to be on the order of half a second. It is possible you are seeing the same issue but your timeout is smaller. Regardless, the system I am working with cannot operate without this hack, so I am hoping for a solution. My vote is still to just make the windows buffer size 1 through the added API. As it stands, Windows is broken, so I believe even a hacky solution is better than being broken. |
I have filed PRs to the issue of read calls not returning until buffer filled on serialport/serialport-rs#79 and berkowski/mio-serial#38. It may also address this issue. |
So I am having some issues with performance when reading interrupted byte streams from the serial port. Consider this example:
Cargo.toml
main.rs
If we run this program we can see the following:
It takes longer (by ~17ms (!)) to write/read one byte less of data! If we examine the syscalls, I think we can find the culprit:
The serial library is issuing read requests for 4096 bytes, which of course time out when only 4095 bytes are available -- the problem is that this timeout should* be 1ms, but in practice appears to be quite long.
*based on: https://github.com/berkowski/mio-serial/blob/8cb54a5667e66632016db5ee5b9977c67713ceec/src/lib.rs#L810
So this leaves me with two questions:
pending
read is returned as soon as there is more data.The text was updated successfully, but these errors were encountered: