Redis INFO Order Detailed

Source: Internet
Author: User
Tags redis cpu usage server memory redis server

No code explanation is not explained, no deadline task is not a task, no flowchart or shared source reading is not the source read, no reported performance test is not performance testing. --Desert Ice Yue

This article is intended as the output of the Info command rollup, not yet completed ... 1. Environmental

Code version: redis-4.0.6
Tools: Local with Clion open, add CMakeLists.txt can be debugged.

Cmake_minimum_required (VERSION 3.6)
project (redis-4.0.6)

set (cmake_c_flags "${cmake_c_flags}-G")

add _custom_target (Redis COMMAND make cflags= "G"-C ${redis-4.0.6_source_dir} Clion_exe_dir=${project_binary_dir})
2. Memory Module

2.1 Source Location
Part of the memory module in the Redis.c:2922:info command

2.2 The output of the memory command (find an instance with a large memory fragment rate)

Used_memory: Represents the amount of memory Redis from start to now malloc, defined by ZMALLOC.C as a static global variable used_memory indicates that its value is updated each time the memory is allocated or reclaimed. Used_memory_rss: Represents the number of physical pages that the Redis process resides in memory * page size, where the number of physical pages is obtained by/proc/pid/stat, code see here, take screenshots above for example, PS command to find PID, to/proc/pid/ Look at the situation of this redis process.

$cat stat
109821 (rredis) S 1 109821 109821 0-1 4202560 1495102 0 0 0 6481 13490 0 0 20 0 6 0 2063841897 245932032 10 37 18446744073709551615 1 1 0 0 0 0 0 16781313 17610 18446744073709551615 0 0 17 2 0 0 0 0-0

The 24th field in the output is the value of the RSS, referring to the man 5/proc, its value is: 1037, which is the number of physical pages where the Redis process resides, and calculates the memory size of the Redis process: 1037 pages *4k=1037*4*1024 bytes = 4247552 bytes, you can see the same as the Used_memory_rss value. Used_memory_peak: Represents the maximum amount of memory that the Redis uses during the run, and its value is updated periodically by the Servercron () function, each time the Used_memory current value is greater than Used_memory_peak, If the value is greater than update it to the Used_memory value, the code will see here. Total_system_memory: Represents the total system memory size, get the way see here. Used_memory_lua: Indicates that the memory running Lua occupies, obtained by LUA_GC (), code see here. MaxMemory: The maximum amount of memory consumed by the user specified Redis, exceeding this value will eliminate key in accordance with the established elimination strategy. Mem_fragmentation_ratio: Memory fragment rate, its value is used_memory_rss/used_memory, and the method of calculation is shown here. If this value is close to 1, the server memory fragment is very small, Greater than 1.5 indicates a large memory fragmentation rate, for example, if the Redis process malloc 1024K of memory, the operating system assigns 256 physical pages (page size 4K) to 1024K, which means that the memory allocation is very compact, but if more than 256 or even 500, in the calculation of RS S, the 500*4k = 2000K, at this time Mem_fragmentation_ratio = 2000/1024=2, indicating a high memory fragmentation rate.

2.3 Redis4.0 New Memory command
Memory information Control more granular, but many of the methods to get the index is the original method, there is time to analyze. 3. CPU Module

3.1 Source Location
Server.c#l3274:info CPU Module

3.2 Meaning explanation
The Info CPU command allows you to view the CPU usage of the Redis process as follows:

The meanings of these several fields are as follows:

Used_cpu_sys:system CPU consumed by the Redis server 
Used_cpu_user:user CPU consumed by the Redis server
used_cpu _sys_children:system CPU consumed by the background processes
Used_cpu_user_children:user CPU consumed by the BACKGR Ound processes

3.3 What is the system CPU. What is the user CPU.
CPUs usually have three states: Idle, Idle, doing nothing. Running A user space program, run in user state, such as Shell or Chrome browser, etc. Running the kernel, run in a kernel state, manage interrupts or resources, perform system calls, such as user-state programs malloc memory, fork subprocess, and so on.

The top command allows you to view information about the CPU:

%CPU (s): 24.8 us,  0.5 sy,  0.0 ni, 73.6 ID,  0.4 wa,  0.0 hi,  0.2 si, 0.0  St

The main message of concern is these three US user states, SY kernel State, ID idle, these three values add up to nearly 100.
Other field information explanation see: Http://blog.scoutapp.com/articles/2015/02/24/understanding-linuxs-cpu-stats

3.4 Redis Info CPU information source
is actually done by calling Getrusage this system call.

NAME
     Getrusage--Get information about resource utilization
     int getrusage (int who, struct rusage);
DESCRIPTION
     Getrusage () returns information describing the "resources utilized" by the "current" process, or all it termi nated child processes.

You can count the CPU information consumed by a process, and the second parameter is the structure of the statistic information, which saves the information to the structure body for return.

So info CPU command output information is: from Redis boot to the moment, the CPU is spent in the system and user state of the cumulative time, so as long as the Redis process does not quit, this number is constantly changing, the source code see here

Continue to insert 1G data into the Redis that starts at the beginning of the article, and you can see that CPU time is increasing:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.