Hi
I've a strange behavior using fwrite.
My program writes 5 MB on the disk with buffer of 50000 bytes, but
sometime a single fwrite waits for more than 1 seconds.
System features :
- reiserfs
- DMA actived.
This is the code I used to test fwrite
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
const __int64 TIME_T_ZERO_TIME = 116444700000000000;
longlong UTime64()
{
struct timeval tv;
struct timezone tz;
gettimeofday(&tv,&tz);
long long Ret = (__int64)tv.tv_sec*10000000+TIME_T_ZERO_TIME+(__int64)tv.tv_usec*10
+ (__int64)36000000000;
int main(int argc, char** argv)Quote:}
{
char buffer[100000];
int size;
__int64 tTime1;
int Count = 0;
char Name[2014];
while (1)
{
sprintf(Name,"/tmp/prova_fwrite_%d.tmp",Count++);
FILE* f = fopen(Name,"w");
int Size = 50000;
int SizeWritten = 0;
while (SizeWritten < 5000000)
{
tTime1 = UTime64();
size = fwrite(buffer,1,Size,f);
tTime2 = UTime64();
float fl = (float)(tTime2-tTime1) / size;
if (fl>50 && tTime2-tTime1 > 10000000) // > 1 sec
{
printf("Ratio = %f - %d - %llu\n",fl,size,tTime2-tTime1);
}
SizeWritten[i] += size;
}
fclose(f);
usleep(1000);
}
return 1;
And this is the outputQuote:}
(idx) (delta T / size) (size) (delta T sec)
15730 - Ratio2 = 305.085602 - 50000 - 1,5254330
19665 - Ratio2 = 559.221008 - 50000 - 2,7961100
23154 - Ratio2 = 490.265991 - 50000 - 2,4513350
24989 - Ratio2 = 430.956207 - 50000 - 2,1547860
27135 - Ratio2 = 283.720795 - 50000 - 1,4186090
31161 - Ratio2 = 238.803802 - 50000 - 1,1940240
42781 - Ratio2 = 263.786591 - 50000 - 1,3189380
....