How to connection pool memcached in Java (spymemcached)
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>
.
Spymemcached 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.
More generally - what's the most "moral" way to make my application tolerant against loss of connection?
Like 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.