Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top