1

我将 Web 表单和 Asp.Net 与 MS SQL 一起使用。

对于我的网站,我需要存储这些代码亲爱的,也许将来还有其他代码:

  • 谷歌分析代码
  • 一些 JavaScript 代码
  • 我的模板的 HTML 页脚和页眉。

我需要一个可以集中的解决方案,使用 CACHE,易于更新:

在这里我的想法,我想你的意见:

  • 01 使用带有表(配置表)的数据库,该表对于每条记录(VARCHAR)都允许将这些代码尖峰存储为字符串。
  • 02 在特定文件夹中使用简单的文本文件,这样我就可以将这些文件包含在我的代码中。我可以使用 FTP 和记事本更新代码(这里我担心缓存)。
  • 03 使用 Web.Conf 文件。
  • 04 使用文本文件和一个类,它将管理在缓存中存储这些文件的内容。

有任何想法吗?谢谢你的时间。

在这里,我想为这个主题提供重点和有用的文章:

http://nathanaeljones.com/153/performance-killer-disk-io/

4

2 回答 2

3

首先,关于 Nathanael Jones 博客的引用链接,虽然磁盘 IO 比内存操作慢得多,但大多数网站都不受磁盘 IO 限制,坦率地说,他的大多数解决方案都是没有受过教育的废话。

一般来说,只有极少数情况下您会成为 DISK io 绑定。首先是数据库服务器本身。如果它没有足够的 RAM 来将数据库的相关部分保存在内存中,那么该服务器的磁盘速度至关重要;特别是在高交易情况下。

其次,如果您的应用程序直接读写大量文件,您可能会受到磁盘 IO 的限制。很少有应用程序这样做。我没有计算应用程序的 .aspx 或 .html 文件,因为它们可以被现有框架和 IIS 缓存。

基本上,直接无视他。

The whole filesystem to database syncing idea as a method to improve performance is of no value to about 99.999% of sites. If nothing else the database should be pushing files to the web server file system, not the other way around. I have seen exactly 1 site in 20 years of development that required this. They serve several million page views a day. Also, he is flat wrong about making a database call across a network being faster than loading an equivalent amount of data from a local file.

Next, the actual area that we are really bound at is in sending data across the network to the client browser. This is ALWAYS slower than reading a file from a disk; even with no traffic on the line. Hard drives move data much faster than your network card can. Taking it one step further; modern hard drives are orders of magnitude faster than your internet connection. The best thing you can do to improve performance is just to limit the number of connection requests a single page load requires. Optimization here means having 1 css file, not 20; having just a couple .js file references, not 100; and combining graphics into sprites where feasible. It's faster to transfer 1 big file than 100 small files due to how TCP works.

Maybe on an overloaded shared server you might have an issue. However, the reality is that an overloaded shared server is going to be network congested long before it's disk queue length grows out of control.


With that out of the way, let's look at your actual issue.

The javascript items have two preferred locations: 1. As .js files on the web server or 2. embedded in your master page. Just do option 1, they will be cached by the web server. Further, they will be cached by the client browser meaning you won't have to

For your header and footer, the code for this should be in your master page. Don't do server side includes, that just complicates things. Build a normal .net website that leverages master pages for your "chrome" content. You can enable partial page caching at the application level which will handle all of caching for you.

When you update the header or footer content, just redeploy the site.

于 2010-12-16T21:45:51.920 回答
0

将页眉和页脚存储在文件中并使用Server Side Includes。某些 Web 服务器 (IIS 6.0) 可能允许您将文档页脚添加到所有页面。

将您的 Javascript 存储在文件中并在您的页面中使用。这将允许缓存并提高页面性能。

于 2010-12-16T17:42:16.293 回答