Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NFS read timeout using c poll()

We have a NFS server which may sometimes have latency issues which then causes problem in my client, so Im trying to find a way to timeout, when it takes more time ( eg. > 200 ms) to read from NFS. Here is a minimal example which uses poll function to try to handle this issue:

struct pollfd pfd[1];
pfd[0].fd = fileno(file); //file opened previously using fopen 
pfd[0].events = POLLIN;
ret = poll(pfd, 1, 200); //wait for 200 milliseconds
if(ret == 0)
{
   fprintf(stderr, "poll timed out\n");
}

To test this I introduced latency of 400 ms using linux tc command.
My understanding with poll is that, with POLLIN event, and with the added 400 ms latency, there should be a timeout. But somehow it doesnot happen and ret is always > 0

Is using poll the correct way to handle NFS latency issues?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

No, poll() is not the correct choice. In POSIX a regular file is always considered ready, so poll() will return immediately but the actual I/O will still block.

You might do the I/O in a separate thread, or on Linux you could look into using io_uring.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading