in order to speed up file access and provide multiple users, management that needs to establish memory cache data in memory reduces the number of read-write disks and ensures data updates, because cache caching is required. 1, Memcached main features a, data only exist in memory, downtime or restart data will all fail B, the content data reached the start of the set memory specified value, based on the LRU algorithm to delete the cache, lazy mode, you can specify the maximum memory usage. c, the actual bottleneck is the network connection, the need for less CPU resources D, server-side no distributed function (C development), depending on the implementation of the client (PHP, C #, Java), the deployment of more than one server, access to do a balanced strategy, such as IP-based allocation of the connection load. E, stored node data key name 250 bytes, the key value is limited to 1MB, only suitable for ordinary string, as a small-scale data distributed platform is very effective. F, 32-bit machine single process using maximum memory 2G, can be divided into multiple ports open multi-process support, 64-bit machine can be considered unlimited 2, Data directly to the memory need to solve the problem: A, can not be distributed extension B, lack of a valid information expiration mechanism C, multiple concurrent use of shared use of the failure mechanism D, file FD can not be asynchronous, unable to join the asynchronous IO High-speed concurrent access system  3, distributed cluster build a, by memcached Private communication protocol with the Daemon Communication B, nginx through the upstream protocol communication, access server misses can only access the Memcached client to obtain data and actively write data to the memcached server. C, lack of certification and security control, placed behind the firewall D, the client through a consistent hash to build a distributed cache system, while the machine and the cache key for the data hash, the use of virtual nodes to reduce the minimum data migration. 4, how to add and delete entries A, add data via Set/add/replace and set entry expiration time and data length B, delete delete C, information access only provides simple cache kv type data structure D, available flush_ All clears all key values, marks all item invalidation, and memory is reusable.  5, server expansion and disaster preparedness A, server can be expanded at any time, need to support dynamic modification of access policy B, server down the cache data all failed, unable to prepare disaster 6, memory efficiency using slab allocator mechanism allocation, management memory. The total allocated memory is divided into a specific length block according to the pre-defined size by the increase factor. A, according to the minimum space loss principle, allocate the closest slab space B, perform get to check the timestamp, avoid monitoring CPU resource C, new object join or find the closest to slab space, and can not use other slab, can only reassign page, memory waste serious. D, when the memory is low, the LRU delete record is started, the non-expired record may be deleted, and the cache utilization is decreased. Several terms: PagE: The memory space allocated to slab, which is 1MB by default. After assigning to slab, the slab is divided into chunk according to the size of the. Chunk: The memory space used to cache records. Slab class: A group of chunk of a specific size. Growth Factor: Growth factor, default is 1.25
Memcached characteristics and advantages and disadvantages