LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
 
Search this Thread
Old 05-19-2005, 02:30 PM   #1
ceoping
LQ Newbie
 
Registered: Apr 2005
Posts: 6

Rep: Reputation: 0
Question Using IPCS and Performance of Shared Memory vs. Socket


I had built some executables on the Linux 2.4 kernel and ran them on the SUSE 9 (Linux 2.6) because Linux 2.4 build does not support POSIX shared-memory. IPC mechanism through shared-memory and sockets are working, but I noticed two things:

(1) ipcs was not showing shared-memory while the executables were running. Shouldn't there be something since there are shared-memory segments being mapped?

------ Shared Memory Segments --------
key shmid owner perms bytes nattch status

(2) performance measurement of socket vs. shared-memory on 40 MB was actually at par running on the same system (SUSE 9 with Linux 2.6). Given some reported ratio that says POSIX shared memory is 20x faster, I would assume that I would see a huge performance difference. However, the numbers does not reflect that. For 40 MB, dif1 = 2 seconds, dif2 = 3 seconds for shared-memory and dif1 = 2-3 seconds, dif2 = 2-3 seconds for sockets. See my crude measurement below. Any comment as to whether I am expecting too much out of shared-memory IPC?

time (&start1);
start2 = start1;
// execute something
time (&end1);
dif1 = difftime (end1,start1);


Roundtrip measurement through callback acknowledging data got across:
time(&end2)
dif2 = difftime (end2,start2);

Thanks,

kl
 
Old 05-22-2005, 01:58 AM   #2
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 46
I'm no kernel guru (*far* from it), but I suspect that shared memory can be *slightly* faster than sockets. Here's why:

I suspect that the kernel will notice that the connection is local and use a kernel-space buffer for the data you send/recv directly instead of sending it to eth0/whatever. "But wait, this sounds just like shared memory" you say. not exactly--your program has to switch to kernel-mode to stuff the data into the buffer or read from it. With shared memory, you just go at it.

that being said, there may be a smarter implementation (which I'm dying to hear about--yet I'm too lazy to "use the source, luke" ), but this is the one that's obvious to me.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
ipcs -lm shows : max total shared memory (kbytes) = 0 vicv Linux - Software 1 09-01-2005 10:58 AM
is shared memory expandable in memory size? Thinking Programming 4 08-16-2005 09:57 AM
c + shared memory dilberim82 Programming 3 03-07-2005 07:49 PM
poor java socket read performance bobwall Linux - Networking 0 01-21-2005 09:55 PM
shared memory blackzone Programming 1 10-14-2004 11:52 AM


All times are GMT -5. The time now is 03:53 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration