linux 多线程把内存中的内容写入文件怎样效率最高呢...???
如题,经测试,我开一个线程写内存中的内容到磁盘,写效率有100M/s,但如果我开2路或者多路线程,写效率就只有10M/s了,我要怎么做,在开多线程的时候效率才高呢(至少要达到50M/s,当然越高越好),求大神指点...!!!!
我的写入线程函数如下:
void run()Linux 多线程 io读写
{
int fd2;
char buffer[10] = {0},storeRout[50] = {0};
printf("thread.........write........fun4\n");
strcat(storeRout, StoreRoute);
strcat(storeRout, "2.txt");
//printf(".................storeRout = %s\n", storeRout);
fd2 = open(storeRout, O_CREAT|O_RDWR|O_EXCL, 0777);
if(0 > fd2)
{
if(EEXIST == errno)
{
fd2 = open(storeRout, O_RDWR);
if(-1 == fd2)
{
perror("fd2....1.....open");
exit(-1);
}
}
else
{
perror("fd2....2....open");
exit(-1);
}
}
while(1)
{
write(fd2, buffer, writeBuf);
}
}