background

There was an online server alarm today, MEM_USED_PERCENT=90.58, memory usage is 90.58. Seeing this alarm, most of the ancestors would go to the server and type the top command to see how the server was doing. How to use the top command to analyze system performance.

Using the top command, you can get a comprehensive view of the current server status, including the current CPU, memory, and process.

First of all, we directly on the Linux server input top, press enter can dynamically see the current server running status, the default is every 3S refresh, here I cut a picture for you to analyze, don’t look at a lot of data, listen to my analysis you will fully understand.

Look at the top command line by line

First line: Overview of the system

Name System running 276 days 3 hours 40 minutes System load: 1 minute /5 minutes /15 minutes Top-19:09:08 up 276 days,3:40, 1 user, load Average: 0.00, 0.02, 0.05 Current System Time Number of Current Login Users 1 Single-core CPU 1.0 indicates the full loadCopy the code

Line 2: Process status

Total number of Tasks: 367 Running processes 1 366 Currently sleeping stopped processes 0 Zombie processes 0 Tasks: 367 Total, 1 running, 366 sleeping, 0 Stopped, 0 zombie processesCopy the code

Line 3: CPU state

Cpu usage: User space Kernel space User-defined Priority Idle WAIT I/O Hard Interrupt Soft Interrupt VM %Cpu(s): 0.7 US, 0.5 SY, 0.0 Ni, 98.7 ID, 0.2 WA, 0.0 Hi, 0.0 Si, 0.0 STCopy the code

Line 3-4: Memory and Swap Swap status

Unit Physical memory Free Used kernel cache KiB Mem: 5944564 Total, 158904 Free, 3020092 Used, 2765568 Buff/Cache Swap total free used memory KiB Swap: 0 total, 0 free, 0 used. 2192080 avail MemCopy the code

There’s one last thing you need to know about the process state

Process ID Priority Nice Virtual Memory Physical Memory Shared Memory CPU Memory TOTAL CPU TIME COMMAND PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1090 root 20-10 50088 920 584 S 1.3 0.0 4190:25 rshim 11285 root 20 20 1088692 146912 12332 S 1.0 2.5 602:17.59 YDService......Copy the code

A negative value of NI indicates high priority and a positive value indicates low priority.

The top command provides quick operations

Now that you’re done analyzing top content, let’s learn some cool shortcuts.

● SHIFT + E Switch memory display mode (returnable key) ● Z switch color display mode (returnable key) ● M Switch memory display mode (returnable key) ● E Switch display mode of units in the bottom process (returnable key) ● B Switch Highlight selected (returnable key) ● W Saves the current configuration to a file. The current configuration will be used when top is started next time. ● h To access the help menu (after entering the menu, press ESC or Q to exit the help menu) ● Q To exit the top commandCopy the code

In addition, you can also sort dynamically displayed content

● Press F to enter the field selection interface, ● Then press up or down to select the field to be sorted, the interface will be highlighted, select the appropriate content ● After confirming the selected operation, press S key to activate the selection. ● Finally, press q to exit the sorting field selection interface.Copy the code

conclusion

After understanding the above specific parameters, combined with specific alarm analysis. Log in to the server and check the deployed services. There are 10 Java services, and the -xmx-XMS of each service is 1344M. The 10 services have used up 10G of machine memory just after running. Finally, our temporary optimization solution was to reduce the memory of some low-traffic service initialization heap by half to relieve the server stress.