当前位置:网站首页>Operation and maintenance boss ridicules me, you don't know this?

Operation and maintenance boss ridicules me, you don't know this?

2021-05-04 14:49:07 I'm amu

Hello everyone , I'm amu , A happy pirate .

Today I'd like to introduce info Command view redis The specific details are explained !

The cause is : A few years ago, I had an internship interview in my hometown Zhengzhou ( I didn't graduate at that time ) When I meet the interviewer to ask questions ; The interviewer is an engineer from Baidu headquarters 6 year java Development experience +3 Years of PHP Development experience , In front of him, I am basically the younger of my younger brothers , Even though I barely got through , But he was ridiculed mercilessly , Just because the team leader asked me to watch it on the computer redis The basic situation of , I won't , I asked about operation and maintenance . In a fit of rage , I made up for it that night ......, I still remember

however , Speak true , At that time, I didn't go to see it in detail redis Parameter information of ; You're in Redis Have a good look at the parameter configuration on the official website ?

ha-ha ~~~, You don't have to be so modest . It's estimated that just graduated or in the internship , Even the developers who graduated for a year or two didn't have a good look at it ( I'm one of them , At that time, I only knew how to use the foundation ). Suddenly feel Knowing how to use and knowing are two things ;

Often can hear other colleagues or network message , Will use it , Why do you know so much .ctrl+c and ctrl+v This is the highest level of programmer coding . Is that what everyone thinks ?

There is a saying called : Know how it works , You can change everything 「 I was just kidding , Don't take it seriously 」. So today we're going through info Clear understanding of instructions Redis A series of internal operating parameters .

redis Parameter module partition

01) Explain the module

As you can see clearly from the picture above, we will redis The parameters of are divided into 9 Large module , Each module means :

  • Server module: Mainly refers to redis The server Environmental parameters ; for example : System version number 、 Server version number and so on .
  • Clients module: Mainly refers to Client related information ; for example : Number of client connections 、 Blocking wait number 、buffer The value, etc. .
  • Memory module: Mainly refers to the server Memory consumption information ; for example : Occupied memory size 、redis Peak data .
  • Persistence module: Mainly refers to redis Of Persistence Information ; for example : The last time rdb Is persistence successful 、 Whether the server is loading persistent files, etc .
  • Stats module: Mainly refers to It's used to count general data ; for example :1/s Concurrency number 、1/min Data volume 、 Number of hits, etc .
  • Replication module: Mainly refers to Master slave synchronization information explain ; The number of successful synchronizations 、 The number of synchronization failures and so on .
  • Cpu module: Mainly refers to cpu Statistics ; for example : Nuclear mentality / The user mode is occupied by CPU And so on .
  • Cluster module: Mainly refers to Cluster related information ; for example : Whether to enable cluster mode and so on .
  • KeySpace module: Mainly refers to Key value pair statistics quantity information . for example : The number of successful key lookups 、 The number of times the search key failed, and so on .

02) Why understand ?

If you are already a God , Then you don't have to understand . But for just entering the workplace or working for a year 、 Two years 、 Even three years of development does not necessarily know the relevant knowledge .

Now most companies have configured professional operation and maintenance 、DBA, Environment building 、redis colony 、 The master-slave architecture is all done by them , Don't we need to learn to develop ?

I've been interviewed and many developers have answered like this :“ The company has a professional operation and maintenance team , A lot of us can't participate in , So there is no place for actual combat . Can only engage in business requirements development ”. It's obvious that our technology iteration will not go up , A development is not just about business requirements 、 What is more important is to understand the accumulation of knowledge :mysql Lord 、 Master-slave ;redis Multi master and multi slave deployment ;docker、k8s wait , Even if it wasn't deployed by us , But we also need to know what's going on , What is the structure of the company , How to achieve , It's a process specification ?

That's why we need to understand this , Although it seems to be a very basic and simple article . It's estimated that many people will be spraying , But the target group of amu needs to be consolidated and strengthened redis A scholar of knowledge .

03) Inside information

