Memcache is a free, open source, high-performance, distributed distributed memory object caching system. This system can improve the access speed of websites, especially for some large websites that require frequent access to databases. The improvement effect is very significant.
Why use Memcache?
Mainly used in dynamic web applications to reduce the load on the database.
It reduces the number of database reads by caching data and objects in memory,
thereby improving the speed of website access.
The implementation principle of Memcache
The atoms processed by memcache are each key and val. The key will be converted into a hash key through a hash table, which is convenient for search, comparison and matching. Hashing possible. At the same time, mem uses a two-level hash, which is maintained through a hash table.
Memcache has two core components: server and client
In a memcache component query, the client first determines the location of kv on the service side through the hash value of the key. When the server side determines Afterwards, the client will send a request to the server. Let it find the exact data, because there is no interaction or multicast protocol, so mem has minimal impact on the network
Memcache Features and Limitations
In There is no limit to the amount of item data that can be saved in Memcached, as long as there is enough memory.
The maximum memory used by a single Memcached process in a 32-bit system is 2G. If it is used in a 64-bit system, there is no limit. This is because the 32-bit system limits a single process to use up to 2G of memory. To use more memory, Multiple Memcached processes can be opened on multiple ports.
The maximum data expiration time is 30 days. If set to permanent, it will also expire at this time. Constant REALTIME_MAXDELTA
60*60*24* 30 control
The maximum key length is 250 bytes. If it is larger than this length, it cannot be stored. Constant KEY_MAX_LENGTH 250 control
The maximum data for a single item is 1MB. Data exceeding 1MB will not be stored. Constant POWER_BLOCK 1048576 Control,
It is the default slab size
The maximum number of simultaneous connections is 200, controlled through freetotal in conn_init(), the maximum number of soft connections is 1024, through
Settings.maxconns=1024 for control
Parameters related to space occupancy: settings.factor=1.25, settings.chunk_size=48, affecting slab data occupancy and stepping method
memcached is A non-blocking socket communication service based on the libevent library. Due to non-blocking communication, the memory reading and writing speed is very fast.
Memcached is divided into server and client. Multiple servers and clients can be configured. It is widely used in distributed services.
Memcached is very effective as a small-scale data distribution platform.
Memcached has a one-to-one correspondence between key and value. The default key size cannot exceed 128 bytes. The default value size is 1M, which is one slab. If you want to store 2M values (continuous), you cannot use two Slabs, because the two slabs are not continuous and cannot be stored in the memory, the size of the slabs needs to be modified. When multiple keys and values are stored, even if the slabs are not fully utilized, other data will not be stored.
memcached can already support language clients such as C/C, Perl, PHP, Python, Ruby, Java, C#, Postgres, Chicken Scheme, Lua, MySQL and Protocol.
Recommended tutorial: "PHP"
The above is the detailed content of What does Memcache mean?. For more information, please follow other related articles on the PHP Chinese website!