Solved

writing to harddisks

Posted on 2001-06-21
7
436 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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.

756 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