Memcached Notes--(iii) Summary of the use of memcached

Source: Internet
Author: User
Tags memcached serialization
In order to synchronize n front-end data through the memcached to complete the data through, but brought some new problems:
Using Ibatis to consolidate the memcached,ibatis generates a unique identity for each server, causing the same data SQL to produce different keys, resulting in duplicate caching. --by rewriting the ibatis part of the original code, terminated the generation of the unique identity, the same SQL generated the same key, the generation of key to do hash, control the length, so that the data unified in the memcached. In order to cater to the Ibatis architecture, caching data is managed by Cachemodel mode. The first implementation of Cachemodel through a map is the simple key corresponding to the final object. In order to operate the data in the background, the front desk can respond in time to Cachemodel as the datum point. Background operation data, do flush, empty corresponding Cachemodel, can synchronize data in time. However, classnotfonudexception (CNF) occurs when a Cachemodel (MAP) deserialization is invoked because the front and back domain objects may be inconsistent. --Change the Cachemodel map implementation to Set,cachemodel only save the key,object that needs to be flush cached in the original way. Used to Ehcache, and rarely put list<list> such heavyweight objects into the cache. Even so, as long as the Ehcache did not throw the exception, we are afraid that there is no perception. This time switch to memcached, did not notice the cache list too large, resulting in "cannot cache data larger than 1MB memcached", that is, cache object volume can not exceed 1mb--use memcached data compression, optimize SQL, Can be maintained for a while.

RELATED Links:
Memcached notes-(i) Installation & General error & Monitoring
Memcached Notes--(ii) xmemcached&spring integration
Memcached Notes--(iii) Summary of the use of memcached
Memcached Notes--(iv) responding to high concurrent attacks


Said so much, briefly summarized as follows:
memcached key, to eliminate the use of space, and length control in 250 characters. memcached value, to control the volume, must be less than 1MB, when necessary to use compression. The expiration time, 0 is permanent, the maximum value must not exceed 30 days (2592000s), otherwise the recalculation may cache only 1 secondsMemcached only supports the LRU algorithm, fully applicable to your needs. Try not to throw the list of heavy volume objects into the memcached, transmission, storage will create bottlenecks. Use the consistent hashing algorithm to improve multiple MEMCACEHD server utilization.



For the use of xmemcached implementations, refer to the following implementations:
Java Code Private Memcachedclientbuilder Creatememcachedclientbuilder (properties properties) {String addresses = Properti Es.getproperty (ADDRESSES). Trim (); if (logger.isinfoenabled ()) {Logger.info ("Configure properties:[addresses =" + addresses + "]);} Memcachedclientbuilder builder = new Xmemcachedclientbuilder (addrutil.getaddresses (addresses)); Use binary file Builder.setcommandfactory (new Binarycommandfactory ()); Use the consistent hashing algorithm (consistent hash strategy) Builder.setsessionlocator (New Ketamamemcachedsessionlocator ()); Use serialization transfer encoding Builder.settranscoder (new Serializingtranscoder ()); Data compression, greater than 1KB compression Builder.gettranscoder (). Setcompressionthreshold (1024); return builder; }
	Private Memcachedclientbuilder Creatememcachedclientbuilder (
			properties properties) {
		String addresses = Properties.getproperty (ADDRESSES). Trim ();

		if (logger.isinfoenabled ()) {
			logger.info ("Configure properties:[addresses =" + addresses + "]);
		}
		Memcachedclientbuilder builder = new Xmemcachedclientbuilder (
				addrutil.getaddresses (addresses));

		Use binary file
		builder.setcommandfactory (New Binarycommandfactory ());
		Use the consistent hashing algorithm (consistent hash strategy)
		Builder.setsessionlocator (New Ketamamemcachedsessionlocator ());
		Use serialization transfer encoding
		Builder.settranscoder (new Serializingtranscoder ());
		Data compression, greater than 1KB compression
		builder.gettranscoder (). Setcompressionthreshold (1024);

		return builder;
	}

There are mainly the following reference points:
Use a consistent hashing algorithm to compress data using the binary file pattern with serialization encoding

About Set&add
Set&add is an update operation, you must first apply for memory SET, will erase the corresponding memory of this key, regardless of whether the original content ADD, will first see the corresponding memory of this key is content, if there is, then wait; if not, get the lock and update the memory.


Cache Hit ratio, it is generally considered that the design of cache hit rate less than 95% is unreasonable, there are design defects.




This is my online server, after optimized to get the best results.

RELATED Links:
Memcached notes-(i) Installation & General error & Monitoring
Memcached Notes--(ii) xmemcached&spring integration
Memcached Notes--(iii) Summary of the use of memcached
Memcached Notes--(iv) responding to high concurrent attacks



Memcached ppt Reference size: 50.7 KB size: 60.4 KB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.