高流量 Web 服务的提示,c# asp.net sql2000

发布于 2024-07-06 00:39:07 字数 479 浏览 9 评论 0原文

我正在开发一个 Web 服务,其方法将从“动态横幅”中调用,该横幅将显示从 SQL Server 表读取的某种消息队列。

横幅在高流量网站的主页上会产生很大的压力; 每次加载横幅时,它都会调用我的 Web 服务,以便获取新的消息队列。

现在:我不希望每次加载横幅时所有这些流量都会驱动对数据库的查询,因此我正在考虑使用 asp.net 缓存(即 HttpRuntime.Cache[cacheKey])来限制数据库访问; 我会尝试每分钟左右刷新一次缓存。

显然,我会尝试尽可能少地发送消息,以限制流量。

但也许还有其他方法来处理这种情况; 例如,我可以在文件系统上写入队列的最新版本,并让 Web 服务访问该文件; 或者混合这两种方法...

解决方案是 c# web 服务、asp.net 3.5、sql server 2000。

有什么提示吗? 其他方法?

谢谢安德里亚

I'm developing a web service whose methods will be called from a "dynamic banner" that will show a sort of queue of messages read from a sql server table.

The banner will have a heavy pressure in the home pages of high traffic sites; every time the banner will be loaded, it will call my web service, in order to obtain the new queue of messages.

Now: I don't want that all this traffic drives queries to the database every time the banner is loaded, so I'm thinking to use the asp.net cache (i.e. HttpRuntime.Cache[cacheKey]) to limit database accesses; I will try to have a cache refresh every minute or so.

Obviously I'll try have the messages as little as possible, to limit traffic.

But maybe there are other ways to deal with such a scenario; for example I could write the last version of the queue on the file system, and have the web service access that file; or something mixing the two approaches...

The solution is c# web service, asp.net 3.5, sql server 2000.

Any hint? Other approaches?

Thanks

Andrea

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

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

发布评论

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

评论(7

撩动你心 2024-07-13 00:39:07

当然,您也可以(应该)使用 SixPack 库 中的缓存功能。

  • 转发(普通)缓存,基于 HttpCache,它通过在类上放置属性来工作。 使用最简单,但在某些情况下,您必须等待实际从数据库中获取内容。
  • 从头开始预取缓存,在第一次调用后将开始在幕后刷新缓存,并且在某些情况下保证您无需等待即可获得内容。

有关详细信息,请访问 SixPack 库主页。 请注意,代码(尤其是前向缓存)经过了负载测试。

这是一个简单缓存的示例:

    [Cached]
    public class MyTime : ContextBoundObject
    {
            [CachedMethod(1)]
            public DateTime Get()
            {
                    Console.WriteLine("Get invoked.");
                    return DateTime.Now;
            }
    }

Of course you could (should) also use the caching features in the SixPack library .

  • Forward (normal) cache, based on HttpCache, which works by putting attributes on your class. Simplest to use, but in some cases you have to wait for the content to be actually be fetched from database.
  • Pre-fetch cache, from scratch, which, after the first call will start refreshing the cache behind the scenes, and you are guaranteed to have content without wait in some cases.

More info on the SixPack library homepage. Note that the code (especially the forward cache) is load tested.

Here's an example of simple caching:

    [Cached]
    public class MyTime : ContextBoundObject
    {
            [CachedMethod(1)]
            public DateTime Get()
            {
                    Console.WriteLine("Get invoked.");
                    return DateTime.Now;
            }
    }
临风闻羌笛 2024-07-13 00:39:07

谢谢大家,由于数据大小很小,但基础表会发生变化,我想我会采用 HttpCache 方式:我实际上需要一种减少数据库访问的方法,即使数据正在变化(所以这就是原因按照@Bloodhound的建议不使用直接的Sql依赖项)。

我想在上市之前我会做一些压力测试。

再次感谢大家。

Thanks all, as the data are little in size, but the underlying tables will change, I think that I'll go the HttpCache way: I need actually a way to reduce db access, even if the data are changing (so that's the reason to not using a direct Sql dependency as suggested by @Bloodhound).

I'll make some stress test before going public, I think.

Thanks again all.

属性 2024-07-13 00:39:07

此外,解决 Skliwz 提到的内存限制的一种方法是,如果您在正常应用程序之外使用此服务,您可以将其隔离在它自己的应用程序池中。 我以前见过这样做,这也有帮助。

Also, one way to get around the memory limitation mentioned by Skliwz is that if you are using this service outside of the normal application you can isolate it in it's own app pool. I have seen this done before which helps as well.

画中仙 2024-07-13 00:39:07

恕我直言,编写文件是一个更好的解决方案 - 它由 IIS 内核代码提供服务,没有巨大的 asp.net 开销,您可以稍后将文件复制到 CDN。

据我所知,SQL Server 2000 的依赖关系兑现效率不是很高。

Writing a file is a better solution IMHO - its served by IIS kernel code, w/o the huge asp.net overhead and you can copy the file to CDNs later.

AFAIK dependency cashing is not very efficient with SQL Server 2000.

[浮城] 2024-07-13 00:39:07

我认为缓存是一种合理的方法,您可以更进一步并向其添加 SQL 依赖项。

ASP.NET 缓存:SQL 缓存与 SQL Server 2000 的依赖关系

I think caching is a reasonable approach and you can take it a step further and add a SQL Dependency to it.

ASP.NET Caching: SQL Cache Dependency With SQL Server 2000

深陷 2024-07-13 00:39:07

这取决于很多事情:

  • 如果数据几乎没有变化(想想带有“发布”按钮或每日批次的后端),那么我肯定会使用静态文件(通过后端推送更新)。 我们在几个大型网站上使用了这个解决方案,并且效果非常好。
  • 如果数据足够小,内存缓存(即 Http Cache)是可行的,但要注意锁定问题,还要注意 Http Cache 在内存负载过重时无法正常工作,因为项目可能会过期如果框架需要内存,请尽早。 我以前也被它咬过! 有了上述注意事项,Http Cache 就可以很好地工作了。

It depends on a lot of things:

  • If there is little change in the data (think backend with "publish" button or daily batches), then I would definitely use static files (updated via push from the backend). We used this solution on a couple of large sites and worked really well.
  • If the data is small enough, memory caching (i.e. Http Cache) is viable, but beware of locking issues and also beware that Http Cache will not work that well under heavy memory load, because items can be expired early if the framework needs memory. I have been bitten by it before! With the above caveats, Http Cache works quite well.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文