*  ~ redis-cli -h localhost
localhost:6379> info

# Server
redis_version:5.0.9                -- Redis  Server version 
redis_git_sha1:00000000            -- Git SHA1
redis_git_dirty:0                  -- Git Dirty flag 
redis_build_id:544ec503bcbee8b6    --  Internal version number 
redis_mode:standalone              --  Operation mode   Stand alone or cluster 
os:Darwin 17.7.0 x86_64            --  The host operating system of the server 
arch_bits:64                       --  Architecture (32 Bits or 64 position )
multiplexing_api:kqueue            -- Redis The event loop mechanism used 
atomicvar_api:atomic-builtin       --  Atomic processing api
gcc_version:4.2.1                  --  Used to compile Redis Server's GCC Compiler version number 
process_id:411                     --  Server process PID
run_id:e8bf4443cdd6696036e07c4a65d64e6916a6a79e  -- Redis  Random identifier of the server ( be used for  Sentinel  And clusters )
tcp_port:6379                      -- TCP/IP  Listening port 
uptime_in_seconds:29924            -- redis server Start time ( Unit second )
uptime_in_days:0                   -- redis server Start time ( Unit day )
hz:10                              -- redis Internal scheduling ( Shut down timeout The client of , Delete expired key wait ) frequency , The procedure says serverCron Run... Every second 10 Time 
configured_hz:10                   --  Configured frequency settings for the server 
lru_clock:9421068                  --  Self increasing clock , be used for LRU tube ; The clock 100ms(hz=10, So every 1000ms/10=100ms Perform a scheduled task ) Updated once 
executable:/usr/local/opt/redis/bin/redis-server  --  The path to the server executable 
config_file:/usr/local/etc/redis.conf             -- redis The path to the configuration file 

# Clients
connected_clients:1                --  Number of clients connected ( Does not include clients connected through a secondary server )
client_recent_max_input_buffer:2   --  Current client's latest maximum input cache size 
client_recent_max_output_buffer:0  --  The maximum output cache size of the current client 
blocked_clients:0                  --  Waiting for blocking command (BLPOP、BRPOP、BRPOPLPUSH) Number of clients 

# Memory
used_memory:148180600              -- Redis Total memory allocated by allocator , In bytes (byte) In units of 
used_memory_human:1015.52K         --  Return... In a human readable format Redis The total amount of memory allocated , It means that we normal people can understand it , With units 
used_memory_rss:3293184            --  From an operating system perspective , return  Redis  Total allocated memory ( Commonly known as resident set size ). The value and top、ps Wait for the output of the command to be consistent 
used_memory_rss_human:3.14M        --  In a human readable format , return  Redis  Total allocated memory ( Commonly known as resident set size ); The value and top、ps Wait for the output of the command to be consistent 
used_memory_peak:1040976           -- redis Peak memory consumption ( In bytes ), That is, the amount of memory occupied at the peak 
used_memory_peak_human:1016.58K    --  Return... In a human readable format redis Peak memory consumption 
used_memory_peak_perc:99.90%       -- (used_memory/used_memory_peak) *100%, Peak memory usage 
used_memory_overhead:1037198       -- redis The memory overhead required to maintain the internal mechanism of the dataset , Include all client output buffers 、 Query buffer 、AOF Rewrite buffer and master-slave copy backlog
used_memory_startup:987504         -- Redis Initial amount of memory consumed at startup ( In bytes )
used_memory_dataset:2690           --  The byte size of the data set used_memory—used_memory_overhead
used_memory_dataset_perc:5.14%     --  Percentage of net memory usage (used_memory_dataset/(used_memory—used_memory_startup))*100%
total_system_memory:8589934592     --  The whole system memory 
total_system_memory_human:16.00G   --  Normal people can understand the format display    System memory size   With units 
used_memory_lua:37888              -- Lua Memory occupied by script storage 
used_memory_lua_human:37.00K       --  Normal people can understand the format display Lua Memory occupied by script storage   With units 
used_memory_scripts:0              --  The cache Lua The number of bytes used by the script 
used_memory_scripts_human:0B       --  Normal people can understand the format display    The cache Lua The number of bytes used by the script   With units 
maxmemory:0                        -- Redis The maximum memory configuration of the instance   Number of bytes 
maxmemory_human:0B                 --  Normal people can understand the format display   Maximum memory configuration   With units 
maxmemory_policy:noeviction        --  When reach maxmemory When the elimination strategy 
allocator_frag_ratio:3.24
allocator_frag_bytes:2249712
allocator_rss_ratio:1.00
allocator_rss_bytes:0
rss_overhead_ratio:1.01
rss_overhead_bytes:37888
mem_fragmentation_ratio:3.27
mem_fragmentation_bytes:2287600
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:49694
mem_aof_buffer:0
mem_allocator:libc                --  Memory allocator 
active_defrag_running:0           --  Indicates that there is no activity defrag The task is running ,1 It means active defrag The task is running (defrag: Memory defragmentation )
lazyfree_pending_objects:0        -- 0 Indicates that there is no delayed release ( There are also materials that have not been deleted ) Pending objects for 

