3
  • I have an application, where I send approx. 125 data items via a named pipe.
  • Each data item consists of data block 1 with max. 300 characters and data block 2 with max. 600 characters.
  • This gives 125 data items * (300 + 600) characters * 2 bytes per character = 125 * 900 * 2 = 225000 bytes.
  • Each data item is surrounded by curly braces like {Message1}{Message2}.
  • I noticed that if I send the messages, there are sending/receiving problems. Instead of {Message1}{Message2} the receiving application gets {Messa{Message2}.
  • Then I changed the sending code so that the messages are sent in 500 ms intervals. Then, the problem disappeared.

If I do everything correct (no bugs on my side, no misconfiguration of named pipes), how much time is required to send 225000 bytes over a named pipe from application in Delphi 2009 to application in .NET on the same machine?

What is a reasonable time for sending data of that size?

Glory to Russia
  • 17,289
  • 56
  • 182
  • 325
  • 3
    It sounds like your code is flawed. You should concentrate on finding and fixing the flaw. Adding sleep calls merely papers over the cracks. Find and fix the real problem. – David Heffernan Nov 08 '12 at 08:06
  • Try a good IPC library here, [Cromis-IPC](http://www.cromis.net/blog/downloads/cromis-ipc/). – LU RD Nov 08 '12 at 08:35
  • 4
    Are threads involved? The named pipe will send and receive exactly what you put down it, in the order you put it there. There is a logic problem in your code, so please revisit that "no bugs on my side" as it isn't true. – mj2008 Nov 08 '12 at 09:51
  • "If what you are looking at is speed, the fastest solution is shared Memory, not named pipes." ([IPC performance: Named Pipe vs Socket](http://stackoverflow.com/a/1955266/80901)) – mjn Nov 08 '12 at 11:17
  • As @mj2008 said if you have multiple threads at the sending side ensure **only one thread sends it's entire message** to the pipe. Other threads must wait meanwhile. – iPath ツ Nov 08 '12 at 11:47
  • There is only one thread. First, I assemble a list of strings (`TStringList`), then send all the strings one by one. – Glory to Russia Nov 08 '12 at 11:50
  • Each string represents one message. – Glory to Russia Nov 08 '12 at 11:51
  • Use something like Codesite to output what you are sending, and what is being received. A low level logger will help a lot. – mj2008 Nov 08 '12 at 12:18
  • @mj2008 I do this already. The Delphi application sends correct messages, but sometimes messages are delivered incorrectly (part of a message is lost). At the receiving side there is only one thread that reads data from the named pipe. The errors with sending/receiving can be fixed by changing buffer sizes of the named pipe. – Glory to Russia Nov 08 '12 at 12:32
  • What makes you so sure that your code is correct? – David Heffernan Nov 08 '12 at 14:02
  • 2
    Okay, so one thread either side. Are they running at the same time? It sounds like you simply are reaching buffer limits in the pipe. If the reader is not as fast as the writer, and the buffer is too small, and there is no synchronisation, then this will happen. Waiting for an acknowledgement by return (perhaps with a window to allow the reader to be up to 10 packets behind) would seem to be in order here. – mj2008 Nov 08 '12 at 14:04
  • @mj2008 Regarding "buffer is too small": How can I calculate an optimal buffer size (except by trial and error) ? – Glory to Russia Nov 08 '12 at 16:06
  • 1
    Post your code, and we'll find the bug. :-) – Harry Johnston Nov 11 '12 at 23:40
  • @Dmitri Pisarenko - the optimal buffer size on Windows with a modern Intel processor, in user space, is going to be a 4KB page aligned on a 64-byte boundary. – hoodaticus Oct 14 '15 at 19:50

0 Answers0