mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oded Shimon <ods15@ods15.dyndns.org>
To: linux-kernel@vger.kernel.org
Subject: Pipes and fd question. Large amounts of data.
Date: Sun, 30 Jan 2005 11:15:59 +0200	[thread overview]
Message-ID: <200501301115.59532.ods15@ods15.dyndns.org> (raw)

A Unix C programming question. Has to do mostly with pipes, so I am hoping I 
am asking in the right place.

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.

             reply	other threads:[~2005-01-30  9:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-30  9:15 Oded Shimon [this message]
     [not found] ` <200501300941.45554.miles@milessabin.com>
2005-01-30 10:48   ` Oded Shimon
2005-01-31 15:02     ` Chris Friesen
2005-01-31 15:14       ` Oded Shimon
2005-01-30 19:41 ` Miquel van Smoorenburg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200501301115.59532.ods15@ods15.dyndns.org \
    --to=ods15@ods15.dyndns.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®