使用selinux,System V消息队列发送速度非常慢

时间:2015-10-29 04:30:39

标签: ipc rhel selinux

启用selinux后,我的System V消息队列发送速度明显减慢。禁用selinux后,我的测试程序可以在大约1,500微秒内完成1000次发送(msgsnd)。启用selinux后,执行1,000次发送大约需要25,000微秒。 我能做些什么来加快这个速度吗?

  unsigned long long gettime()
  {
    struct timeval gtime;
    unsigned long long usecs;
    gettimeofday (&gtime,NULL);
    usecs = (((unsigned long long)gtime.tv_sec) * 1000000) + gtime.tv_usec;
    return usecs;
  }

  key_t keyval = 102715; 
  int     qid;
  if((qid = msgget( keyval, IPC_CREAT | 0660 )) == -1)
  {
    printf("msgget failed\n");
    return -1; 
  }
  printf("qid = %d\n",qid);
  struct XmitMsg 
  {
    long    mtype;     
    int     data1;
    int     data2;
  } msg;

  struct XmitMsg xmitmsg;
  xmitmsg.mtype=1;
  xmitmsg.data1=10;
  xmitmsg.data2=20;
  int length = sizeof(struct XmitMsg) - sizeof(long);        
  unsigned long long beforeTime=gettime();
  for (int i=0; i<1000; i++)
  {
    int result = msgsnd( qid, &xmitmsg, length, 0);
    if (result != 0 ) printf("result=%d\n",result);
  }
  unsigned long long afterTime=gettime();
  printf("time diff=%llu\n",afterTime-beforeTime);

0 个答案:

没有答案