Memcache knowledge

Basic features

  1. The core functions of the mc is the Key-Value memory management, value up to 1M, does not support complex data structures.
  2. mc not persistent.
  3. mc support key expired.
  4. mc continuous operation rarely appear memory fragmentation, speed will not degrade over time.
  5. mc using non-blocking IO multiplexing network model, the use of multi-threading model listener thread / worker threads.

 

Why only string structure

  mc is designed by way of services, rather than manage KV library, which is designed not to complex data structure and persistence.

 

mc expiration of key way

  Lazy eliminated.

  item does not actively eliminated, only get, find expired were eliminated.

 

If you run out of memory, it does not crowd out existing item

  To. Using LRU elimination mechanism.

  Elimination algorithm is commonly used FIFO and LRU:

    • FIFO (first in first out): the first item out of the first set
    • LRU (least recently used): the least recently used item out of first

  LRU algorithm requires two additional properties:

    • Recent item access count
    • Recent item access time

  

mc why so few memory fragmentation

  Allocate memory in advance. No memory storage unit store only one item

  

mc Why use non-blocking IO multiplexing network model, using the listener thread / multi-threaded model worker threads

  The purpose is to improve the throughput.

  Take advantage of multicore multithreaded tender, but there will be lock conflicts.

  

mc way to find the key

  By hash table lookup to resolve the conflict through hash list

  

How hash expansion

  item hash total to 1.5 times the length, hash dynamically expansion.

  hash extension, there will be a dedicated thread to implement. Part of the hash table buckets shackles, data migration, unlocked.

    1. To ensure that there will be no long blocked.

    2. Ensure that the old and the new item does not match the hash table.

  If the migration has inserted a new item, then according to the position of the barrel,

    1. have migrated, with a new

    2. No migration, with the old

Guess you like

Origin www.cnblogs.com/lqyy/p/11031944.html