# Persistence
loading:0                         --  Whether the server is loading persistent files 
rdb_changes_since_last_save:5     --  Last successful build rdb file , Number of write commands , That is, how many write commands are not persistent 
rdb_bgsave_in_progress:0          --  Is the server creating rdb file 
rdb_last_save_time:1620033801     --  Last saved successfully RDB Era based timestamps for   second 
rdb_last_bgsave_status:ok         --  The last time rdb Is persistence successful 
rdb_last_bgsave_time_sec:-1       --  The last successful generation rdb Files take time ( In seconds )
rdb_current_bgsave_time_sec:-1    --  Ongoing RDB The duration of the save operation ( In seconds )
rdb_last_cow_size:0               --  Last time RDB Copy memory size on write during save operation ( In bytes )
aof_enabled:0                     --  Whether it is turned on aof
aof_rewrite_in_progress:0         --  identification aof Of rewrite Is the operation in progress 
aof_rewrite_scheduled:0           --  If rdb After saving, execute rewrite
aof_last_rewrite_time_sec:-1      --  The last time aof rewrite It takes a long time ( In seconds )
aof_current_rewrite_time_sec:-1   --  If rewrite The operation is in progress , Then record the time used ( In seconds )
aof_last_bgrewrite_status:ok      --  The last time bgrewriteaof State of operation 
aof_last_write_status:ok          --  The last time aof Write status 
aof_last_cow_size:0               --  The last time aof Copy the size of memory when rewriting ( In bytes )

# Stats
total_connections_received:1      --  Total number of connections accepted by server ( Excessive connection creation and destruction has a performance impact )
total_commands_processed:3        -- redis The total number of commands processed 
instantaneous_ops_per_sec:0       -- redis The number of commands processed per second , Namely qps
total_net_input_bytes:63          -- redis Total bytes of network read traffic 
total_net_output_bytes:14765      -- redis The total number of bytes of network write traffic 
instantaneous_input_kbps:0.00     -- redis Internet portal kps, With KB/ Seconds per unit 
instantaneous_output_kbps:0.00    -- redis Internet outlet kps, With KB/ Seconds per unit 
rejected_connections:0            -- redis The number of connections reaches maxclients Limit , Number of new connections rejected 
sync_full:0                       --  Master slave full synchronization success times 
sync_partial_ok:0                 --  Master slave partial synchronization success times 
sync_partial_err:0                --  The number of master-slave partial synchronization failures 
expired_keys:0                    -- redis Expired since run key The number of 
expired_stale_perc:0.00           -- key The overdue rate 
expired_time_cap_reached_count:0  -- key Number of times expired 
evicted_keys:0                    -- redis Since running ( More than the maxmemory after ) Of key The number of 
keyspace_hits:0                   --  The number of successful key lookups , That's the number of hits 
keyspace_misses:0                 --  Number of failed find keys , That's the number of misses 
pubsub_channels:0                 -- redis Number of channels currently in use 
pubsub_patterns:0                 --  The number of patterns currently in use 
latest_fork_usec:0                --  The last time fork Operation blocking redis The amount of time the process takes , Unit microseconds 
migrate_cached_sockets:0          --  Whether the connection to the address has been cached 
slave_expires_tracked_keys:0      -- redis From instance expiration key Number 
active_defrag_hits:0              -- redis Proactive defragmentation hits 
active_defrag_misses:0            -- redis Proactive defragmentation Miss count 
active_defrag_key_hits:0          -- redis Active defragmentation key Number of hits 
active_defrag_key_misses:0        -- redis Active defragmentation key Number of misses 

