LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-10-2016, 08:35 PM   #1
david_8274
Member
 
Registered: Jun 2013
Location: California
Distribution: Ubuntu, Fedora
Posts: 75

Rep: Reputation: Disabled
Which is better for embedded Linux ipc: message queue vs socket


Hi all,

I am working on an embedded Linux project. I have multiple processes running in the user space. Now I need to choose a way for the process to communicate with each other. I read about SOCKET & MESSAGE QUEUE. Could anyone give me an idea which one I should use for embedded Linux system?

Thanks,
Wei Xu
 
Old 03-11-2016, 06:18 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
It really depends on what and how fast you need the data passed.

For fastest, use shared memory segments. Neither socket or message queues are all that fast. Sockets are easiest as the kernel does the buffering. I haven't used message queues but I believe they cause some extra synchronization overhead.

The best would be to try all three, then pick the one that works best for your application.
 
Old 03-11-2016, 02:19 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,665
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
Message queues ... "pipes" ... are probably plenty fast enough.

Linux makes fairly-constant use of pipes. Anytime you use the "|" character when "piping" one command to another in the (bash) shell, you're using pipes. Therefore, the implementation is easy-to-use and fast.

All that having been said . . . When possible, use a software library that gives you several alternatives. Plenty of good IPC solutions are available "right out of the box." Don't waste time doing something that has already been done. You should be able to program to a high-level API, e.g. in C++, that is agnostic to exactly how the trick is done. (And definitely, IMHO, "use C++.")

Last edited by sundialsvcs; 03-11-2016 at 02:23 PM.
 
Old 03-11-2016, 05:30 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by sundialsvcs View Post
Message queues ... "pipes" ... are probably plenty fast enough.

Linux makes fairly-constant use of pipes. Anytime you use the "|" character when "piping" one command to another in the (bash) shell, you're using pipes. Therefore, the implementation is easy-to-use and fast.

All that having been said . . . When possible, use a software library that gives you several alternatives. Plenty of good IPC solutions are available "right out of the box." Don't waste time doing something that has already been done. You should be able to program to a high-level API, e.g. in C++, that is agnostic to exactly how the trick is done. (And definitely, IMHO, "use C++.")
Pipes are one way transfer. You can't do two way communications without the chance of deadlock.

Using pipes can be VERY slow depending on what you are doing (don't, for instance, try to pass video data through one...).

One of the slowdowns is due to the kernel having to copy data into the kernel, then copy it back
out. The larger the data, the slower it goes.

Sockets are just as fast - but is much easier to avoid deadlock, and allow for two way data transfers.

Shared memory segments are even faster (two or even three times as fast), and can be done
both directions.

I agree with the rest (well, possibly excepting C++ as it depends on what is being done).

Last edited by jpollard; 03-11-2016 at 05:31 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
IPC _synchronization message queue Tala_22 Linux - Kernel 1 12-15-2015 07:38 PM
Linux IPC - message queues aryan1 Programming 6 08-03-2009 02:22 AM
Is it possible for me to write in front of queue in case of message queue? hemanthv414 Linux - Newbie 1 11-17-2008 04:40 PM
IPC V message queue --msgsnd() call jasdeep.js Linux - Kernel 1 01-02-2007 06:59 PM
linux ipc programming message queues mariogarcia Programming 2 05-28-2006 03:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration