Memcached power to write to all servers in the pool

I thought a bit about making sure that the specific key applies to ALL memcached servers in the pool.

My current, untested solution is to create another memcached instance, something like this:

$cluster[] = array('host' => '192.168.1.1', 'port' => '11211', 'weight' => 50); $this->tempMemcached = new Memcached; $this->tempMemcached->addServers($cluster); foreach ($this->cluster() as $cluster) { $this->tempMemcached->setByKey($cluster, $key, $value, $this->compress, $expireTime); } $this->tempMemcache->close(); 

What is common in this case when certain keys must be stored on ALL servers for reliability?

+4
source share
3 answers

I think you are not using memcached as it was intended. Check the FAQ : you should only store a single copy of your product, which, according to the hash algorithm used, will put your item on a specific node.

Now, if you want the element to be available in all for nodes, the only way to do this is to repeat, just like you do now.

I hope your code handles cases where this element is not found in the cache.

+6
source

I think you are missing the memcached point. This is not for reliable data storage. This is for VERY quick access to cached data. If you want redundancy, try a NOSQL database like MongoDB ...

In addition, creating multiple connections will be bad for performance and redundancy (the more connections it needs to make, the more likely it is that something will go wrong, and the more you need to do for each request).

To simplify, not to complicate ...

+4
source

We had to "spread" the load on the key, which often gets on memcache servers. We do this by simply adding a random number 0-N, where N is a multiple of the number of instances you have configured. If you miss, you will go to the source (database, whatever). I say several times, since memcache hashes are against your key, you may get a bucketing collision without knowing.

This can lead to an increase in reading costs from the source (proportional to your N edge), but it allows you to distribute the load by one key in all copies, keeping these boxes happy.

But yes, this is not for redundancy, but for load balancing.

+1
source

Source: https://habr.com/ru/post/1310682/


All Articles