In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1. Memecached introduction
Is an open source, high-performance in-memory caching software, by temporarily caching all kinds of data in the database in a planned memory space, in order to reduce the business's direct and high concurrent access to the database, so as to improve the database access performance and accelerate dynamic services.
Memcache is based on libevent event handling, using this library for asynchronous event handling.
2. The application of memecached in enterprises.
1) as the front-end cache application of the database, full cache and hot cache
2) session session shared storage as a cluster
3. The workflow of memecached service in enterprise business.
1) when the web program accesses the back-end database, it accesses the memcached memory cache first. If the cache hits the data, it directly obtains the data and returns it to the front-end user. If the data is not hit, the program requests the back-end database server to obtain the corresponding data, then returns the data to the front-end user and stores the data in memcached memory for caching, waiting for the next request for access.
2) when the program updates, modifies or deletes the existing data in the database, it will send a request to notify the same ID memory that memcached has cached at the same time, so as to ensure that the data in memcache is consistent with that in the database.
3) the database plug-in can automatically push the updated data to memcached cache after it is written to the updated database.
4. Implementation of memcached service distributed cluster.
In the memcached cluster, each memcache server does not communicate with each other and is individual. Each server only manages the data of its own server. The sum of the cached data of all memcached servers is the whole data in the database.
1) Program-side implementation: the program loads the ip list of all memcached, and does hash (consistent hash) to key.
2) load balancer: (LVS keplaved)
Consistent hash: ensure that only one corresponding server is requested for each object, and that data updates are minimized when the node goes down.
5. The characteristics and working principle of memcached service.
1) completely memory-based
2) nodes are independent of each other
3) based on the asynchronous Istroke O model, libevent is used as event notification mechanism.
4) cached data exists in the form of key/value pairs
5) cplash mode architecture, written in c language, with a total code of more than 2000 lines
6) all data is stored in memory, no persistent storage design, restart service data will be lost.
7) you can set the expiration time for the stored data. The service itself does not monitor the expiration. Instead, check the key timestamp to determine whether it expires during access.
8) memcached memory allocation mechanism is to divide specific memory into blocks, and then group multiple blocks.
6. Memcached memory management mechanism
The full name of malloc is memory allocaion, which is called dynamic memory allocation in Chinese. When you can't know the specific location of memory, if you want to bind memory space, you need to use dynamic memory allocation.
The early memcached memory management method is the memory allocated by malloc. After using it, recovering the memory will produce fragments, which will reduce the memory management of the operating system, increase the burden of the operating system memory manager, and cause the operating system to be slower than the local memcached process. In order to solve the above problems, the slab allocator memory allocation mechanism was born.
The principle of Slab Allocation mechanism is that according to the predetermined size, the memory allocated to memcached is divided into specific length memory blocks, and then the same size memory blocks are divided into groups, these memory blocks will not be released and can be reused.
The memcached server stores a list of free chunk in the slab. Select chunk according to the list, and then store the data in it. When there is data in it, memcached will allocate a minimum memory block (chunk) that can store the data according to the size of the data and the slab with the most appropriate data size. For example, 100byte data is allocated to a 112byte block of memory, thus wasting 12 bytes of memory, which is a disadvantage of the slab allocation mechanism.
1) the main terms of slab allocation:
Page: the memory space allocated to slab. The default is 1MB. After being allocated to slab, it is split into chunk according to the size of slab.
Chunk: memory space or block of memory used to cache data
Slab class: a collection or group of multiple chunk of a specific size
2) Optimization of memcached slab allocation memory management mechanism:
Specify the "- f" parameter at startup to control the size difference between memory groups. When using memcached in an application, you usually do not reset this parameter. The default value is 1.25.If you want to optimize the memory use of memcached, you can consider recalculating the expected average length of the data and adjusting this parameter to get the appropriate setting value.
-f chunk size growth factor (default:1.25)
For example:
With 2, the size of the chunk increases by a multiple of 2:
Memcached-m 512m-d-u root-c 8192-f 2-vv [root@zxq tmp] # slab class 1: chunk size 96 perslab 10922slab class 2: chunk size 192 perslab 5461slab class 3: chunk size 384perslab 2730slab class 4: chunk size 768 perslab 1365slab class 5: chunk size 1536 perslab 682slab class 6: chunk size 3072 perslab 341slab class 7: chunk size 6144 perslab 170slab class 8: Chunk size 12288 perslab 85slab class 9: chunk size 24576 perslab 42slab class 10: chunk size 49152 perslab 21slab class 11: chunk size 98304 perslab 10slab class 12: chunk size 196608 perslab 5slab class 13: chunk size 393216 perslab 2slab class 14: chunk size 1048576 perslab 1
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.