我们面临的问题是系统调用与容器外部相比,容器内部执行时间更长。
BASE OS Container : Ubuntu Container image
CAPS ALLOW : sys_resource sys_nice sys_tty_config ipc_lock
RHEL 7.3
时间./a.out
for循环执行时间为8.690000秒
for循环执行
需要9.170000秒real 0m9.188s
user 0m1.768s
sys 0m7.419s
for循环执行时间为64.123517秒
for循环执行时间为64.316575秒
real 1m4.503s
user 0m1.449s
sys 1m2.870s
我们运行以下代码来检查系统调用的执行时间
int main()
{
int key,share_id,num;
char *data;
int semid;
int count= 0;
struct sembuf sb={0,-1,0};
clock_t t;
t = clock();
if(!fork())
{ //Child Porcess
for (int i= 0 ;i < 50; i++){
for (int idx =0; idx < 1000000 ; idx++){
sb.sem_op=-1; //Lock
semop(share_id,(struct sembuf *)&sb,1);
count++;
sb.sem_op=1;//Unlock
semop(share_id,(struct sembuf *)&sb,1);
}
}
}
else
{ //Parent Process
for (int i= 0 ;i < 50; i++){
for (int idx=0; idx < 1000000; idx++){
sb.sem_op=-1; //Lock
semop(share_id,(struct sembuf *)&sb,1);
count++;
sb.sem_op=1;//Unlock
semop(share_id,(struct sembuf *)&sb,1);
}
}
}
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds
printf(" for loop took %f seconds to execute \n", time_taken);
return 0;
}