public Memcache createMemcacheClient() throws Exception {
    String poolName = getPoolName();

    // grab an instance of our connection pool
    SockIOPool pool = SockIOPool.getInstance(poolName);

    // set the servers and the weights
    pool.setServers(getServers());
    pool.setWeights(getWeights());

    // set some basic pool settings
    pool.setInitConn(getInitConn());
    pool.setMinConn(getMinConn());
    pool.setMaxConn(getMaxConn());
    pool.setMaxIdle(getMaxIdle());

    // set the sleep for the maint thread
    // it will wake up every x seconds and
    // maintain the pool size
    pool.setMaintSleep(getMaintSleep());

    // set some TCP settings
    pool.setNagle(false);
    pool.setSocketTO(getSocketTimeout());
    pool.setSocketConnectTO(getSocketConnectTimeout());

    // initialize the connection pool
    pool.initialize();

    MemCachedClient client = new MemCachedClient(getClassLoader(), getErrorHandler(), poolName);
    client.setCompressEnable(isCompressEnable());
    client.setDefaultEncoding(getDefaultEncoding());

    return new DangaMemcache(client, poolName);
  }
 public static void setupMemCachedPool() {
   String[] servers = {MEMCACHED_SERVER_ADDR};
   SockIOPool pool = SockIOPool.getInstance();
   pool.setServers(servers);
   pool.setFailover(true);
   pool.setInitConn(10);
   pool.setMinConn(1);
   pool.setMaxConn(20);
   // pool.setMaintSleep( 30 );
   pool.setNagle(false);
   pool.setSocketTO(3000);
   pool.setAliveCheck(true);
   pool.initialize();
 }
예제 #3
0
  // 设置与缓存服务器的连接池
  static {
    String server1 = Config.getCacheServer();
    // 服务器列表和其权重
    String[] servers = {server1};
    // String[] servers = {"10.6.12.147:11211" };
    // String[] servers = {"192.168.8.129:11211" };
    Integer[] weights = {3};

    // 获取socke连接池的实例对象
    SockIOPool pool = SockIOPool.getInstance();

    // 设置服务器信息
    pool.setServers(servers);
    pool.setWeights(weights);

    // 设置初始连接数、最小和最大连接数以及最大处理时间
    pool.setInitConn(5);
    pool.setMinConn(5);
    pool.setMaxConn(250);
    pool.setMaxIdle(1000 * 60 * 60 * 6);

    // 设置主线程的睡眠时间
    pool.setMaintSleep(30);

    // 设置TCP的参数,连接超时等
    pool.setNagle(false);
    pool.setSocketTO(3000);
    pool.setSocketConnectTO(0);

    // 初始化连接池
    pool.initialize();

    // 压缩设置,超过指定大小(单位为K)的数据都会被压缩
    // mcc.setCompressEnable(true);
    // mcc.setCompressThreshold(64 * 1024);
  }