duanba8070 2013-03-29 05:03
浏览 49
已采纳

为什么有时候查询需要3秒才能完成工作

The application is real time site that need a speed of access on every query (select, update, insert) Low latency must less than 200ms every query

Well, On average 98% each query. time is less than 0.001-0.005 secound on for complete job query.

the problem is Sometime around 5 time per hour, they can take up to 1s and may be 5s, i don't know real cause of problem

i found to reducing the problem are move that from INNODB to MEMORY.

THE QUESTION are Why sometime the query can take time up to 5 secound ?

Example query in sometime query more than 1 secound

# Time: 130328 20:27:40
# User@Host: ferge572w[ferge572w] @ localhost []
# Query_time: 1.339712  Lock_time: 0.000026 Rows_sent: 0  Rows_examined: 1
SET timestamp=1364477260;
UPDATE log_product SET credit=credit+1 WHERE id_product='149721921' and id_user='2029275' LIMIT 1;

table index: id_product, id_user
No.row: 33,491   table size: 5Mb

# Time: 130329  7:25:37
# User@Host: ferge572w[ferge572w] @ localhost []
# Query_time: 1.439856  Lock_time: 0.000031 Rows_sent: 0  Rows_examined: 1
SET timestamp=1364516737;
UPDATE product SET lastuser='hello',picperson='1',lastid='2030505',country='thailand',price=price+0.01,time=DATE_ADD(time, INTERVAL 3 SECOND) WHERE id='349721227' LIMIT 1;

table index: id
No.row: 35   table size: 2.1Mb

i ensure EXPLAIN to optimize query and update use index. also checked data types and their lengths of the fields of the table but still problem


UPDATE i find the cause of problem are when system High IOwait. the slow query heppen Immediate. How to fix it

Slow query when IO wait is high.

Show from iotop command

-- TID -- PRIO -- USER -- DISK READ -- DISK WRITE -- SWAPIN -- IO> -- COMMAND

-- 2311 -- be/4 -- mysql -- 0.00 B/s -- 0.00 B/s -- 0.00% -- 96.25% -- mysql~l.sock

-- 2311 -- be/4 -- mysql -- 0.00 B/s -- 0.00 B/s -- 0.00% -- 96.25% -- mysql~l.sock

-- 2311 -- be/4 -- mysql -- 0.00 B/s -- 0.00 B/s -- 0.00% -- 96.24% -- mysql~l.sock

High IO wait start when 6:13:28 PM - 6:13:29 PM (sar command)

--------------------- CPU -- %usr -- %nice -- %sys -- %iowait -- %steal

-- 6:13:28 PM --- all -- 2.53 -- 0.00 -- 2.02 -- 39.39 -- 0.00

-- 6:13:29 PM --- all -- 1.99 -- 0.00 -- 1.00 -- 49.25 -- 0.00

Got slow query between that time

Time: 130329 18:13:29

User@Host: wdwdwd[wdwdwd] @ localhost []

Query_time: 2.007902 Lock_time: 0.000025 Rows_sent: 0 Rows_examined: 1 SET timestamp=1364555609;

UPDATE log_product SET credit=credit+1 WHERE id_product='349721228' and id_user='2021841' LIMIT 1;

  • 写回答

4条回答 默认 最新

  • douquanzhan0315 2013-03-29 05:09
    关注

    There could be a number of reasons, the more data you have (and check) the closer you'll get to finding your answer.

    Things to check:

    • Are you on shared hosting, they can be unreliable.
    • Have you checked mySQL slow logs
    • Have you done a mysql explain on your queries?
    • Are you getting lots of requests at the time your SQL queries are too slow, disk IO could be an issue
    • Do your tables need to be optimised?
    • Are you running out of memory on the machine?

    http://newrelic.com/ can be very helpful in these situations (and they have a free version which you can take advantage of)

    Potential Reasons:

    • Disk I/O: You are on shared hosting and/or your server's disk is
      unreliable/saturated at times
    • Peak Usage: Lots of traffic/queries at specific times causing delays
    • Other Server related slowdowns: e.g AntiVirus or another process is running and chewing up resources

    If you're able to do more analysis of your data as I and others have suggested it could prove very valuable in getting to the bottom of your particular issue

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序