CPU/Memory Analysis

1. Conceptual understanding

The principle of program operation: a request is sent to the server, first passes through the network card, and then notifies the cpu that there is a task to be processed, the CPU runs the operating system command, finds the corresponding application code according to the port number of the request, and arranges the thread to process; because the program code is in The execution speed in the disk is too slow, and a memory space will be opened up to process the task - that is, the network buffer

 CPU  : Execute code instructions and process data

Process : A unit that manages program execution at the operating system level

  • Apply for a memory area
  • Apply for binding port
  • load code command

Thread : A thread is an execution flow of a process and the basic unit of CPU scheduling and dispatching. It is a basic unit that is smaller than a process and can run independently.

  • Multiple threads in the same process, shared memory usage
  • share a port
  • It can be used as an operating system level to call resources separately (the operating system will assign instructions and data to the CPU for processing and execution in units of threads)

Process - the smallest unit of resource allocation, thread - the smallest unit of program execution

Popular analogy: the network card is equivalent to the entrance/exit of the train station; the CPU is equivalent to the train track, and the number of cores of the CPU is equivalent to multiple tracks; the operating system is the dispatching room of the train station, responsible for scheduling resources; the port number is It is equivalent to the train number; the process is a train, which is responsible for running. It needs to occupy CPU track resources when running, and does not occupy resources if it is not running; the thread is the carriage of the train, carrying different people.

Two, cpu and memory monitoring

1. Use the top command to view real-time resource usage

The first line of system operation information: current time, how long the system has been running, how many logged-in users, load information - 1 minute/5 minutes/15 minutes (using a specific algorithm, the number of CPU cores * 3~5 is an ultra-high load)

The second line of task information: how many processes in total, running, dormant, stopped, and suspended

The third line of CPU information:

  • 21.6 us: Indicates that the CPU usage ratio in user mode is 21.6%
  • 8.3 sy: indicates that the CPU usage ratio in system mode is 8.3%,
  • 0.0 ni: indicates that the CPU usage ratio of the process whose priority has been changed is 0.0%
  • 69.9 id: Indicates that the CPU usage in the idle state is 99.8%
  • 0.0 wa: indicates that the CPU usage due to I/O waiting is 0.0%
  • 0.0 hi: Indicates the CPU usage ratio of hard interrupts
  • 0.0 si: Indicates the CPU occupancy ratio of soft interrupts.
  • 0.0 st: Indicates the percentage of time the CPU waits for the virtual machine to be scheduled. This indicator is generally only available in the virtual machine, and the value is generally maintained at 0 in the physical machine.

Memory usage information on the fourth line:

  • total represents the total amount of physical memory
  • free indicates the free size of physical memory
  • used indicates the size of the physical memory used
  • buff/cache indicates the size of physical memory used for caching

The fifth line of virtual memory/swap memory: the essence is to open up a space on the hard disk as memory for use

2. Use the free command to view memory usage

Parameter meaning:

  • total: total available memory, unit K
  • used: used memory, java heap memory
  • free: free memory
  • shared: shared area, multiple processes share a piece of memory, java heap memory
  • buffer/cache: buffer/cache memory, when the memory is not enough, this area will be released (for example: when writing a file, the memory is enough, write to the buffer, when the memory is not enough, it will quickly fall to the disk)
  • available: available memory size
  • Virtual memory: When the physical memory is not enough, the operating system designers thought of a way. Most of the program processes are not running, and the operating system temporarily stores part of the data in the memory to the disk.

3. Grafana platform monitoring (environment construction check grafana+prometheus+node_exporter server performance monitoring construction_shines_m's blog-CSDN blog )

3. Analysis of performance test results

If the throughput reaches the bottleneck, but the CPU resource usage is not high, it may be a problem with the design of the performance test scenario: insufficient pressure--gradually increase the number of concurrency tests

  • The amount of concurrency has increased, but the resources have not increased accordingly. There may be problems with the program or other configurations
  • If the CPU usage does not increase, you need to consider the program code or operating system configuration issues, such as the multi-threading mechanism of the Jvm program

Guess you like

Origin blog.csdn.net/qq_38571773/article/details/128233859