Basic features
- The core functions of the mc is the Key-Value memory management, value up to 1M, does not support complex data structures.
- mc not persistent.
- mc support key expired.
- mc continuous operation rarely appear memory fragmentation, speed will not degrade over time.
- 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