Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are all the disadvantages of using files as a means of communicating between two processes?

I have legacy code which I need to improve for performance reasons. My application comprises of two executables that need to exchange certain information. In the legacy code, one exe writes to a file ( the file name is passed as an argument to exe) and the second executable first checks if such a file exists; if does not exist checks again and when it finds it, then goes on to read the contents of the file. This way information in transferred between the two executables. The way the code is structured, the second executable is successful on the first try itself.

Now I have to clean this code up and was wondering what are the disadvantages of using files as a means of communication rather than some inter-process communication like pipes.Is opening and reading a file more expensive than pipes? Are there any other disadvantages? And how significant do you think would be the performance degradation.

The legacy code is run on both windows and linux.

like image 422
Manny Avatar asked May 22 '10 14:05

Manny


1 Answers

Some problems with using files for IPC are:

  • What happens when process (1) is writing to the file when process (2) finds it? You need to have special logic to handle this case.

  • What happens if process (1) wishes to send another message while process (2) is still reading from the file? (1) would have to somehow detect that the file cannot be written to, and wait until it is available.

  • Files could become a bottleneck under large amounts of message traffic, especially if you are only using a single file for IPC.

To determine if file I/O is a performance bottleneck for you, we need to understand more about the messages you are sending. How large they are, how frequently they are sent, etc. Otherwise it is difficult to judge what affect they have on your performance, if any.

That said, I have used files in the past to pass information between processes, although typically either new filenames will be created each time or files will be used to pass large amounts of data and a smaller IPC message will be used to signal when the file is ready.

In my opinion unless you have a reason to use files - such as transfers of large amounts of data - I would prefer a traditional IPC mechanism such as pipes, sockets, etc. But you would have to implement it carefully to make sure everything works on both platforms.

like image 162
Justin Ethier Avatar answered Oct 12 '22 11:10

Justin Ethier