ASP.NET:每次请求时都会从磁盘访问 aspx/ascx 文件吗?

发布于 2024-11-15 01:05:34 字数 382 浏览 6 评论 0原文

我用谷歌搜索了很久,但找不到答案;答案要么是显而易见的(我需要更多的培训),要么是深埋在文档中(或没有记录)。一定有人知道这一点。

我一直在与坚持在 ASP.NET 站点上缓存一些静态文件的人争论,我认为没有必要这样做,因为一个简单的事实是,生成动态 HTML 的所有其他文件都不会被缓存(默认情况下;让我们忽略输出缓存)现在;我们也忽略人们想到的缓存机制[内存中或网络上])。换句话说,当所有 aspx 文件在映射到它们的每个请求上都从磁盘读取时,为什么要缓存某些 xml 文件(无论访问频率如何)?如果我是对的,通过缓存此类静态文件几乎不会获得什么(更少的磁盘读取操作),但会花费更多的内存(如果缓存在内存中)或会导致更多的网络操作(如果缓存在外部机器上) 。有人知道当 [通常] 请求 aspx 文件时实际上会发生什么吗?谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心凉 2024-11-22 01:05:34

如果我没记错的话,ASPX 文件是在运行时、第一次访问时编译的。将页面编译为 Page 类的内存实例后,将对同一资源(ASPX 页面)的请求针对内存中的对象提供服务。因此本质上,它们是针对磁盘访问进行缓存的。

显然,动态内容是为每个请求生成的,除非使用输出缓存机制进行缓存。

关于内存消耗与磁盘访问时间,我不得不说,从性能角度来看,如果经常使用对象,则将对象存储在内存中比每次从磁盘读取它们更有意义。磁盘访问比 RAM 中的访问慢 2 个数量级。尽管不适当的缓存策略可能会将频繁使用的对象挤出内存,为很少使用的对象腾出空间,但这可能会因明显的原因而损害性能。话虽如此,缓存对于高性能网站或 Web 应用程序确实非常重要。

作为更新,请考虑以下因素:

  • 典型的 DRAM 访问时间在 50 - 200 纳秒之间
  • 平均磁盘访问时间在 10 - 20 毫秒范围内

这意味着在不缓存的情况下,对磁盘的命中将比访问慢约 200 倍内存。当然,操作系统、硬盘驱动器和中间可能的其他组件可能会自己进行一些缓存,因此如果您只有几个正在读取的此类文件,则只有在第一次命中时才会出现速度减慢的情况。

最后,唯一确定的方法是进行一些基准测试。对两种实现进行压力测试,并选择最适合您的情况的版本!

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!

心在旅行 2024-11-22 01:05:34

IIS做了大量的缓存,所以直接说,不行。但是,IIS 会检查 Web 目录中的任何更改,并在文件发生更改时重新加载任何更改的文件。有时 IIS 会停止运行,您必须重新启动它才能检测到更改,但通常它工作得很好。

PS 缓存机制可能会根据服务器使用情况频繁刷新数据,但缓存适用于 Web 目录中的所有文件。任何检测到的源代码更改都会导致 IIS 刷新 Web 应用程序并重新编译/重新加载。

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.

筑梦 2024-11-22 01:05:34

我相信您问题的答案取决于您使用的 IIS 版本和配置设置。

但我相信可以配置 IIS/.Net 的某些组合来避免检查文件 - 有一个 预编译网站的选项,因此实际上不需要将任何代码部署到 Web 服务器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文