Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the most efficient way to exchange high volume data between 2 process?

Tags:

linux

Recently I am building the software for a DVR.

It will be installed on a x86 pc server with 2 or more PCIE x4 video encoder card plugged in.

We have 2 seperated proces, one has to get encoded video data from these encoder card, the other has to save these data to hard driver. Why we have 2 process? Some histroy problem.

So, what kind of IPC should we use? Socket, Pipe, or shared memory?

Currently we are using socket.

like image 665
lilyonwind Avatar asked Dec 29 '22 16:12

lilyonwind


1 Answers

With pipes on linux, you could use the splice functionality to get zero-copy moves of the data from one process to the other. For example, the sending process uses vmsplice() with SPICE_F_GIFT to gift the data into a pipe, then the receiving processes uses splice() with SPLICE_F_MOVE to move the data straight from the pipe into the disk file without touching it. Note that there are naturally some alignment and length restrictions around this.

Depending on how the driver for your encoder card works, potentially you could arrange things to get zero-copy all the way from the driver to the disk - the encoder card DMAs into memory and the disk DMAs it back out, without the CPU ever needing to look at it (in this case you would splice() the data from the encoder card into the pipe, then splice() it back out of the pipe to the disk file).

like image 69
caf Avatar answered Jan 08 '23 03:01

caf