Solved

writing to harddisks

Posted on 2001-06-21
7
434 Views
Last Modified: 2012-05-04
My app needs to check how fast data can be written to the hard-disk(s).
I tried it the cheap way before, writing 10 MB to file with FileWrite() and  counting the milliseconds, but it doesn't seem to work properly since there's peaks.
e.g:
10 MB written in 402 ms
10 MB written in 389 ms
10 MB written in 428 ms
10 MB written in 1689 ms.

Seems there's some caching/flushing going on (?)
Or maybe it was just the OS itself reading/writing to the disk, maybe swapping or something.

Anyways, my question is:
If you'd have to check the speed of a harddrive,
would you use FileWrite()?

Or create a FileStream?

Any suggestions welcome.

Regards,
Oli
0
Comment
Question by:Oli2
7 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 6213884
There is indeed buffering/caching going on and measuring true disk performance is a tough task.  Not only does Windows buffer write data but all hard disks have hardware caches on them.  Further, you can really either optimize this or trash this by careful choice of the blocksize.  If you hit the sweet-spot for the system, it will really fly, it you hit the "anti-resonant" blocksize, you will crawl.

If your app needs to know something about hard disk access, you might want to study the pattern that your app uses when it write data.  This is what you are interested in anyway, right?  Any other test is likely to be somewhat meaningless since your app does it in a different way.
0
 
LVL 1

Expert Comment

by:rgoerdes
ID: 6215558
the speed of harddisks has many aspects. ok, you can write a large amount of data. but you also can write a small block, jump back, write again a small block - or even mix it up with readings. and i remember somewhere in the dark chambers of my brain: it's possible to undergo windows caching opening files in a sort of passthrough mode. it's a flag setting in the CreateFile-command.
0
 
LVL 1

Author Comment

by:Oli2
ID: 6215807
you wouldn't happen to remember that flag, would you?

Cheers,
Oli
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Accepted Solution

by:
rgoerdes earned 100 total points
ID: 6217243
we proudly present - the flag is:

FILE_FLAG_NO_BUFFERING: Instructs the system to open the file with no intermediate buffering or caching. When combined with FILE_FLAG_OVERLAPPED, the flag gives maximum asynchronous performance, because the I/O does not rely on the synchronous operations of the memory manager. However, some I/O operations will take longer, because data is not being held in the cache.
An application must meet certain requirements when working with files opened with FILE_FLAG_NO_BUFFERING:

File access must begin at byte offsets within the file that are integer multiples of the volume's sector size.
File access must be for numbers of bytes that are integer multiples of the volume's sector size. For example, if the sector size is 512 bytes, an application can request reads and writes of 512, 1024, or 2048 bytes, but not of 335, 981, or 7171 bytes.
Buffer addresses for read and write operations should be sector aligned (aligned on addresses in memory that are integer multiples of the volume's sector size). Depending on the disk, this requirement may not be enforced.
One way to align buffers on integer multiples of the volume sector size is to use VirtualAlloc to allocate the buffers. It allocates memory that is aligned on addresses that are integer multiples of the operating system's memory page size. Because both memory page and volume sector sizes are powers of 2, this memory is also aligned on addresses that are integer multiples of a volume's sector size.

An application can determine a volume's sector size by calling the GetDiskFreeSpace function.

hope could help you

regards,
reinhold
0
 
LVL 1

Author Comment

by:Oli2
ID: 6217874
Now that's what I call a lot of info!
Thanx, reinhold!!
I'll look into this stuff and I'm sure it'll fit my needs just perfect.

Again: thanx!

Regards,
Oli
0
 
LVL 22

Expert Comment

by:nietod
ID: 6222840
Does anyone know if this accepted answer was posted as a comment or as an answer?
0
 
LVL 1

Author Comment

by:Oli2
ID: 6224197
it was a comment - why?

Regards,
Oli
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question