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

666 views Asked by At

How can we use persistent connections to memcached servers using xmemcached or spymemcached? I am presently using xmemcached.

MemcachedClientBuilder builder = new XMemcachedClientBuilder(
    AddrUtil.getAddresses(
        "127.0.0.1:11211 127.0.0.1:11311" 
    )
);
builder.setConnectionPoolSize(5);

With this code I tried to create connection pool and I used ss command to watch the connections being made. However, I can see that when program terminates connections go to time-wait state and next time I run it, more connections are created. So this is not working. What am I missing? Or what can be done in this case? Please help

1

There are 1 answers

2
mikewied On BEST ANSWER

In spymemcached all connections are persistent. The reason that your socket are in time-wait state after the program terminates is likely because you have to call some sort of shutdown() function to actually close the sockets. At least this is the case in spymemcached. I would also bet that this is the case in xmemcached.