Store a data stream on hard disk in Windows

95 views Asked by At

In our application, we need to store a data stream from a camera to the hard disk, and because all the CPU cores are already occupied by calculus, we are trying to save every frame in a separate .jpeg file created with nvjpeg. What we see is that after a while, the hard drive goes to 100% usage, and if we stop the application it remains in writing mode for a while.

I did some checks and see that the maximum speed of this HDD is 100Mb/sec. For our .jpegs, we need 60Mb/sec, so I change the code to do it with overlapped and no-buffering:

HANDLE hfile = CreateFileW(fileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 
    FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL);
FILE_END_OF_FILE_INFO eofi;
eofi.EndOfFile.QuadPart = dim;
SetFileInformationByHandle(hfile, FileEndOfFileInfo, &eofi, sizeof(FILE_END_OF_FILE_INFO));
DWORD d = (DWORD)dim;
DWORD unA = d & 511;
if (unA) d += 512 - unA;
::WriteFile(hfile, buff, d, NULL, &overlapped);
DWORD n = 0;
while(n<d) GetOverlappedResult(hfile, &overlapped, &n, TRUE);
CloseHandle(hfile);

But the problem still happens; there is some peaks of 1Mb/sec and after a while the hard drive is 100%.

What is the cause of those peaks? How can I obtain maximum performance?

0

There are 0 answers