How to connection pool memcached in Java (spymemcached)
NickName:djechlin Ask DateTime:2012-05-22T03:40:30

How to connection pool memcached in Java (spymemcached)

The API I'm using, spymemcached, basically gives

MemcachedClient memc = new MemCachedClient(new InetSocketAddress("host", port));

It doesn't really give me a connect() or isConnected() function. The API offers a DefaultConnectionFactory but at first look at the code it doesn't look like it manages a connection pool. Does anyone know how to do this in spymemcached or in another Java memcached library?

More generally - what's the most "moral" way to make my application tolerant against loss of connection?

Copyright Notice:Content Author:「djechlin」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/10691528/how-to-connection-pool-memcached-in-java-spymemcached

Answers
mikewied 2012-05-22T23:25:51

When you call the MemcachedClient constructor it automatically connects to your memcached server. There is no connect() or isConnected() method. If you lose the connection with Spymemcached it will try to reconnect for you. Also, the DefaultConnectionFactory is meant to be used to specify special connection attributes (e.g. hashing method and failure mode). If you want to use a connection factory then you need to use the MemcachedClient constructor that takes a ConnectionFactory and a List<InetSocketAddress>.\n\nSpymemcached uses a single IO thread, but acts like a multithreaded client. With one thread for example, you can do up to 50k ops per second. If you want to create a thread pool then you will have to do it in your user application.\n\n\n More generally - what's the most \"moral\" way to make my application tolerant against loss of connection?\n\n\nLike I mentioned above, Spymemcached will attempt to reconnect if it loses connection to the server. This process will usually take around 17ms. Most people that use the client do however create a thread pool in their application code.",


Atul Sharma 2014-07-08T10:09:59

You can create an object pool initially.Then while performing set,delete or get operation you can borrow objects from the pool. MemcachedClient will automatically connect to the server once you invoke its constructor. ",


More about “How to connection pool memcached in Java (spymemcached)” related questions

How to connection pool memcached in Java (spymemcached)

The API I'm using, spymemcached, basically gives MemcachedClient memc = new MemCachedClient(new InetSocketAddress("host", port)); It doesn't really give me a connect() or isConnected() function. ...

Show Detail

How to cache a Memcached connection using the java spymemcached client

I am learning how to cache objects using memcached with the spymemcached client from spymemcached examples MemcachedClient c=new MemcachedClient(new InetSocketAddress("hostname", portNum)); //...

Show Detail

Java (spymemcached) and PHP (memcached)

I'm trying to build a Java app that will set data in Memcached and have a PHP script to get the same data later in the process. So far, I haven't been able to find a way to get a 100% hit rate. To ...

Show Detail

SpyMemcached and Memcached: SpyMemcached.getInstance(memcache.job) is invalid! check memcached.property

[2011-08-29 10:05:09.132]ALERT: SpyMemcached.getInstance(memcache.job) is invalid! check memcached.property . [2011-08-29 10:05:54.590]ALERT: SpyMemcached.getInstance(memcache.job) is invalid! check

Show Detail

spymemcached (Java Memcached Client)

Is there a way to collect the memcached stats using this API (spymemcached)? I know there are tools like cacti to collect information on Memcached Server. But I would like to collect, say, memory ...

Show Detail

Items set with spymemcached cannot be fetched with php memcached

I am using spymemcached. I set a couple of items. Then I run a php script, however then I cannot get all those items using php memcached. PHP-Memcached can only partially retrieve those items. I c...

Show Detail

spymemcached: how can I tell whether memcached had connected successfully?

I'm using the following library: compile 'net.spy:spymemcached:2.12.0' So if I do this, if memcachedclient is not connected successfully, it gives me an error: mc.get(myvariable) I want to ch...

Show Detail

how to make persistent connections to memcached server using xmemcached or spymemcached

How can we use persistent connections to memcached servers using xmemcached or spymemcached? I am presently using xmemcached. MemcachedClientBuilder builder = new XMemcachedClientBuilder( Add...

Show Detail

How to add memcached nodes dynamically with spymemcached

I have a Java application setup which has multiple memcached server nodes communicating with a spymemcached client. I want to know if it is possible to add or remove server nodes at runtime, without

Show Detail

memcached (spymemcached) counters and expiry time

can anybody tell me (or point to some documentation that documents) how memcached counters work? Specifically: how do they expire? I'm using the java spymemcached client. The method net.spy.mem...

Show Detail