Recently, a project needs to use NO-SQL database to save a lot of data, insert and query are more frequent, relatively more frequent query. Is it the choice of memcached or Redis? Memcached and Redis to do a related test, you know.
Memcached and Redis test comparison:
1 Performance aspects:
Same number of write and read data, key is UUID, value is analog terminal information about 600 bytes
Single Thread:
Memcached write time is better than Redis, and Redis read time is better than memcached
20,000 write data, memcached write time is approximately 9000,msredis write time of about 13000MS
20,000 times read data, memcached read time is approximately 7000,msredis read time of about 6000MS
Multithreading:
Redis is better than memcached when it comes to low concurrency.
60 concurrent
Redis write 1000 data per thread, the total time is approximately 5000ms;memcached each thread writes 1000 data, the total execution time is approximately 10000ms
Redis each thread reads 1000 times of data, the total execution time is approximately 2000ms; memcached reads 1000 times per thread, and executes about 8000MS
2) Memory usage efficiency:
If you use simple key-value storage, memcached memory utilization is higher.
But if Redis uses the hash structure to do the key-value storage, because of its combined compression, its memory utilization rate will be higher than memcached.
This is related to the application scenario and the data characteristics.
Redis when physical memory is exhausted, you can swap some of the value for a long time to disk
Memcache exists in memory, the allocated memory is full, some k/v data will be deleted according to certain rules (LRU rule)
3) Data manipulation
Redis has more data structures and supports richer data operations than memcached.
Usually in memcached, you need to take the data to the client for similar modifications and set back.
This greatly increases the number of network IO and the volume of data. In Redis, these complex operations are often as efficient as the general get/set.
(4) Data persistence and data synchronization
Redis support These two, will periodically write the updated data to disk or modify the operation to write the additional record file, and on this basis to achieve master-slave (master-slave) synchronization, upgrade or restart the system can be loaded again to use, and memcached do not support
5) distributed
Both support cluster one master more from or one master one from
Summary: Both performance is relatively high, this is not a bottleneck, Redis not only support the simple k/v type of data, but also provide list,set,hash and other data structure storage, if the need for caching can support more complex structure and operation, then Redis will be a good choice. Redis, with certain characteristics of the database, you can keep the data in memory on disk, when the importance of the data is relatively high, restart upgrade system, Redis can recover some of the data by AOF.
Based on the above analysis, it is recommended to use Redis.