Lao Li share: "Java performance" note of the performance analysis basis 1

Source: Internet
Author: User

1. Two methods of performance analysis:

(1). Top-down:

Application developers look for opportunities to optimize performance from top to bottom through applications that focus on software stack tops.

(2). Bottom-up:

Performance experts start with CPU statistics at the bottom of the software stack, such as CPU cache misses, CPU instruction efficiency, and gradually rise to the application's own structure or application common usage.

2.CPU Usage Rate:

The CPU usage of most operating systems is divided into user-state CPU usage and system-state CPU utilization.

User-State CPU Usage: The percentage of total CPU time that the application code is executing.

System-State CPU utilization: The percentage of the total CPU time that the application performed the operating system call.

System-State CPU usage means that there is competition for shared resources or there is a lot of interaction between I/O devices. Since CPU cycles originally used to perform operating system calls can also be used to execute application code, ideally, when the application achieves the highest performance and scalability, its system-state CPU usage is 0%, so one goal of delivering application performance and scalability is to minimize system-state CPU usage.

For compute-intensive applications, you need to monitor not only the user and System state CPU usage, but also the indicators per clock instruction (instructions per clock, IPC) or per instruction clock cycle (Cycles per instruction, CPI), A common strategy for increasing compute-intensive applications is to reduce stagnation (the CPU usage monitoring tool that comes with the modern operating system can only report CPU usage and cannot report the percentage of CPU clock cycles that CPU execution instructions consume, so even if the CPU is waiting for data in memory, the operating system tools will still report CPU busy, This is often referred to as stagnation, or improves CPU cache usage, which reduces the clock cycles that the CPU wastes while waiting for memory data.

(1). Windows CPU Usage Monitoring:

The most commonly used CPU usage monitoring tools for Windows are Task Manager and Performance Monitor, which are not covered by the two graphical tools, with a focus on the command line tool typeperf.

The command line that monitors the system state and user-state CPU usage at the command line is as follows:

Typeperf "\processor (_total) \% Privileged Time" "\processor (_total) \% User Time"

You can also write a list of performance counters to a file, and then pass the file name to Typeperf for use, such as writing system State and user-state CPU Usage performance counters to the following Cpu-util.txt file:

\processor (_total) \% Privileged Time

\processor (_total) \% User time

Then use the Typeperf call, as follows:

TYPEPERF-CF Cpu-util.txt

The following command uses TYPEPERF to count user-state CPU usage, System-state CPU usage, and total CPU usage:

Typeperf "\processor (_total) \% User Time" "\processor (_total) \% Privileged Time" "\processor (_total) \% Processor Time"

(2). Linux CPU Usage Monitoring:

Linux can be used with the graphical tools Gnome System Monitor (gnome-system-monitor command boot) or Xosview to monitor CPU usage, which focuses on command-line tools.

A. Vmstat:

The Vmstat can set the reporting interval (in seconds) and, if you do not specify a reporting interval, outputs the total CPU usage since the last boot of the system. The vmstat output of us is the user-state CPU usage, SY is the system-state CPU usage, the ID is the idle rate or the CPU availability rate.

B. Mpstat:

Mpstat can monitor the CPU usage of each virtual processor, helping to find out whether some threads consume more CPU cycles than other threads, or whether all of the threads in the application are evenly split between CPU cycles, and if the latter indicates a better extensibility of the application, Note that most Linux requires the Sysstat package to be installed to use Mpstat.

The mpstat output usr is the percentage of CPU time spent executing user code, the SYS is the percentage of CPU time spent executing kernel code, and WT is the percentage of wait time (no longer counted, always 0), and IDL is the percentage of CPU idle time.

C. Top:

The Linux top command includes not only CPU usage, but also process statistics and memory utilization

3.CPU Scheduler Run Queue:

The CPU scheduler runs in a queue of lightweight processes that are ready to run, waiting for the available CPUs, and if the number of lightweight processes that are ready to run exceeds the limit that the system can handle, the run queue is long and the running queue length indicates that the system load may be saturated.

When the system runs at a queue length equal to the number of virtual processors, the user does not noticeably experience performance degradation and the system responds very slowly when the queue length reaches 4 times or more of the virtual processor.

The general principle of the CPU scheduler running Queue performance Tuning: If, for a long time, the running queue is consistently longer than 1 time times the number of virtual processors, you need to focus on it, but you don't need to take immediate action. If, for a long period of time, the running queue is up to a few or more times the number of virtual processors, you need to take immediate action.

The following two methods are used to resolve the CPU calling program running queue too long:

A. Increasing the CPU to share load or reduce the load on the processor radically reduces the number of active threads on each virtual processor, thereby reducing the number of lightweight processes in the running queue.

B. Analyze the applications running in the system to improve CPU utilization. Programmers can achieve better performance through more efficient algorithms and data structures, and performance experts improve performance by reducing the length of the code path or by completing algorithms that do the same task with less CPU instruction.

(1). The Windows CPU Scheduler runs queue monitoring:

The Typeperf can monitor the running queue Length and monitor the command as follows:

Typeperf "\system\processor Queue Length"

The following is a command that typeperf every 5 seconds (by default, every 1 seconds) to monitor the output run queue Length:

Typeperf-si 5 "\system\processor Queue Length"

(2). Linux CPU Scheduler runs queue monitoring:

Linux can use the Vmstat command to monitor the run queue length, the first column of the Vmstat output is the run queue length, and the value is the actual number of lightweight processes in the running queue.

Lao Li share: "Java performance" note of the performance analysis basis 1

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.