繁体   English   中英

网站宕机,无法理解网络服务器进程日志?

[英]Website going down, cannot understand webserver process logs?

任何人都可以帮助解释以下日志:

MariaDB [(none)]> show full processlist;
+--------+----------------+-----------------+---------------------+---------+-----
|      3 | user-rw        | localhost       | bets-stage          | Sleep   |   51 |                      | NULL                                                                                                  |    0.000 |
|     11 | user-rw        | localhost       | bets-stage          | Sleep   |   39 |                      | NULL                                                                                      |    0.000 |
|     13 | db1029865-news | localhost       | db1029865-sportnews | Query   |   30 | Writing to net       | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc                                                                                                                                                                 |    0.000 |
|     17 | db1029865-news | localhost       | db1029865-sportnews | Query   |   20 | Writing to net       | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc                                                                                                                                                                                                                                                                                                                         |    0.000 |
|     34 | db1029865-news | localhost       | db1029865-sportnews | Query   |    3 | Sorting result       | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc   |    0.000 |
|     37 | db1029865-news | localhost       | db1029865-sportnews | Sleep   |   31 |                      | NULL |    0.000 |
|     39 | user-rw        | localhost       | bets-stage          | Sleep   |   77 |                      | NULL                                                                            |    0.000 |
|     40 | db1029865-news | localhost       | db1029865-sportnews | Query   |   16 | Writing to net       | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc                                                                                     |    0.000 |
|     41 | user-rw        | localhost       | bets-stage          | Sleep   |   43 |                      | NULL                                                                                     |    0.000 |
|     49 | db1029865-news | localhost       | db1029865-sportnews | Query   |   24 | Writing to net       | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc                                                                                     |    0.000 |
|     52 | db1029865-news | localhost       | db1029865-sportnews | Sleep   |   36 |                      | NULL                                                                                     |    0.000 |
|     53 | db1029865-news | localhost       | db1029865-sportnews | Query   |   26 | Writing to net       | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc                                                                                     |    0.000 |
|     54 | db1029865-news | localhost       | db1029865-sportnews | Query   |    1 | Copying to tmp table | SELECT `post`.*, `post`.`team1_seourl` AS `team1seourl`, `post`.`team1_seourl` AS `teamseourl`, `post`.`team2_seourl` AS `team2seourl`, IF(`temp_tn1uid`.`value` > 0, `post`.`team1_uid`, NULL) AS `tn1uid`, IF(`temp_tn2uid`.`value` > 0, `post`.`team2_uid`, NULL) AS `tn2uid` FROM (SELECT `post`.*, `post_j`.`title`, `post_j`.`teaser` FROM (SELECT `post`.* FROM `sportnews_cache_post_team` AS `post` FORCE INDEX(`sort_index`) JOIN (SELECT `cache_uid` FROM `sportnews_cache_post_team` AS `post` WHERE (`post`.`team1_uid` = 4894 OR `post`.`team2_uid` = 4894) GROUP BY `post`.`uid` ORDER BY `post`.`cache_uid` LIMIT 40 OFFSET 0) AS `post_j` ON `post`.`cache_uid` = `post_j`.`cache_uid`) AS `post` JOIN `sportnews_post` AS `post_j` ON `post_j`.`uid` = `post`.`uid`) AS `post` LEFT JOIN (SELECT `uid`, COUNT(*) AS `value` FROM `sportnews_cache_post_team` AS `post` FORCE INDEX(`sort_index`) WHERE `post`.`team1_uid` = 4894 GROUP BY `post`.`uid`) AS `temp_tn1uid` ON `temp_tn1uid`.`uid` = `post`.`uid` LEFT JOIN (SELECT `uid`, COUNT(*) AS `value` FROM `sportnews_cache_post_team` AS `post` FORCE INDEX(`sort_index`) WHERE `post`.`team2_uid` = 4894 GROUP BY `post`.`uid`) AS `temp_tn2uid` ON `temp_tn2uid`.`uid` = `post`.`uid` |    0.000 |
|     57 | db1029865-news | localhost       | db1029865-sportnews | Sleep   |   22 |                      | NULL                                                                                     |    0.000 |
|     75 | user-rw        | localhost       | bets-stage          | Sleep   |   32 |                      | NULL                                                                                     |    0.000 |
|     77 | db1029865-news | localhost       | db1029865-sportnews | Sleep   |    6 |                      | NULL                                                                                     |    0.000 |
|     78 | db1029865-news | localhost       | db1029865-sportnews | Sleep   |   15 |                      | NULL                                                                                     |    0.000 |
|     79 | db1029865-news | localhost       | db1029865-sportnews | Sleep   |    3 |                      | NULL                                                                                     |    0.000 |
|     88 | db1029865-news | localhost       | db1029865-sportnews | Query   |   18 | Writing to net       | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc                                                                                     |    0.000 |
|     99 | db1029865-news | localhost       | db1029865-sportnews | Sleep   |   39 |                      | NULL                                                                                     |    0.000 |
|    100 | db1029865-news | localhost       | db1029865-sportnews | Query   |    1 | Sorting result       | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc                                                                                                                                                                   |    0.000 |
|    110 | db1029865-news | localhost       | db1029865-sportnews | Query   |   32 | Writing to net       | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc                                                                                                                                                                   |    0.000 |
|    117 | db1029865-news | localhost       | db1029865-sportnews | Sleep   |    9 |                      | NULL                                                                                                                                                                   |    0.000 |
|    119 | user-rw        | localhost       | bets-stage          | Sleep   |   70 |                      | NULL                                                                                                                                                                   |    0.000 |
|    137 | user-rw        | localhost       | bets-stage          | Sleep   |   34 |                      | NULL                                                                                     |    0.000 |
|    138 | db1029865-news | localhost       | db1029865-sportnews | Query   |   28 | Sending data         | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc                                                                                     |    0.000 |
|    160 | user-rw        | localhost       | bets-stage          | Sleep   |   40 |                      | NULL                                                                                     |    0.000 |
|    162 | user-rw        | localhost       | bets-stage          | Sleep   |   27 |                      | NULL                                                                                     |    0.000 |
|    189 | user-rw        | localhost       | bets-stage          | Sleep   |   19 |                      | NULL       |    0.000 |
|    208 | user-rw        | localhost       | bets-stage          | Sleep   |   56 |                      | NULL       |    0.000 |
|    218 | db1029865-news | localhost       | db1029865-sportnews | Query   |   22 | Writing to net       | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc                                                                                                                                                                   |    0.000 |
|    219 | user-rw        | localhost       | bets-stage          | Sleep   |    3 |                      | NULL                                                                                                                                                                   |    0.000 |
|    274 | user-rw        | localhost       | bets-stage          | Sleep   |   20 |                      | NULL                                                                                                                                                                   |    0.000 |
|    301 | user-rw        | localhost       | bets-stage          | Sleep   |   30 |                      | NULL                                                                                     |    0.000 |
|    302 | user-rw        | localhost       | bets-stage          | Sleep   |    2 |                      | NULL                                                                                                                                                                   |    0.000 |
|    356 | user-rw        | localhost       | bets-stage          | Sleep   |   36 |                      | NULL                                                                                                                                                                   |    0.000 |
|    435 | user-rw        | localhost       | bets-stage          | Sleep   |   55 |                      | NULL       |    0.000 |
|    511 | user-rw        | localhost       | bets-stage          | Sleep   |   59 |                      | NULL                                                                                                                                                                   |    0.000 |
|   2007 | user-rw        | localhost       | bets-stage          | Sleep   |   61 |                      | NULL                                                                                                                                                                   |    0.000 |
| 606299 | db1029865-news | localhost:34857 | db1029865-sportnews | Sleep   |   60 |                      | NULL                                                                                                                                                                   |    0.000 |
| 606300 | db1029865-news | localhost:34860 | db1029865-sportnews | Sleep   |   60 |                      | NULL                                                                                                                                                                   |    0.000 |
| 606438 | db1029865-news | localhost:34940 | db1029865-sportnews | Sleep   |   91 |                      | NULL                                                                                     |    0.000 |
| 606439 | db1029865-news | localhost:34941 | db1029865-sportnews | Sleep   |    3 |                      | NULL                                                                                     |    0.000 |
| 610631 | user-rw        | localhost:35813 | sportnews-stage     | Sleep   |  177 |                      | NULL                                                                                                                                                                   |    0.000 |
| 611528 | db1029865-news | localhost:36298 | db1029865-sportnews | Query   |   10 | Writing to net       | SELECT /*!40001 SQL_NO_CACHE */ * FROM `sportnews_log`                                                                                                                                                                                               |    0.000 |
| 612224 | root           | localhost       | NULL                | Query   |    0 | NULL                 | show full processlist                                                                                                                                                  |    0.000 |
+--------+----------------+-----------------+---------------------+---------+------+----------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
47 rows in set (0.00 sec)
|     13 | db1029865-news       | localhost       | db1029865-sportnews | Query   |   24 | Writing to net   | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|     17 | db1029865-news       | localhost       | db1029865-sportnews | Query   |   21 | Sending data     | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|     34 | db1029865-news       | localhost       | db1029865-sportnews | Query   |   10 | Sorting result   | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|     37 | db1029865-news       | localhost       | db1029865-sportnews | Query   |    6 | Sorting result   | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|     39 | user-rw              | localhost       | bets-stage          | Sleep   |   38 |                  | NULL                                                                                                                                                             |    0.000 |
|     40 | db1029865-news       | localhost       | db1029865-sportnews | Query   |   21 | Sending data     | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|     41 | user-rw              | localhost       | bets-stage          | Sleep   |  139 |                  | NULL                                                                                                                                                             |    0.000 |
|     49 | db1029865-news       | localhost       | db1029865-sportnews | Query   |   25 | Sending data     | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|     52 | db1029865-news       | localhost       | db1029865-sportnews | Query   |    8 | Sorting result   | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|     53 | db1029865-news       | localhost       | db1029865-sportnews | Query   |   20 | Writing to net   | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|     54 | db1029865-news       | localhost       | db1029865-sportnews | Query   |    7 | Sorting result   | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|     57 | db1029865-news       | localhost       | db1029865-sportnews | Sleep   |   48 |                  | NULL                                                                                                                                                             |    0.000 |
|     75 | user-rw              | localhost       | bets-stage          | Sleep   |   33 |                  | NULL                                                                                                                                                             |    0.000 |
|     77 | db1029865-news       | localhost       | db1029865-sportnews | Query   |   28 | Sending data     | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|     78 | db1029865-news       | localhost       | db1029865-sportnews | Sleep   |   29 |                  | NULL                                                                                                                                                             |    0.000 |
|     79 | db1029865-news       | localhost       | db1029865-sportnews | Sleep   |    6 |                  | NULL                                                                                                                                                             |    0.000 |
|     88 | db1029865-news       | localhost       | db1029865-sportnews | Query   |   14 | Sorting result   | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|     99 | db1029865-news       | localhost       | db1029865-sportnews | Query   |   10 | Sorting result   | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|    100 | db1029865-news       | localhost       | db1029865-sportnews | Query   |   13 | Sorting result   | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|    110 | db1029865-news       | localhost       | db1029865-sportnews | Sleep   |    4 |                  | NULL                                                                                                                                                             |    0.000 |
|    117 | db1029865-news       | localhost       | db1029865-sportnews | Query   |   34 | Sending data     | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|    119 | user-rw              | localhost       | bets-stage          | Sleep   |   10 |                  | NULL                                                                                                                                                             |    0.000 |
|    137 | user-rw              | localhost       | bets-stage          | Sleep   |   24 |                  | NULL                                                                                                                                                             |    0.000 |
|    138 | db1029865-news       | localhost       | db1029865-sportnews | Query   |   31 | Sending data     | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc |    0.000 |
|    160 | user-rw              | localhost       | bets-stage          | Sleep   |  260 |                  | NULL                                                                                                                                                             |    0.000 |
|    162 | user-rw              | localhost       | bets-stage          | Sleep   |  136 |                  | NULL                                                                                                                                                             |    0.000 |
|    189 | user-rw              | localhost       | bets-stage          | Sleep   |   14 |                  | NULL                                                                                                                                                             |    0.000 |
|    208 | user-rw              | localhost       | bets-stage          | Sleep   |   10 |                  | NULL                                                                                                                                                             |    0.000 |
|    218 | db1029865-news       | localhost       | db1029865-sportnews | Query   |   24 | Sending data     | SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'

