0

I googled forever, and I couldn't find an answer to this; the answer is either obvious (and I need more training) or it's buried deep in documentation (or not documented). Somebody must know this.

I've been arguing with somebody who insisted on caching some static files on an ASP.NET site, where I thought it's not necessary for a simple fact that all other files that produce dynamic HTML are not cached (by default; let's ignore output caching for now; let's also ignore the caching mechanism that person had in mind [in-memory or out on network]). In other words, why cache some xml file (regardless on how frequently it's accessed) when all aspx files are read from disk on every request that map to them? If I'm right, by caching such static files very little would be gained (less disk-read operations), but more memory would be spent (if cached in memory) or more network operations would be caused (if cached on external machine). Does somebody know what in fact happens when an aspx file is [normally] requested? Thank you.

3
  • Is a program (such as Word, Unreal Tournament etc.) read from the disk on every input command? A web app is likely to work in a similar way...
    – cjk
    Jun 8, 2011 at 17:32
  • So, you're saying how the IIS process reads files once, stores them in memory, and then monitors changes on all contents so that it can update its cached version? That makes sense. However, then why do some developers insist on specifically caching some static data files (e.g. xml) that we sometimes have as part of our websites (since those are cached the same way, by IIS, then)? Jun 8, 2011 at 18:40
  • Xml files aren't part of the prgram that is running, there will be code that explicitly reads them, so caching here is a good idea
    – cjk
    Jun 14, 2011 at 7:31

3 Answers 3

0

If I'm not mistaken ASPX files are compiled at run-time, on first access. After the page is compiled into an in-memory instance of a Page class, requests to the same resource (ASPX page) are serviced against the object in memory. So in essence, they are cached with respect to disk-access.

Obviously the dynamic content is generated for every request, unless otherwise cached using output caching mechanisms.

Regarding memory consumption vs disk access time, I have to say that from the performance stand point it makes sense to store objects in memory rather than reading them from disk every time if they are used often. Disk access is 2 orders of magnitude slower than access in RAM. Although inappropriate caching strategies could push frequently used objects out of memory to make room for seldom used objects which could hurt performance for obvious reasons. That being said, caching is really important for a high-performance website or web application.

As an update, consider this:

  • Typical DRAM access times are between 50 - 200 nano-seconds
  • Average disk-access times are in the range of 10 - 20 milliseconds

That means that without caching a hit against disk will be ~200 times slower than accessing RAM. Of course, the operating system, the hard-drive and possible other components in between may do some caching of their own so the slow-down may only occur on first hit if you only have a couple such files you're reading from.

Finally, the only way to be certain is to do some benchmarking. Stress-test both implementations and choose the version that works best in your case!

4
  • I agree that caching is important in instances of the content being stored remotely (e.g. different machine, database) or some content that needs to be calculated/generated and the process of generating it takes a long time. I can't quite agree that caching local files is necessary: RAM gets used, and file access is fast enough. Yes, accessing RAM is quicker, but if abused (which is very easy to inadvertently do), the performance will be affected from that front. Jun 8, 2011 at 19:17
  • @Ha Focokabe, it's all relative. I'm not sure what you're use-case is but if you're reading from a file on disk (i.e. using file i/o) and a large number of requests will need that resource, and you have lots or requests (i.e. 100s or 1000s per second) then disk access will slow you down A LOT! DRAM access times are 2 orders of magnitude faster than disk access (~100 nano-seconds vs ~10 - 20 milli-seconds) Jun 9, 2011 at 15:44
  • Thank you for you time. I will agree to that. Jun 9, 2011 at 15:56
  • Agree that benchmarking is the way to go, but just because a file is accessed "from disk" doesn't mean the disk access cost is actually incurred - there are many layers of caching built into the different layers of modern systems, right down to the cache memory built into most modern hard drives.
    – chris
    Jun 9, 2011 at 16:40
0

IIS does a large amount of caching, so directly, no. But, IIS checks for ANY changes in the web directory and reloads any changed files as they get changed. Sometimes IIS gets borked and you have to restart it to detect changes, but usually it works pretty good.

P.S. The caching mechanisms may flush data frequently based on server usage, but the caching works for all files in the web directory. Any detected changes to source code causes IIS to flush the web applicaiton and re-compile/re-load as well.

0
0

I believe that the answer to your question depends on both the version of IIS you're using, and configuration settings.

But I believe that it's possible to configure some combinations of IIS/.Net to avoid checking the files - there's an option to pre-compile sites, so no code actually needs to be deployed to the web server.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.