Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

writing to harddisks

Posted on 2001-06-21
7
Medium Priority
?
443 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Accepted Solution

by:
rgoerdes earned 400 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

886 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