正如很少有用户评论的那样,需要更多信息才能知道确切的问题。

从您提供的processlist输出中可以看到,您的许多查询在“写入网络”状态停留了20-30秒。 这意味着您的选择查询返回了大量数据并花费大量时间将数据包写入网络,或者您的网络速度很慢/受到其他进程的限制,从而使mysql输出速度变慢。

如果任何页面正在使用这些查询,则它们将在20-30秒(相当于网站关闭)中不会出现geeting结果

1.减轻数据库压力

我个人会对此负责:

SELECT `post`.*,
       `post`.`team1_seourl` AS `team1seourl`,
       `post`.`team1_seourl` AS `teamseourl`,
       `post`.`team2_seourl` AS `team2seourl`,
       IF(`temp_tn1uid`.`value` > 0, `post`.`team1_uid`, NULL) AS `tn1uid`,
       IF(`temp_tn2uid`.`value` > 0, `post`.`team2_uid`, NULL) AS `tn2uid`
FROM
  (SELECT `post`.*,
          `post_j`.`title`,
          `post_j`.`teaser`
   FROM
     (SELECT `post`.*
      FROM `sportnews_cache_post_team` AS `post`
      FORCE INDEX(`sort_index`)
      JOIN
        (SELECT `cache_uid`
         FROM `sportnews_cache_post_team` AS `post`
         WHERE (`post`.`team1_uid` = 4894
                OR `post`.`team2_uid` = 4894)
         GROUP BY `post`.`uid`
         ORDER BY `post`.`cache_uid` LIMIT 40
         OFFSET 0) AS `post_j` ON `post`.`cache_uid` = `post_j`.`cache_uid`) AS `post`
   JOIN `sportnews_post` AS `post_j` ON `post_j`.`uid` = `post`.`uid`) AS `post`
