In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you how Redis uses different memory allocators fragment rate comparison of the relevant knowledge points, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.
In the zmalloc.c source code of Redis, we can see the following code:
/ * Explicitly override malloc/free etc when using tcmalloc. , /
# if defined (USE_TCMALLOC)
# define malloc (size) tc_malloc (size)
# define calloc (count,size) tc_calloc (count,size)
# define realloc (ptr,size) tc_realloc (ptr,size)
# define free (ptr) tc_free (ptr)
# elif defined (USE_JEMALLOC)
# define malloc (size) je_malloc (size)
# define calloc (count,size) je_calloc (count,size)
# define realloc (ptr,size) je_realloc (ptr,size)
# define free (ptr) je_free (ptr)
# endif
As we can see from the above code, when Redis compiles, it will first determine whether to use tcmalloc, and if so, it will replace the function implementation in the standard libc with the corresponding function of tcmalloc. Second, it will determine whether jemalloc makes it possible to use the memory management functions in the standard libc only if none of them are used.
In the latest version 2.4.4, jemalloc is already included in the source package as part of the source package, so it can be used directly. If you want to use tcmalloc, you need to install it yourself.
Let's briefly talk about how to install the tcmallock. tcmalloc is part of google-proftools, so we actually need to install google-proftools. If you are installing on a 64-bit machine, you need to install the dependent libunwind library first.
Wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz
Tar zxvf libunwind-0.99-alpha.tar.gz
Cd libunwind-0.99-alpha/
CFLAGS=-fPIC. / configure
Make CFLAGS=-fPIC
Make CFLAGS=-fPIC install
Comparison of fragmentation rates of Redis using different memory allocators
Then install google-preftools:
Wget http://google-perftools.googlecode.com/files/google-perftools-1.8.1.tar.gz
Tar zxvf google-perftools-1.8.1.tar.gz
Cd google-perftools-1.8.1/
. / configure-disable-cpu-profiler-disable-heap-profiler-disable-heap-checker-disable-debugalloc-enable-minimal
Make & & make install
Sudo echo "/ usr/local/lib" > / etc/ld.so.conf.d/usr_local_lib.conf # if you don't have this file, create one yourself
Sudo / sbin/ldconfig
Then install Redis and specify the appropriate parameters to enable tcmalloc during make
$curl-O http://redis.googlecode.com/files/redis-2.4.4.tar.gz
$tar xzvf redis-2.4.4.tar.gz
$cd redis-2.4.4
$make USE_TCMALLOC=yes FORCE_LIBC_MALLOC=yes
$sudo make install
After starting Redis, you can see the memory allocator used through the info command.
Let's go back to the topic of this article, for the three memory allocators for tcmalloc,jemalloc and libc. What about its performance and fragmentation rate? Here is a simple test result, with data extracted from Redis info information when using different allocators. We can see that the fragmentation rate is the lowest when using tcmalloc, which is 1.01 and 1.02, while the fragmentation rate of libc allocator is 1.31, which is as follows:
Used_memory:708391440
Used_menory_human:675.57M
Used_memory_rss:715169792
Used_memory_peak:708814040
Used_memory_peak_human:675.98M
Mem_fragmentation_ratio:1.01
Mem_allocator:tcmalloc-1.7
Used_memory:708381168
Used_menory_human:675.56M
Used_memory_rss:723587072
Used_memory_peak:708803768
Used_memory_peak_human:675.97M
Mem_fragmentation_ratio:1.02
Mem_allocator:jemalloc-2.2.1
Used_memory:869000400
Used_menory_human:828.74M
Used_memory_rss:1136689152
Used_memory_peak:868992208
Used_memory_peak_human:828.74M
Mem_fragmentation_ratio:1.31
Mem_allocator:libc
These are all the contents of the article "how Redis uses different memory allocators to compare fragmentation rates". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.