NHibernate - Memcached 性能不佳
我安装了 Membase 并创建了一个新的 memcached 存储桶。在设置中,为了简单起见,我选择设置端口 ID 为 1111 的专用端口。
在我的 web.config 中,我有这个:
<configSections>
<section name="memcache" type="NHibernate.Caches.MemCache.MemCacheSectionHandler, NHibernate.Caches.MemCache" requirePermission="false" />
...
</configSections>
<memcache>
<memcached host="127.0.0.1" port="1111" />
</memcache>
在我的 NHibernate 配置部分:
<property name="cache.use_query_cache" >true</property>
<property name="cache.use_second_level_cache">true</property>
<property name="cache.provider_class">NHibernate.Caches.MemCache.MemCacheProvider, NHibernate.Caches.MemCache</property>
在每个 NHibernate 类映射中,我在类标记之后的右上角都有这个:
<cache usage="nonstrict-read-write" />
当我运行这个时,我的查询比 if 慢一个数量级我正在使用 Syscache。有什么看起来不对劲的地方吗?我对设置这样的东西相当陌生。
预先感谢您的任何帮助。
I installed Membase and created a new memcached bucket. In the settings, I chose to setup a dedicated port with port ID of 1111 for simplicity sake.
In my web.config I have this:
<configSections>
<section name="memcache" type="NHibernate.Caches.MemCache.MemCacheSectionHandler, NHibernate.Caches.MemCache" requirePermission="false" />
...
</configSections>
<memcache>
<memcached host="127.0.0.1" port="1111" />
</memcache>
In my NHibernate config section:
<property name="cache.use_query_cache" >true</property>
<property name="cache.use_second_level_cache">true</property>
<property name="cache.provider_class">NHibernate.Caches.MemCache.MemCacheProvider, NHibernate.Caches.MemCache</property>
In each of my NHibernate class mappings, I have this at the top right after the class tag:
<cache usage="nonstrict-read-write" />
When I run this, my queries are an order of magnitude slower than if I was using Syscache. Is there anything that looks wrong? I am fairly new to setting something like this up.
Thanks in advance for any assistance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的配置似乎没有任何明显的问题。 Syscache 使用 ASP.NET 缓存提供程序,并且您的应用程序和缓存之间没有网络通信,但理论上它仍然应该只比本地主机上运行的 memcached 快一点(假设您有足够的内存来避免交换)。
您可能想尝试使用分析器运行您的应用程序,以查看时间实际花在哪里。此外,您还应该确保 memcached 实际上用于返回缓存的查询,并且不会发出 sql 查询 - 记录 sql 并期望仅在第一次执行查询时看到它。
我正在将 membase 与 memcached 存储桶 和 enyim memcached 客户端,配置与您类似我对这次的表现非常满意。 membase 还提供了一个很好的管理控制台,您可以在其中查看有关缓存使用情况的各种有用的统计信息。
另外,与您的问题无关,但请确保您在启用查询缓存之前了解查询缓存的工作原理。请参阅两个 帖子 来自阿延德。
You don't seem to have any obvious problems in your configuration. Syscache is using the ASP.NET cache provider and there is no network communication between your app and the cache, but still it should in theory only be a little faster than memcached running on localhost (this assuming you have enough memory to avoid swapping ).
You might want to try to run your app with a profiler to see where the time is actually spent. Also you should make sure that memcached is actually used to returned the cached queries and no sql query is issued - log the sql and expect to see it only the first time the query is executed.
I'm using membase with a memcached bucket and the enyim memcached client, with a configuration similar to yours and i'm very pleased with the performance. The membase also provides a nice administration console where you can see various useful statistics about cache usage.
Also, not related to your question but, make sure you understand how query caching works before enableing it. See this two posts from ayende.