The Memcached (not Memcache) PECL plugin for PHP accepts a $persistent_id as part of its constructor.
The docs say:
By default the Memcached instances are destroyed at the end of the request. To create an instance that persists between requests, use persistent_id to specify a unique ID for the instance. All instances created with the same persistent_id will share the same connection.
What is the best way to use (or not use) $persistent_id on a site with multiple webservers and several shared memcached servers? In particular, if I assign the same $persistent_id always, will the "shared instance" become a bottleneck, while different php processes wait for the instance? Can additional instances with the same $persistent_id be created, by, for example, a race condition? What happens to those additional connections, if that happens? What happens to those instances between processes?
At the very least, according to my tests, more than one "connection" can have the same $persistent_id. I did a simple test where I created Memcached instances with the same $persistent_id and added different servers to them, then loaded and echoed out servers; sometimes I would get the first set, sometimes the second, always using the same $persistent_id.
Additionally, it is clear that there are issues when adding servers to one of these shared instances. Because Memcached allow you to add the same server multiple times, I've seen advice that one should check the servers with getServerList() before adding servers, and only add them if the server list is not populated. Depending on the degree to which these instances are shared, this seems like a potential race condition--is it possible that two processes could simultaneously add servers to the same instance, corrupting the server list?
Is there a way to safely share Memcached instances between processes without race conditions? Is it worth doing?