LEFT JOIN
  (SELECT `uid`,
          COUNT(*) AS `value`
   FROM `sportnews_cache_post_team` AS `post`
   FORCE INDEX(`sort_index`)
   WHERE `post`.`team1_uid` = 4894
   GROUP BY `post`.`uid`) AS `temp_tn1uid` ON `temp_tn1uid`.`uid` = `post`.`uid`
LEFT JOIN
  (SELECT `uid`,
          COUNT(*) AS `value`
   FROM `sportnews_cache_post_team` AS `post`
   FORCE INDEX(`sort_index`)
   WHERE `post`.`team2_uid` = 4894
   GROUP BY `post`.`uid`) AS `temp_tn2uid` ON `temp_tn2uid`.`uid` = `post`.`uid`

从您的日志中。 我还没有一个数据库引擎能够以有效的方式加入这么多子选择。 我从日志中假设您正在使用它来创建临时表-这是一个非常好的技巧。 您可能想考虑为其中一些子查询创建临时表,设置与您的任务相关的适当索引,然后再将它们加入。 我希望此查询不会过于频繁地发送到数据库。

SQL中有一个有用的EXPLAIN命令。 尝试该文档: 此处

2.判断结果集

取决于您的sportsnews_log表的大小,您可能会在长时间writing to net发生这种情况:

