ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've noticed that opening a file in linux and setting the file descriptor to non blocking does not appear to work the way I would expect, I am seeing read and write calls block for up to 6 seconds waiting for a 65K write to complete. The aggregate IO rate for the RAID 0 I am doing IO to is reasonable, and the measurement mentioned above is rare, but I am using non blocking IO because I am in my server's execution state machine so I cannot afford to block that long. I have noticed that sockets under Linux work the way I expect. My solution will be to defer IO to separate threads so that I can maintain responsive service to clients. I was wondering if other developers have experienced similar issues with file IO under Linux and what solutions they may have come up with.
O_NONBLOCK or O_NDELAY
When possible, the file is opened in non-blocking
mode. Neither the open nor any subsequent opera_
tions on the file descriptor which is returned will
cause the calling process to wait. For the han_
dling of FIFOs (named pipes), see also fifo(4). This mode need not have any effect on files other
than FIFOs.
Yes, I'm not sure where the quote came from, but setting the O_NONBLOCKING flag has no effect on the descriptor of a regular file. What still bothers me is that I am seeing the write function block for up to 30 seconds for an 8000 byte write! Last night I saw roughly 15 times where a small write took over 10 seconds up to 30 seconds on one of my servers. This measurement is wrapped around a write function call. I can't help but think there is something very wrong here. Unfortunately, my background is in device drivers, so I'm used to being on the other end of the call.
Thanks for the reply, I've been a way for a while. Last night I had a 40K (thats K not MB!) write take 38 seconds. The measurements I am getting are wrapped around a write call, so synchronization (at least at the application level) should not be the issue. The partition is configured as a RAID 0, and we are writing to 2-4 SATA drives. We are running Fedora core 2. The aggregate IO rate averages out to a reasonable value (30-60 MBS), but occasionally I see this anomaly. I'm concerned that using aio_write, or deferring my disk IO to separate threads may just be band-aiding a system level flaw in our overall architecture.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.