# Replication
role:master                       -- redis The role of the instance , yes master or slave
connected_slaves:0                --  Connected from slave The number of instances 
master_replid:1e913ad6101de7d40fcea32378f515e62a55c9db   -- master Instance starts random string 
master_replid2:0000000000000000000000000000000000000000  -- master Instance starts random string 2, Auxiliary function , For post fail over synchronization 
master_repl_offset:0              -- redis The current master-slave offset of 
second_repl_offset:-1             -- redis The current master-slave offset of 2
repl_backlog_active:0             --  Whether the copy backlog buffer is on 
repl_backlog_size:1048576         --  Copy backlog buffer size  
repl_backlog_first_byte_offset:0  --  The size of the offset in the copy buffer 
repl_backlog_histlen:0            --  Copy the size of the data in the backlog buffer ( In bytes ), The value is equal to master_repl_offset-repl_backlog_first_byte_offset

# CPU
used_cpu_sys:3.629912             -- Redis The system consumed by the server CPU, This is all threads of the server process ( The main thread and the background thread ) Consuming systems CPU The sum of  
used_cpu_user:2.675796            -- Redis Users consumed by the server CPU, This is all threads of the server process ( The main thread and the background thread ) Consuming users CPU The sum of 
used_cpu_sys_children:0.000000    --  The system consumed by the background process CPU The cumulative sum  
used_cpu_user_children:0.000000   --  Users consumed by the background process CPU The cumulative sum 

# Cluster
cluster_enabled:0                 --  Whether the instance enables cluster mode 

# Keyspace
db0:keys = 749916                -- db0 Of key The number of 
expires = 8                      --  With a lifetime key Number of numbers 
avg_ttl = 138855028143523        --  Average survival time 
 Copy code 

I'm really tired after finishing here , Too many parameters , The above is to sort out some basic parameters . But when you really sort out the data , You'll find that , You thought you knew a lot ; But there's more you don't know .

04) Parameters that need to be focused on

see redis Memory footprint :

reason : Although basically large companies have Kanban to see directly redis Cluster usage , But sometimes it may be necessary for us to develop and check the computer to see if it is really abnormal .

*  ~ redis-cli -h localhost info memory | grep -E 'used|human'
used_memory:1038896
used_memory_human:1014.55K
used_memory_rss:1490944
used_memory_rss_human:1.42M
used_memory_peak:1040976
used_memory_peak_human:1016.58K
used_memory_peak_perc:99.80%
used_memory_lua:37888
used_memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human:0B
 Copy code 

You can see clearly above , At present redi The total amount of memory allocated from the operating system and the memory usage ( Because there are many outputs , I delete some of the data that I need to show ).

1、used_memory:redis Total memory allocated by allocator ( Unit byte ), It also contains virtual memory swap.

2、used_memory_rss:redis The amount of operating system memory occupied by a process ( Unit byte ); Including the running memory of the process itself 、 Memory fragments .

Difference between them :used_memory The object of acquisition is redis;used_memory_rss The object of acquisition is operating system ; It can be seen from the above results that the former is obviously smaller than the latter , Because redis The operation itself takes up memory and there are memory fragments , So it looks like the former is much smaller than the latter . But it doesn't mean that the former is necessarily smaller than the latter , It is possible that the former will have more virtual memory than the latter .