SELECT /*!40001 SQL_NO_CACHE */ * FROM `sportnews_log`

@comment:我可能以为是错误的原因,因为我不知道您的数据库,但是我认为sportsnews_log表可能很大(假设记录sportsnews_log 250k)。 我很确定您不会在现场显示所有这些输入。 SQL_NO_CACHE不能帮助固定该查询,也不建议使用* (有点)-但在您的情况下可能有必要。 如果您定期重写sportnews_log并保持sportnews_log行,我可能会想错了,但是我确信您会理解我对此表示怀疑的原因。 您可能正在使用约20条记录,因此对最新输入使用适当的ORDER进行简单的LIMIT将产生HUDGE差异。

3.经常相同的查询

让我们以单独的方式对待这一点:

SELECT `detail`, UNIX_TIMESTAMP(created_on) AS created_on
FROM (`sportnews_log`)
WHERE `severity` =  'info'
AND `source` =  'crawler'
ORDER BY `created_on` desc

它更像是#2的示例,也许适当的LIMITLIMIT ,但是我认为此查询非常频繁地触发。 可能有一个针对您的新解决方案, 但有一个条件 :那些结果不需要是100%实际的,可以说在发布确定之前可以偏移5分钟。 为此,有一些缓存机制可能会有所帮助。 在我工作的公司中,我们使用的是memcashed (请查看“嵌入式用户”列表)。 PHP很好地支持它。 随之而来的是,新解决方案的伪代码为:

declare RESULT
RESULT get from cache on key LAZY_UPDATE
if RESULT is false
    get use of your DB and set RESULT into query result
    set cache under LAZY_UPDATE key to value of RESULT for 5 minutes

return RESULT

这将使您每5分钟仅对一次特定查询施加压力。 如果到目前为止您对此仍然不感兴趣,请在这里看看。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM