Solved

writing to harddisks

Posted on 2001-06-21
7
432 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
Comment Utility
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
Comment Utility
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
Comment Utility
you wouldn't happen to remember that flag, would you?

Cheers,
Oli
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Accepted Solution

by:
rgoerdes earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Does anyone know if this accepted answer was posted as a comment or as an answer?
0
 
LVL 1

Author Comment

by:Oli2
Comment Utility
it was a comment - why?

Regards,
Oli
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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. …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now