ASP.NET缓存W /文件相关性:静止无功与ASPNET缓存memcached的对比 [英] ASP.NET caching w/file dependency: static var vs. AspNet cache vs. memcached

查看:170
本文介绍了ASP.NET缓存W /文件相关性:静止无功与ASPNET缓存memcached的对比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR:这可能是速度快:访问静态局部变量,访问存储在HttpRuntime.Cache变量,或访问存储在memcached的变量

在工作中,我们获得约20万页面访问量/天。在我们的主页,我们会显示一个推广。这种宣传是针对不同用户的不同,基于他们的起源和语言的国家。

At work, we get about 200,000 page views/day. On our homepage, we display a promotion. This promotion is different for different users, based on their country of origin and language.

所有不同的促销活动在每个Web服务器上的XML文件中定义。我们有12个网络服务器都提供相同的XML文件的同一站点。有基于国家/语言约50不同的促销组合。我们想象我们永远不会有超过200左右(如果有的话),促销(组合)总。

All the different promotions are defined in an XML file on each web server. We have 12 web servers all serving the same site with the same XML file. There are about 50 different promotion combinations based on country/language. We imagine we'll never have more than 200 or so (if ever) promotions (combinations) total.

XML文件可以在任何时候都可以改变了发布周期。当它改变时,促销的新定义,应立即更换现场网站上。为实现这一要求的功能是另一开发商和我。

The XML file may be changed at any time, out of release cycle. When it's changed, the new definitions of promotions should immediately change on the live site. Implementing the functionality for this requirement is the responsibility of another developer and I.

本来,我写了code,这样XML文件的内容进行解析,然后存储在一个类的静态成员。 A FileSystemWatcher的监测变化的文件,只要文件被改变了,XML将被重新加载/重新解析和静态成员将与新的内容进行更新。看起来像一个坚实的,简单的解决方案,以保持在内存中的字典促销与XML文件电流。 (每个服务器与当地的XML文件的副本indepedently这样做;所有的XML文件是在同一时间同一和变化)

Originally, I wrote the code so that the contents of the XML file were parsed and then stored in a static member of a class. A FileSystemWatcher monitored changes to the file, and whenever the file was changed, the XML would be reloaded/reparsed and the static member would be updated with the new contents. Seemed like a solid, simple solution to keeping the in-memory dictionary of promotions current with the XML file. (Each server doing this indepedently with its local copy of the XML file; all XML files are the same and change at the same time.)

其他的开发者,我正在拥有高级职位,并决定,这是没有好处的。相反,我们应该存储在所有的促销活动每个服务器的 HttpContext.Current.Cache 与自动监控的的CacheDependency 文件相关性文件的变化,清空缓存的促销活动时,该文件的变化。虽然我很喜欢,我们不再需要使用 FileSystemWatcher的,我担心一点点从volitile缓存,而不是一个静态类成员抓住促销活动会少高性能。

The other developer I was working holds a Sr. position and decided that this was no good. Instead, we should store all the promotions in each server's HttpContext.Current.Cache with a CacheDependency file dependency that automatically monitored file changes, expunging the cached promotions when the file changed. While I liked that we no longer had to use a FileSystemWatcher, I worried a little that grabbing the promotions from the volitile cache instead of a static class member would be less performant.

(护理对这一问题有何评论?我已经放弃了主张不切换到HttpRuntime.Cache。)

(Care to comment on this concern? I already gave up trying to advocate not switching to HttpRuntime.Cache.)

后来,我们开始使用 HttpRuntime.Cache ,我们通过与Enyim memcached的作为我们的其他业务问题(例如搜索结果).NET接口。当我们这样做,这种高级开发者决定,我们应该使用memcached的,而不是的httpRuntime 的HttpContext 缓存存储促销活动。上级说,是啊,听起来不错,并给了他的memcached的专用服务器只为这些促销活动。现在,他目前正在实施的更改使用memcached来代替。

Later, after we began using HttpRuntime.Cache, we adopted memcached with Enyim as our .NET interface for other business problems (e.g. search results). When we did that, this Sr. Developer decided we should be using memcached instead of the HttpRuntime (HttpContext) Cache for storing promotions. Higher-ups said "yeah, sounds good", and gave him a dedicated server with memcached just for these promotions. Now he's currently implementing the changes to use memcached instead.

我怀疑这是一个很好的决定。相反,住在进程和抓住从本次促销活动数据的 HttpRuntime.Cache ,我们现在打开一个套接字连接到网络memcached服务器并将其值传送到我们的Web服务器

I'm skeptical that this is a good decision. Instead of staying in-process and grabbing this promotion data from the HttpRuntime.Cache, we're now opening a socket to a network memcached server and transmitting its value to our web server.

这必须小于高性能的,对不对?即使缓存memcached的。 (我没有编译任何性能指标还没有机会。)

This has to be less performant, right? Even if the cache is memcached. (I haven't had the chance to compile any performance metrics yet.)

在最重要的是,他将不得不在工程师的memcached自己的文件相关解决方案,因为它并没有提供这样的设施。

On top of that, he's going to have to engineer his own file dependency solution over memcached since it doesn't provide such a facility.

难道我原来的设计是最好的吗?这是否让你觉得过度设计?为 HttpRuntime.Cache 缓存或memcached的缓存甚至是必要的?

Wouldn't my original design be best? Does this strike you as overengineering? Is HttpRuntime.Cache caching or memcached caching even necessary?

推荐答案

不知道到底有多少你所谈论的(假设这不是很多)的数据,我倾向于有点同意你的看法;原始速度明智的,静态的成员应该是'最快',那么缓存。这并不一定意味着它是最好的选择,当然。可扩展性并不总是与速度有关。事实上,我们对可伸缩性做的事情往往负相关(略)影响应用程序的速度。

Not knowing exactly how much data you are talking about (assuming it's not a lot), I tend to somewhat agree with you; raw-speed wise, a static member should be the 'fastest', then Cache. That doesn't necessarily mean it's the best option, of course. Scalability is not always about speed. In fact, the things we do for scalability often negatively (marginally) affect the speed of an application.

更具体;我倾向于先从缓存对象自己,除非有点'静态'的数据是pretty混账小而pretty多少保证不断需要(在这种情况下,我去了静态成员。唐忘记线程同步过,当然!)

More specifically; I do tend to start with the Cache object myself, unless a bit of 'static' data is pretty darn small and is pretty much guaranteed to be needed constantly (in which case I go for static members. Don't forget thread synch too, of course!)

通过数据适量的,当你因为你注意到需要,通过改变文件不会经常改变的一切,可以很容易地修改,缓存对象可能是一个很好的解决方案。 memcached的可能是矫枉过正,和过于复杂的......但它应该工作了。

With a modest amount of data that won't change often at all, and can easily be modified when you need to, by altering the files as you note, the Cache object is probably a good solution. memcached may be overkill, and overly complex... but it should work, too.

我觉得主要可能的负面的memcached的解决方案是单点故障的问题;使用本地服务器的缓存保持相互隔离的服务器。

I think the major possible 'negative' to the memcached solution is the single-point-of-failure issue; Using the local server's Cache keeps each server isolated.

这听起来像有可能不是真的你的情况任何选择,政治上。但我认为你的推理未必那么糟糕,因为你在这里分享的内容!

It sounds like there may not really be any choice in your case, politically speaking. But I think your reasoning isn't necessarily all that bad, given what you've shared here.

这篇关于ASP.NET缓存W /文件相关性:静止无功与ASPNET缓存memcached的对比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