`
michaelljx
  • 浏览: 9194 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

MemcachedClient Configuration(from githun)

    博客分类:
  • Web
 
阅读更多

You have two options to configure the MemcachedClient:

  • using the app.config,
  • providing an object which implements IMemcachedClientConfiguration

App.config (or web.config) is recommended when your pool is static or you rarely change it. Use the programmatic configuration (either implementing the interface or just using the MemcachedClientConfiguration) when your application has a custom configuration mechanism and you need to integrate memcached there.

App.config

This is a full configuration file:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <configSections>

    <sectionGroup
 name=
"enyim.com"
>

      <section
 name=
"memcached"
 type=
"Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching"
 />

    </sectionGroup>

  </configSections>


  <enyim.com>

    <memcached
 protocol=
"Binary|Text"
>

      <servers>

        <!-- make sure you use the same ordering of nodes in every configuration you have -->

        <add
 address=
"ip address"
 port=
"port number"
 />

        <add
 address=
"ip address"
 port=
"port number"
 />

      </servers>

      <socketPool
 minPoolSize=
"integer"
 maxPoolSize=
"integer"
 connectionTimeout=
"timespan"
 deadTimeout=
"timespan"
 />

      <locator
 type=
"fully qualified type name"
 factory=
"fully qualified type name"
 />

      <transcoder
 type=
"fully qualified type name"
 factory=
"fully qualified type name"
 />

      <keyTransformer
 type=
"fully qualified type name"
 factory=
"fully qualified type name"
 />

      <performanceMonitor
 type=
"fully qualified type name"
 factory=
"fully qualified type name"
 />

    </memcached>

  </enyim.com>

</configuration>

All elements are optional except where specified.

enyim.com/memcached

This section is used as default, if no other config is provided to the client.

  • protocol (optional) : Specify which protocol the client should use to communicate with the server. Binary is recommended, unless you're using an ancient version of Memcached (1.4 or below). The default is Binary .

memcached/servers (required)

Add each of your memcached server's address and port here. Both IP addresses and host names are supported.

Make sure you use the same order in every configuration you have in the application (for example on each web server in your cluster), otherwise the consistent hashing algorithm may assign items to nodes differently.

memcached/socketPool

Defines how the client should handle the connections to the Memcached servers. All attributes are optional.

  • minPoolSize : The minimum number of connections opened to each Memcached server. Default is 10 .
  • maxPoolSize : The maximum number of connections that can be opened to each Memcached server. Default is 20 .
  • connectionTimeout : The amount of time the client is waiting to establish a connection to the memcached server. If it times out the current operation will fail and the node will be marked as unresponsive.
  • deadTimeout : The amount of time the client is waiting to check the state of an unresponsive node. Default is 00:00:10 .
  • queueTimeout : The amount of time the client is waiting to acquire a socket when the pool reached maxPoolSize . If it times out the current operation will fail and the node will be marked as unresponsive. Default is 00:00:00.100 (100msecs). New in 2.8+

Both minPoolSize and maxPoolSize must be greater than zero. The recommended value for maxPoolSize is 0.75 * (number of threads) to avoid thread starvation when one of the nodes becomes unresponsive.

The connection pool works the following way:

  1. When the client is initialized, it opens minPoolSize connections to each server defined in memcached/servers . The client will wait for connectionTimeout to establish a connection. If it expires, the node will be marked as dead.
  2. Each operation takes a socket from the pool
  3. If the pool has no unused connection but it did not reach maxPoolSize , then a new socket will be created. The client will wait for connectionTimeout to establish the connection. If it expires, the node will be marked as dead.
  4. If the pool has no unused connection and it did reach maxPoolSize (a semaphore is used to track this), the client will wait for queueTimeout . If it still cannot acquire one, the node will be marked as dead. The the pool only gets full when a) maxPoolSize is to low while the load is high, or b) a node goes down. A low value here ensures that the application will not eat up all threads while waiting for all connections to timeout when a node goes down.
  5. The first time a node goes down a timer will be started which will periodically (see deadTimeout ) check the marked nodes if they are available. The timer will be stopped when all nodes come online.

Note : maxPoolSize had a much larger value in 2.6 and below. Until you can upgrade it's recommended to set to the optimal value in your configuration files manually (see above).

memcached/locator

Used to map objects to servers in the pool. Either type or factory must be provided (factory takes precedence if both are specified).

  • type must be the fully qualified name of a Type implementing IMemcachedNodeLocator
  • factory must be the fully qualified name of a Type implementing IProviderFactory<IMemcachedNodeLocator>

The following locators are included by default:

  • Enyim.Caching.DefaultNodeLocator, Enyim.Caching The default locator, provides consistent hashing.
  • Enyim.Caching.KetamaNodeLocator, Enyim.Caching Ketama locator, compatible with spymemcached. Uses MD5 for the hash ring. Additionally this can be specified using a factory, Enyim.Caching.KetamaNodeLocatorFactory, Enyim.Caching , so it can use different hash algorithms:
<locator
 factory=
"Enyim.Caching.KetamaNodeLocatorFactory, Enyim.Caching"

	hashName=
"md5|sha1|tiger|crc|fnv1_32|fnv1_64|fnv1a_32|fnv1a_64|murmur|oneatatime"
 />

See also IProviderFactory .

memcached/keyTransformer

Used to normalize/validate the item keys before sending them to the server. Either type or factory must be provided (factory takes precedence if both are specified).

  • type must be the fully qualified name of a Type implementing IMemcachedKeyTransformer
  • factory must be the fully qualified name of a Type implementing IProviderFactory<IMemcachedKeyTransformer>

The following transformers are included by default:

  • Enyim.Caching.DefaultKeyTransformer, Enyim.Caching It does not change the keys, only checks for invalid characters. (ASCII code < 32)
  • Enyim.Caching.TigerHashKeyTransformer, Enyim.Caching Uses TigerHash to hash the keys. Faster than SHA1, recommended when using long (> 150 chars) keys.
  • Enyim.Caching.SHA1KeyTransformer, Enyim.Caching Uses SHA1 to hash the keys.
  • Enyim.Caching.Base64KeyTransformer, Enyim.Caching Uses base-64 encoding on the item keys.

See also IProviderFactory .

memcached/transcoder

Used to serialize stored/retrieved objects. Either type or factory must be provided (factory takes precedence if both are specified).

  • type must be the fully qualified name of a Type implementing ITranscoder
  • factory must be the fully qualified name of a Type implementing IProviderFactory<ITranscoder>

See also IProviderFactory .

memcached/performanceMonitor

Used to define a performance monitor instance which can provide statistics about the client. Either type or factory must be provided (factory takes precedence if both are specified). See Configure the Performance Monitor about enabling this feature.

  • type must be the fully qualified name of a Type implementing IPerformanceMonitor
  • factory must be the fully qualified name of a Type implementing IProviderFactory<IPerformanceMonitor>

See also IProviderFactory .

IMemcachedClientConfiguration

You should implement this interface if you want to provide your own configuration mechanisms (for example, reading the config from the database), or you just need more flexibility.

There is a default implementation included: Enyim.Caching.Configuration.MemcachedClientConfiguration . Its properties correspond with the attributes above.

分享到:
评论

相关推荐

    memcachedclient-2.0.1.jar

    memcachedclient-2.0.1.jar 之前在网上搜了很久没搜到,所以找到了跟大家分享

    memcached安装包以及MemCachedClient

    MemcachedClient client = new MemcachedClient(AddrUtil.getAddresses("localhost:11211")); // 设置 key-value client.set("key", 30, "value").get(); // 获取 value String value = (String) client....

    memcached client for java

    memcached的java客户端jar包,方便调用memcached的服务

    c# asp.net memcached client 调用示例

    在C#代码中,可以创建一个`MemcachedClient`实例,并设置服务器的连接信息。例如: ```csharp var client = new MemcachedClient(); client.Connect("127.0.0.1", 11211); // 假设Memcached服务器运行在本地,端口...

    Memcached Java Client API详解

    Memcached Java Client API详解.doc

    memcaChed java client jar包

    MemcachedClient client = new MemcachedClient(new InetSocketAddress("localhost", 11211)); ``` 这里`localhost`是Memcached服务器的地址,`11211`是默认的Memcached端口号。 2. 存储数据: ```java client.set...

    Memcached Client 使用手册

    ### Memcached Client 使用手册 #### Cache Client 接口定义与功能概述 - **ICache**:作为缓存的基础接口,提供了缓存的基本操作方法。这些方法涵盖了缓存数据的存储、检索、删除等功能,旨在为应用程序提供高效...

    spring调用memcached client for java

    &lt;property name="memcachedClient" ref="memcachedClient" /&gt; ``` 3. **启用缓存注解**:在Spring配置中开启缓存支持,并配置默认的缓存策略: ```xml ``` 4. **使用缓存**:现在,你可以在需要缓存的方法...

    C# Memcached client.zip

    "C# Memcached client.zip" 文件可能包含了一个用C#编写的Memcached客户端库的源代码,供开发者集成到他们的.NET应用中。 Memcached的工作原理是基于键值对存储,它将数据存储在内存中,以便快速访问。当应用程序...

    memcached-client.php

    memcached-client.php

    MemcachedClient4J:它是 java 的 memcached 客户端

    MemcachedClient4J 一个使用netty框架编写的mecached客户端,实现mecached ASCII协议,性能超过Spymecached。 有许多功能和扩展是完美的。 提供同步和异步两种接口,使用方法非常简单,示例如下: Memcached...

    memcached-win32-server1.26服务端与客户端Enyim.Caching与Memcached.ClientLibrary

    包含服务端: memcached-win32.server.1.2.6.0 memcached-win32.server.1.4.4 包含客户端: Enyim.Caching1.2.0.0.dll Enyim.Caching2.12.0.0.dll Memcached.ClientLibrary1.0.0 安装说明文档

    memcached for java client 例子

    "memcached for java client 例子" 指的是一个使用Java语言编写的客户端库,用于与memcached缓存系统进行交互。Memcached是一种高性能、分布式内存对象缓存系统,常用于减轻数据库负载,提升Web应用的响应速度。 **...

    Memcached.ClientLibrary.dll

    Memcached.ClientLibrary.dll Memcached.ClientLibrary.dll

    MemCached Cache Java Client封装优化历程.docx

    【Memcached 缓存系统详解】 Memcached 是一个高性能、分布式的内存对象缓存系统,主要用于减少数据库的负载,提高应用程序的性能。它通过在内存中存储数据来提供快速访问,而不是每次请求时都去查询数据库。...

    Spring memcached 源码

    要配置Spring Memcached,我们需要在Spring的配置文件(如`applicationContext.xml`)中声明`MemcachedClient`。这通常涉及到以下步骤: 1. 引入依赖:在`pom.xml`或`build.gradle`中添加`spring-memcached`的依赖...

    基于memcached client for java的cache封装

    Memcached是一种广泛使用的分布式内存对象缓存系统,它能够减轻数据库的负担,通过将常用数据存储在内存中来加速应用程序的响应速度。本主题将深入探讨如何基于Java客户端对Memcached进行封装,以便更高效地在Java...

    simple-spring-memcached集成memcache

    public MemcachedCacheManager cacheManager(MemcachedClient memcachedClient) { MemcachedCacheManager cacheManager = new MemcachedCacheManager(); cacheManager.setMemcachedClient(memcachedClient); ...

Global site tag (gtag.js) - Google Analytics