-1
一個MSG我寫一個測試程序如下:性能差時多進程寫在Linux
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/msg.h>
#include <time.h>
#define PACKET_SIZE 500
#define LOOP_COUNT 30000
int g_sndsucc = 0;
int g_sndfail = 0;
const int C_IPC_KEY = 0x00231a95;
const int COUNT_SIZE = 10000;
unsigned long g_count = 0;
unsigned long g_t1 = 0;
struct timeval s1, s2, s3, s4;
int main(int argc, char* argv[])
{
int ipckey = C_IPC_KEY;
if(argc > 1)
{
ipckey = atoi(argv[1]);
printf("ipckey is %d\n", ipckey);
}
int qid = msgget(ipckey, IPC_CREAT | 0666);
if(qid <= 0)
{
printf("msgget err: %d \n", errno);
return 0;
}
char data[PACKET_SIZE];
memset(data, 'a', PACKET_SIZE-1);
data[PACKET_SIZE-1] = '\0';
*((long *)data) = 0;
int ret = 0;
struct timeval start;
gettimeofday (&start, NULL);
while(1)
{
*((long *)data) +=1;
gettimeofday (&s1, NULL);
ret = msgsnd(qid, data, PACKET_SIZE,0);
gettimeofday (&s2, NULL);
if(ret != 0)
{
g_sndfail ++;
}
else
{
g_sndsucC++;
}
g_count++;
g_t1 += (s2.tv_sec-s1.tv_sec)*1000000 + (s2.tv_usec-s1.tv_usec);
if (g_count >= 10000)
{
printf("STAT1: t1 : %f\n",
10000000000.0/g_t1);
g_count = 0;
g_t1 = 0;
}
usleep(1000);
}
return 0;
}
創建100個相同的處理來的msgsnd,和在SUSE,每個進程的的msgsnd TPS僅達到50 /秒。 但是在AIX5上,msgsnd tps可以達到10000/s。
有沒有人知道爲什麼在多進程如此窮人的Linux上IPC的性能? 如何提高在Linux上的性能?
順便說一句,SUSE的kenel版本是Linux 3.0.13