1

We've got a real-time linux user application which communicates with another application running on the same host via mkfifo() FIFOs. Our application consists of 4 pthreads, and one of these creates and opens the FIFOs. The FIFOs are opened in non-blocking (O_NONBLOCK) mode.

write() on the pthread to the output FIFO typically take approx. 8 microseconds - this is for messages up to about 2500 bytes. The problem for us is that occasionally, but regularly, it takes 10 times that, and very infrequently it takes milliseconds. The message length isn't any longer than usual when this happens.

Presumably there's something going on 'under the hood' that causes this. Is there some way of avoiding it? It wouldn't matter if the average write() time increased somewhat, as long as we didn't see the very long times.

Any comments/suggestions gratefully received.

user1766169
  • 1,932
  • 3
  • 22
  • 44
matth1j
  • 31
  • 5
  • I suspect that the pipe's buffer is filling up, so the writers have to block until the reader drains it. Try increasing the size with `fcntl` and the `F_SETPIPE_SZ` constant. – Colonel Thirty Two Aug 10 '15 at 13:04
  • It's non-blocking, and we get an error if the FIFO becomes full. So we don't think it's that (if I understand you correctly). – matth1j Aug 10 '15 at 13:08
  • Is there a chance you're just running into the fact that Linux isn't a realtime operating system? Activity of other processes on the system can impact the timing of your tasks – larsks Aug 10 '15 at 13:12
  • We've tried to ensure that's not the case. We're using OpenWrt distro with real-time extensions, and the pthreads are created with SCHED_FIFO scheduling priority. We can see that while the thread doing the write() is writing, it isn't being interrupted by one of the higher priority threads. – matth1j Aug 10 '15 at 13:18
  • Stumbled upon this question: Have you profiled your system with cyclictest? Execution times jitter even under preempt RT - but milliseconds shouldn't happen. – Thomas Maierhofer Aug 07 '17 at 10:38
  • Thanks Thomas - no, we haven't, but it's a bit late for that now :) Not sure whether anyone got to the bottom of this. The project is in maintenance only now, and I'm working on something completely different. – matth1j Aug 08 '17 at 12:04

0 Answers0