Re: Pipes and fd question. Large amounts of data.

From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 01/31/05


Date: Sun, 30 Jan 2005 22:18:27 -0500

In article <10vq0pkf5ugou99@corp.supernews.com>,
 "Johan" <me@knoware.nl> wrote:

> why not use sockets

You can't change from pipes to sockets without modifying the programs,
since you have to use different system calls to open them: socket() and
connect() in the writer; socket(), bind(), listen(), and accept() in the
reader. The programs presumably currently use open().

>
> John
>
> "Oded Shimon" <ods15@ods15.dyndns.org> schreef in bericht
> news:41fca6c2@news.012.net.il...
> >I have a rather unique situation. I have 2 programs, neither of which
> >have
> > control over.
> > Program A writes into TWO fifo's.
> > Program B reads from two fifo's.
> >
> > My program is the middle step.
> >
> > The problem - neither programs are aware of each other, and write into any
> > of
> > the fifo's at their own free will. They will also block until whatever
> > data
> > moving they did is complete.
> >
> > Meaning, if I were to use the direct approach and have no middle step, the
> > programs would be thrown into a deadlock instantly. as one program will
> > write
> > info fifo 1, and the other will be reading from fifo 2.
> >
> > The amounts of data is very large, GB's of data in total, and at least
> > 10mb
> > a
> > second or possibly as much as 300mb a second. So efficiency in context
> > switching is very important.
> >
> > programs A & B both write and read using large chunks, usually 300k.
> >
> > So far, my solution is using select() and non blocking pipes. I also used
> > large buffers (20mb). In my measurements, at worst case the programs
> > write/read 6mb before switching to the other fifo. so 20mb is safe enough.
> >
> > I have implemented this, but it has a major disadvantage - every 'write()'
> > only write 4k at a time, never more, because of how non-blocking pipes are
> > done. at 20,000 context switches a second, this method reaches barely 10mb
> > a
> > second, if not less.
> >
> > Blocking pipes have an advantage - they can write large chunks at a time.
> > They
> > have a more serious disadvantage though - the amount of data you ask to be
> > written/read, IS the amount of data that will be written or read, and will
> > block until that much data is moved. I cannot know beforehand exactly how
> > much data the programs want, so this could easily fall into a dead lock.
> >
> > Ideally, I could do this:
> > my program: write(20mb);
> > program B: read(300k);
> > my program: write() returns with return value '300,000'
> >
> > I was unable to find anything like this solution or similar.
> > No combination of blocking/non blocking fd's will give this, or any system
> > call.
> > I am looking for alternative/better suggestions.
> >
> > - ods15.
> >

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


Relevant Pages

  • Re: Domain scokets? ceptcl?
    ... Well the two common ones are pipes between parent and child, or socket on ... I seriously doubt either of the solutions I propose will be the bottle neck ... Note -- the socket solution is totally platform independent and can be ...
    (comp.lang.tcl)
  • Re: Network pipes
    ... * I do not understand how can you remove the pipe in the remote host ... from regular pipes. ... > user to create a pipeline over the network using a socket as its ... > has tar sending each block through a pipe to a local ssh process, ...
    (freebsd-hackers)
  • Welche Prozesse nutzen eine Pipe oder einen Socket?
    ... Wie kriege ich denn nun raus, wozu die Sockets und Pipes gehören? ... habe ein bisschen mit netstat und lsof gespielt, ... anderen Socket ein Socket verbunden ist. ... Bei den meisten steht nur socket, bei den anderen ein Pfad. ...
    (de.comp.os.unix.linux.misc)
  • Golf Mk2 Fuel gauge sender troubles
    ... the boot carpet and seen the two pipes coming up from a large black ... I can't get the plug to unplug from the socket on the plastic ...
    (uk.rec.cars.vw.watercooled)
  • Re: Socket SecurityDescriptor
    ... > Is there any way to associate a securitydescriptor with a socket? ... > meaning when you create a new socket is there any way you can set the ... protecting it... ...
    (microsoft.public.vc.language)