Strace diagnosing CPU run-up problems (java/php website)

Source: Internet
Author: User
Tags php website

Early in the year, if you know there is a strace command, it is very cow, and now everyone basically know strace, if you encounter performance problems to help others, ten to one will suggest you use strace hang up to see, but when you hang up, look at the full screen tumbling characters, but nine out of ten can not see why. In a simple case, this article shows you some of the routines used to diagnose problems with strace.

The following real case, if there is a similar, it is inevitable! Let's look at the top result of a high-load server:

650) this.width=650; "class=" Size-full wp-image-475 "src=" Http://huoding.com/wp-content/uploads/2015/10/top.jpg " alt= "Top" width= "height=" 1176 "style=" border:1px solid rgb (238,238,238); height:auto;width:auto;margin:-2px 0px 0px-2px;padding:6px; "/>

Top

Tip: When running top, press "1" to open the CPU list and press "shift+p" to sort the CPU.

In this example, it is easy to find that the CPU is mainly occupied by a number of PHP processes, while the PHP process occupies more memory, but the system memory is still the balance, SWAP is not serious, this is not the main cause of the problem.

However, in the CPU list can see the CPU mainly consumed in the kernel state "sy", rather than the user state "us", and our experience does not match. Linux operating system has a lot of tools to track program behavior, kernel-state function call tracking with "strace", the user-state function call tracking with "ltrace", so here we should use "strace":

Shell> strace-p <PID>

But if you follow a process directly with strace, then waiting for you is often full screen tumbling characters, want to see from here the crux of the problem is not an easy thing, fortunately Strace can be summarized by operation time:

Shell> STRACE-CP <PID>

The "c" option is used to summarize the total time spent on each operation, and the result is probably as follows:

650) this.width=650; "class=" Size-full wp-image-476 "src=" http://huoding.com/wp-content/uploads/2015/10/ Strace1.jpg "alt=" STRACE-CP <PID> "width=" "height=" "style=" border:1px solid rgb (238,238,238); height: auto;width:auto;margin:-2px 0px 0px-2px;padding:6px; "/>

Strace-cp

Obviously, we can see that the CPU is consumed primarily by the clone operation, and can be traced to clone individually:

Shell> strace-t-E clone-p <PID>

The "t" option allows you to get the time the operation actually consumes, and with the "e" option you can track an action:

650) this.width=650; "class=" Size-full wp-image-477 "src=" http://huoding.com/wp-content/uploads/2015/10/ Strace2.jpg "alt=" Strace-t-e clone-p <PID> "width=" "height=" 410 "style=" border:1px solid rgb (238,238,238); h eight:auto;width:auto;margin:-2px 0px 0px-2px;padding:6px; "/>

Strace-t-E Clone-p

Obviously, a clone operation takes hundreds of milliseconds, as for the meaning of clone, refer to the man document:

Clone () Creates a new process, in a manner similar to fork (2). It is actually a library function layered on top of the underlying clone () system call, hereinafter referred to as Sys_clo Ne. A description of Sys_clone is given towards the end of this page.

Unlike fork (2), these calls allow the child process to share parts of it execution context with the calling process, such As the memory space, the table of file descriptors, and the table of signal handlers. (Note that on the This manual page, "calling process" normally corresponds to "parent process".) But see the description of clone_parent below.)

Simply put, a new process is created. So when does this kind of system call happen in PHP? The query business code sees the EXEC function and verifies that it does result in a clone system call with the following command:

shell> strace-eclone php-r ' exec ("ls"); '

Finally, we have a question: if we use Strace to track a process, the output is very small, is not that the process is very idle? Actually try Ltrace, you may find Shia. Remember that there are kernel states and user-State points.


This article is from the "Little Rookie" blog, please be sure to keep this source http://baishuchao.blog.51cto.com/12918589/1929783

Strace diagnosing CPU run-up problems (java/php website)

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.