I have been testing spymemcached and xmemcached clients. I have been trying to find answers in the projects documentation but it is very poor.
My questions are regarding
Spymemcached doesn't provide a connection pool, so every time I create a
MemcachedClient
instance I am creating a new connection right?
Yes, every time you create a new MemcachedClient object you create a new connection. Each connection appear asynchronous to the application so even having one connection will probably be enough for your application. Some people do however build a connection pool of MemcachedClients though.
Then when should I close the connection?
You shut down connections as soon as you no longer need to communicate with memcached. If you application is short lived you need to shutdown the connection in order to get the jvm to stop since MemcachedClient connections are daemon connections by default.
Should I provide the same instance to all the threads in my application or create a new one every time?
Use the same connection with multiple threads. Creating a new connection for each call will cause a significant performance drop because of the overhead of creating a TCP connection.
xmemcached does have a connection pool. In this case should I close connections I get from the pool?
I'm not familiar with xmemcached, but I would imagine you would only want to create a few (16 maybe) threads and share them with your application threads for the best performance.