• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

writing to multiple filehandles - buffer

I have filehandles in an array that access named pipes. I need to write to them in a round robin fashion, and not block because the reader of its named pipe is being slow (with in reason).

I believe I need large buffers on each filehandle. Is this correct? How do I do it?
0
modsiw
Asked:
modsiw
  • 2
1 Solution
 
Carl BohmanCommented:
I'm not aware of any way to buffer the output in the way you are asking.  The operating system is likely where you need to look, since it is the operating system is in control of the buffering for named pipes (to the best of my knowledge).  One page I found on a quick search hinted that the buffer may be linked to the page size, but this may or may not be true for a given operating system.
0
 
modsiwAuthor Commented:
I want to buffer inside the perl application before it writes out to the OS. It already does this, but I need to increase that buffer.
0
 
Carl BohmanCommented:
There are the setvbuf methods in Perl's FileHandle and IO::Handle modules.  Perhaps you could use this to do what you are looking for?  I'm not certain that Perl has a way of changing the output buffer size.

Otherwise, you might want to look into something like creating separate threads that do the buffering for you.  One way to do this would be to have a shared array (see threads::shared module) that the originating thread pushes to.  The writer thread then waits for the array to be non-empty and shifts the values off of it to write to the named pipe.  This way, only the thread gets blocked if the pipe is full while the shared array is your buffer (which is bounded only by available memory by default).

Of course this is only one approach (which I've never tried myself, but it should work).  One nice thing about this approach is that you can change your round-robin technique into one that looks for the buffer/queue that is the least full before writing (which could increase overall throughput if any of the threads start getting backed up).
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now