Check the number of client connections :

Let's enumerate and list the configuration parameters of the client first :

*  ~ redis-cli -h localhost info clients
# Clients
connected_clients:1
client_recent_max_input_buffer:4
client_recent_max_output_buffer:0
blocked_clients:0
 Copy code 

Check the maximum number of client connections on this machine :

localhost:6379> config get maxclients
1) "maxclients"
2) "10000"
 Copy code 

Why compare the top with the bottom , Because the number of client connections is affected by maxclients The limitation of , These two parameters are very important to us . We may encounter when we write code redis Service not available , So first of all, make sure it's redis Hang up .

telnet 127.0.0.1( on-line redis Of ip Address ) 80( port )
 Copy code 

Through the number of links to see the abnormal state , We can go through client list Command to view client connections :

localhost:6379> client list
id=10 addr=127.0.0.1:56336 fd=8 name= age=780 idle=1 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=32742 obl=0 oll=0 omem=0 events=r cmd=client

 The meaning of the result set returned by the popular science command :
 Here's what domain means :

id    :  Serial number 
addr  :  The address and port of the client 
fd    :  The file descriptor used by the socket 
name  :  Connection name 
age   :  Connected time in seconds 
idle  :  Idle time in seconds 
flags :  client  flag
db    :  The database that the client is using ID
sub   :  Number of subscribed channels 
psub  :  Number of subscribed patterns 
multi :  Number of commands executed in a transaction 
qbuf  :  Length of query buffer ( Bytes are units , 0  Indicates that there is no query buffer allocated )
qbuf-free :  The length of the remaining space in the query buffer ( Bytes are units , 0  Means there is no room left )
obl   :  Length of output buffer ( Bytes are units , 0  Indicates no output buffer allocated )
oll   :  The output list contains the number of objects ( When there is no space left in the output buffer , Command replies are queued as string objects )
omem   :  The total amount of memory used by the output buffer and output list 
events :  File descriptor Events 
cmd    :  The last command executed 
 Copy code 

So is it very clear that we can find the potential connection source , We can also query the number of rejected client connections , To ensure that services need to be reconfigured :

*  ~ redis-cli -h localhost info stats | grep reject
rejected_connections:0   --  The number of connections rejected by the client 
 Copy code 

If this value comes up to our ideal expectation , We need to adjust our maximum number of connections :

①  adopt redis The maximum number of connections for profile modification :

vim /usr/local/etc/redis.conf 
maxclients = 150000

② redis Specify the maximum number of connections when the service starts :
redis-server --maxclients 150000
 Copy code 

Of course, there are also queries cpu Information 、 Cluster information 、 Parameters of master-slave copy related information , So I'm going to slowly put these in the next chapter, and I'm going to , With the actual practice of the project step by step .

At present, we only need to know some parameters that we often pay attention to ; Seriously , I'm not sure how much I can remember now , It's also a common data index. Be familiar with it .

The final summary

You can see the little guys here , Your eyesight is really awesome , Too many parameters need to be read and remembered , It's really not easy ! Please give yourself a thumbs up , Thief's stick .

Although the article is relatively short , Maybe the experts will scold when they see it “ The garbage , It's about something ”; I'm still saying that , We target different groups of people . And these aren't just random articles , It's an interview with a big company 、 The leader's inquiry will be written in combination with his own actual situation .

I don't know if my friends are right after reading this article redis info Is there any further understanding of the internal parameters of ? If a Mu's article feels helpful or inadequate , Please leave a message below the comments .

Last , Welcome to follow my personal public number 「 I'm amu 」, Will update the back-end knowledge points and learning notes from time to time . I also welcome direct official account or personal mail or email to contact me , We can learn together , Progress together .

Okay , I'm amu , One doesn't want to 30 Migrant workers who were eliminated at the age of 20 ️ ️ ️ . Thank you for your : Collection 、 give the thumbs-up 、 Share and leave messages , See you next time .

版权声明
本文为[I'm amu]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/05/20210504144301058J.html

随机推荐