开发者

NHibernate - Poor performance with Memcached

开发者 https://www.devze.com 2023-02-27 08:30 出处:网络
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.

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开发者_StackOverflow社区>
<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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消