Solved

writing to harddisks

Posted on 2001-06-21
7
437 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
Technology Partners: 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

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

739 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