PHP slow script log and MySQL slow query log (GO)

Source: Internet
Author: User
Tags fpm mysql slow query log

 1. php Slow Script Log
    • Intermittent 502, is caused by the backend php-fpm is not available, the intermittent 5,021-like is due to the PHP-FPM process restart.
    • An intermittent 502 error occurs when the number of PHP-FPM in a configuration exceeds the number of child processes, and if max_requests is set in the configuration, there will be a 502 error over the number, and max_requests settings It is to prevent unsafe third-party library script memory leaks , of course, you write your own script has a deadlock , there will also be 502 phenomenon.

    • If you find that MySQL load is not high, but the number of php-fpm processes and memory consumption is too high, congratulations, most of the situation is because the script has a deadlock.

2. Now that you have found the problem with PHP, how do you locate the PHP script?

To open the PHP slow query log:

  1. $ sudo vi /usr/loal/php/etc/php-fpm.conf
  2. ; Default Value: 0
  3. request_slowlog_timeout = 1s
  4. ; The log file for slow requests
  5. ; Default Value: /usr/local/php/log/php-fpm.log.slow
  6. slowlog = /usr/local/php/log/php-fpm.log.slow

The default request_slowlog_timeout is 0,php the slow script log is off, so set to n greater than 0, which means that scripts that execute more than n are logged into the slowlog.
Then monitor the site when there is a problem when viewing the next Slowlog can find slow script, the script to check processing.

3.2, MySQL slow query log

The MySQL slow query log is useful for tracking problematic queries and can analyze the resource-intensive SQL statements in the current program, so how do I turn on slow query logging for MySQL?

In fact, the slow query log to open MySQL is very simple, only need to in the MySQL configuration file (Windows system is My.ini,linux system is my.cnf) of the [mysqld] under the following code:

    1. log-slow-queries=/var/lib/mysql/slowquery.log
    2. long_query_time=2

The 2 in long_query_time=2 indicates that the query is not logged for more than two seconds.
If the log content is many, with the eye one by one to see will be exhausted, MySQL comes with the tool of analysis, using the following methods:

  1. $ cd /usr/local/mysql/bin
  2. $ mysqldumpslow –help
  3. -s,是order的顺序,主要有c,t,l,r和ac,at,al,ar,分别是按照query次数,时间,lock的时间和返回的记录数来排序,前面加了a的时倒叙
  4. -t,是top n的意思,即为返回前面多少条的数据
  5. -g,后边可以写一个正则匹配模式,大小写不敏感的
  6. $ mysqldumpslow -s c -t 20 host-slow.log #访问次数最多的20个sql语句
  7. $ mysqldumpslow -s r -t 20 host-slow.log #返回记录集最多的20个sql
  8. $ mysqldumpslow -t 10 -s t -g “left join” host-slow.log #按照时间返回前10条里面含有左连接的sql语句

MySQL Slow query log query manual

PHP slow script log and MySQL slow query log (GO)

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.