DrWhy has asked for the wisdom of the Perl Monks concerning the following question:

Greetings monks,

I have a script that does repeated speed tests of an application. However, Windows disk and memory caching is causing the results to be less than accurate. Is there a way in Perl (or with some external tool called by Perl) to clear these caches between each run of the application that I'm testing?

I've looked on CPAN for something that could do this, but I wasn't successful.

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

  • Comment on How do you clear Win32 caches (disk/memory)

Replies are listed 'Best First'.
Re: How do you clear Win32 caches (disk/memory)
by cowboy (Friar) on Sep 26, 2005 at 21:55 UTC


    Some windows tuning guides may point to registry entries, or other settings you can use to disable the caching.

    On the other hand, I really can't see why that would give you accurate performance measurements. Unless you expect to have such a huge dataset, and your access pattern will be such that the cache is essentially useless, I would think you'd want to discount the tests that were run before the system had time to get things loaded into cache.

Re: How do you clear Win32 caches (disk/memory)
by InfiniteSilence (Curate) on Sep 26, 2005 at 18:42 UTC
    I think you need to include more information, namely:

  • What kind of "tests" are you running
  • What kind of application are you testing?
  • Do you have any actual CODE we can look at?

    Celebrate Intellectual Diversity

      I really don't think the answers to these questions will make it any easier to answer my original question. Nevertheless, I'll do what I can...

      I'm testing a server that translates documents from one human language into another (e.g. Arabic to English). The server communicates via SOAP so my test script starts up the server and then acts as a SOAP client submitting translation 'jobs'. The server accepts each job and when it is complete the client retrieves performance data, including the speed of translation in words per minute. We (meaning someone in the company who is not me) have determined that these results are inaccurate because in a single test run (which consists of approximately 7 jobs with slightly varying settings) memory and/or disk caching is making the later runs appear to be too fast. I am already stopping and restarting the server between each job, therefore this discrepancy is not due to any explicit caching that is done by the application itself.

      Unfortunately, I am not able to post any code for this; I hope my explanation of the behavior of the script above will be sufficiently enlightening.

      --DrWhy

      "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

Re: How do you clear Win32 caches (disk/memory)
by spiritway (Vicar) on Sep 27, 2005 at 04:57 UTC

    I think you first need to see whether you can determine just what's doing the caching. This wouldn't be specifically a Perl issue, though. You might get some hint from the names of the caches, if you know where they live. You may be able to disable them using msconfig.exe ( Start | Run... | msconfig.exe).

    AFAIK, there's no Perl module to disable caches (but don't take my word for it - CPAN is full of surprises).

Re: How do you clear Win32 caches (disk/memory)
by DrWhy (Chaplain) on Sep 30, 2005 at 21:57 UTC
    Well, as it turns out memory caching was not the problem. I proved this by running the first and last test scenario each immediately after a reboot. The timing results were nearly identical to what I got when I ran all seven of my tests one after the other with only a restart of the application between them.

    I was however able to figure out a way to clear the windows memory cache from a script. There are some freeware tools that can do this, but they are windows apps with no (useful) command line interface. The one I used was CacheSet from Sysinternals. Then I wrote a little wrapper module that calls this using Win32::GuiTest. Kinda kludgy, but it got the job done.

    At least I learned a new Perl Module.

    --DrWhy

    "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."