PHP Mysql - 长查询成功后下一个短查询超时

如何解决PHP Mysql - 长查询成功后下一个短查询超时

所以我们有一个最多需要 3 分钟才能完成的大查询,之后还有多个小查询

最初,我们在第一次查询时出现超时,因此在 my.cnf 中增加超时变量 + 更改防火墙中的一些设置(PHPMysqL 在 2 个不同的 CentOS7 虚拟机中,并且它们与 pfSense - HAProxy 连接)做了把戏。

但是现在,在任何需要超过 30 秒的事情之后的小查询中,我们都会得到“MysqL 已经消失”,就好像 MysqL 需要休息一下一样。 (我们保持相同的连接)。

我做了一个简单的测试,如下所示:

   SELECT SLEEP(180),123 AS `abc` <-- Used to yield gone away WITHOUT outputing "0|123"
   SELECT SLEEP(1),456 AS `abc`

它曾经产生过,现在它工作得很好

现在对于另外 2 个场景,这个是有效的:

   SELECT SLEEP(29),123 AS `abc` <-- Ouputs "0|123"
   SELECT SLEEP(5),456 AS `abc` <-- Outputs "0|456"

但是这个死在第二个语句中:

   SELECT SLEEP(31),123 AS `abc` <-- Ouputs "0|123"
   SELECT SLEEP(1),456 AS `abc` <-- Gone away

我在 my.cnf 中放入的我认为相关的部分内容

    wait_timeout=1800
    net_read_timeout=1800
    net_write_timeout=1800
    slave_net_timeout=1800
    max_connections=10000
    innodb_log_file_size=512M
    innodb_buffer_pool_size=1G
    innodb_lock_wait_timeout=1800
    max_allowed_packet=256M
    group_concat_max_len=22000000
    lock_wait_timeout=3153600

以及完整的输出(来自 PHPMyAdmin):

    alter algorithm DEFAULT
    aria block size 8,192
    aria checkpoint interval    30
    aria checkpoint log activity    1,048,576
    aria encrypt tables OFF
    aria force start after recovery failures    0
    aria group commit   none
    aria group commit interval  0
    aria log file size  1,073,741,824
    aria log purge type immediate
    aria max sort file size 9,223,372,036,853,727,232
    aria page checksum  ON
    aria pagecache age threshold    300
    aria pagecache buffer size  134,217,728
    aria pagecache division limit   100
    aria pagecache file hash size   512
    aria recover options    BACKUP,QUICK
    aria repair threads 1
    aria sort buffer size   268,434,432
    aria stats method   nulls_unequal
    aria sync log dir   NEWFILE
    aria used for temp tables   ON
    auto increment increment    1
    auto increment offset   1
    autocommit  ON
    automatic sp privileges ON
    back log    900
    basedir /usr/
    big tables  OFF
    bind address    10.2.0.154
    binlog annotate row events  ON
    binlog cache size   32,768
    binlog checksum CRC32
    binlog commit wait count    0
    binlog commit wait usec 100,000
    binlog direct non transactional updates OFF
    binlog file cache size  16,384
    binlog format   MIXED
    binlog optimize thread scheduling   ON
    binlog row image    FULL
    binlog stmt cache size  32,768
    bulk insert buffer size 8,388,608
    character set client    latin1
    character set client (Session value)    utf8mb4
    character set connection    latin1
    character set connection (Session value)    utf8mb4
    character set database  latin1
    character set filesystem    binary
    character set results   latin1
    character set results (Session value)   utf8mb4
    character set server    latin1
    character set system    utf8
    character sets dir  /usr/share/MysqL/charsets/
    check constraint checks ON
    collation connection    latin1_swedish_ci
    collation connection (Session value)    utf8mb4_unicode_ci
    collation database  latin1_swedish_ci
    collation server    latin1_swedish_ci
    column compression threshold    100
    column compression zlib level   6
    column compression zlib strategy    DEFAULT_STRATEGY
    column compression zlib wrap    OFF
    completion type NO_CHAIN
    concurrent insert   AUTO
    connect timeout 10
    core file   OFF
    datadir /var/lib/MysqL/
    date format %Y-%m-%d
    datetime format %Y-%m-%d %H:%i:%s
    deadlock search depth long  15
    deadlock search depth short 4
    deadlock timeout long   50,000,000
    deadlock timeout short  10,000
    debug no thread alarm   OFF
    default regex flags 
    default storage engine  InnoDB
    default tmp storage engine  
    default week format 0
    delay key write ON
    delayed insert limit    100
    delayed insert timeout  300
    delayed queue size  1,000
    div precision increment 4
    encrypt binlog  OFF
    encrypt tmp disk tables OFF
    encrypt tmp files   OFF
    enforce storage engine  
    eq range index dive limit   0
    event scheduler OFF
    expensive subquery limit    100
    expire logs days    0
    explicit defaults for timestamp OFF
    extra max connections   1
    extra port  0
    flush   OFF
    flush time  0
    foreign key checks  ON
    ft boolean Syntax   + -><()~*:""&|
    ft max word len 84
    ft min word len 4
    ft query expansion limit    20
    ft stopword file    (built-in)
    general log OFF
    general log file    /var/lib/MysqL/_logs/general
    group concat max len    22,000
    gtid binlog pos 
    gtid binlog state   
    gtid current pos    0-2-77303
    gtid domain id  0
    gtid ignore duplicates  OFF
    gtid pos auto engines   
    gtid slave pos  0-2-77303
    gtid strict mode    OFF
    have compress   YES
    have crypt  YES
    have dynamic loading    YES
    have geometry   YES
    have openssl    YES
    have profiling  YES
    have query cache    YES
    have rtree keys YES
    have ssl    disABLED
    have symlink    YES
    histogram size  0
    histogram type  SINGLE_PREC_HB
    host cache size 1,103
    hostname    kb-malga-sql1
    idle readonly transaction timeout   0
    idle transaction timeout    0
    idle write transaction timeout  0
    ignore builtin innodb   OFF
    ignore db dirs  
    in predicate conversion threshold   1,000
    init connect    
    init file   
    init slave  
    innodb adaptive flushing    ON
    innodb adaptive flushing lwm    10
    innodb adaptive hash index  ON
    innodb adaptive hash index parts    8
    innodb adaptive max sleep delay 150,000
    innodb autoextend increment 64
    innodb autoinc lock mode    1
    innodb background scrub data check interval 3,600
    innodb background scrub data compressed OFF
    innodb background scrub data interval   604,800
    innodb background scrub data uncompressed   OFF
    innodb buf dump status frequency    0
    innodb buffer pool chunk size   134,728
    innodb buffer pool dump at shutdown ON
    innodb buffer pool dump Now OFF
    innodb buffer pool dump pct 25
    innodb buffer pool filename ib_buffer_pool
    innodb buffer pool instances    8
    innodb buffer pool load abort   OFF
    innodb buffer pool load at startup  ON
    innodb buffer pool load Now OFF
    innodb buffer pool size 1,824
    innodb change buffer max size   25
    innodb change buffering all
    innodb checksum algorithm   crc32
    innodb checksums    ON
    innodb cmp per index enabled    OFF
    innodb commit concurrency   0
    innodb compression algorithm    zlib
    innodb compression default  OFF
    innodb compression failure threshold pct    5
    innodb compression level    6
    innodb compression pad pct max  50
    innodb concurrency tickets  5,000
    innodb data file path   ibdata1:12M:autoextend
    innodb data home dir    
    innodb deadlock detect  ON
    innodb default encryption key id    1
    innodb default row format   dynamic
    innodb defragment   OFF
    innodb defragment fill factor   1
    innodb defragment fill factor n recs    20
    innodb defragment frequency 40
    innodb defragment n pages   7
    innodb defragment stats accuracy    0
    innodb disable sort file cache  OFF
    innodb disallow writes  OFF
    innodb doublewrite  ON
    innodb encrypt log  OFF
    innodb encrypt tables   OFF
    innodb encrypt temporary tables OFF
    innodb encryption rotate key age    1
    innodb encryption rotation iops 100
    innodb encryption threads   0
    innodb fast shutdown    1
    innodb fatal semaphore wait threshold   600
    innodb file format  
    innodb file per table   ON
    innodb fill factor  100
    innodb flush log at timeout 1
    innodb flush log at trx commit  1
    innodb flush method fsync
    innodb flush neighbors  1
    innodb flush sync   ON
    innodb flushing avg loops   30
    innodb force load corrupted OFF
    innodb force primary key    OFF
    innodb force recovery   0
    innodb ft aux table 
    innodb ft cache size    8,000
    innodb ft enable diag print OFF
    innodb ft enable stopword   ON
    innodb ft max token size    84
    innodb ft min token size    3
    innodb ft num word optimize 2,000
    innodb ft result cache limit    2,000
    innodb ft server stopword table 
    innodb ft sort pll degree   2
    innodb ft total cache size  640,000
    innodb ft user stopword table   
    innodb idle flush pct   100
    innodb immediate scrub data uncompressed    OFF
    innodb instant alter column allowed add_last
    innodb io capacity  200
    innodb io capacity max  2,000
    innodb large prefix 
    innodb lock schedule algorithm  fcfs
    innodb lock wait timeout    1,800
    innodb locks unsafe for binlog  OFF
    innodb log buffer size  16,777,216
    innodb log checksums    ON
    innodb log compressed pages ON
    innodb log file size    536,870,912
    innodb log files in group   2
    innodb log group home dir   ./
    innodb log optimize ddl OFF
    innodb log write ahead size 8,192
    innodb lru scan depth   1,024
    innodb max dirty pages pct  75
    innodb max dirty pages pct lwm  0
    innodb max purge lag    0
    innodb max purge lag delay  0
    innodb max purge lag wait   4,294,967,295
    innodb max undo log size    10,485,760
    innodb monitor disable  
    innodb monitor enable   
    innodb monitor reset    
    innodb monitor reset all    
    innodb old blocks pct   37
    innodb old blocks time  1,000
    innodb online alter log max size    134,728
    innodb open files   2,000
    innodb optimize fulltext only   OFF
    innodb page cleaners    4
    innodb page size    16,384
    innodb prefix index cluster optimization    OFF
    innodb print all deadlocks  OFF
    innodb purge batch size 300
    innodb purge rseg truncate frequency    128
    innodb purge threads    4
    innodb random read ahead    OFF
    innodb read ahead threshold 56
    innodb read io threads  4
    innodb read only    OFF
    innodb replication delay    0
    innodb rollback on timeout  OFF
    innodb rollback segments    128
    innodb scrub log    OFF
    innodb scrub log speed  256
    innodb sort buffer size 1,576
    innodb spin wait delay  4
    innodb stats auto recalc    ON
    innodb stats include delete marked  OFF
    innodb stats method nulls_equal
    innodb stats modified counter   0
    innodb stats on Metadata    OFF
    innodb stats persistent ON
    innodb stats persistent sample pages    20
    innodb stats sample pages   8
    innodb stats Traditional    ON
    innodb stats transient sample pages 8
    innodb status output    OFF
    innodb status output locks  OFF
    innodb strict mode  OFF
    innodb sync array size  1
    innodb sync spin loops  30
    innodb table locks  ON
    innodb temp data file path  ibtmp1:12M:autoextend
    innodb thread concurrency   0
    innodb thread sleep delay   10,000
    innodb tmpdir   
    innodb undo directory   ./
    innodb undo log truncate    OFF
    innodb undo logs    128
    innodb undo tablespaces 0
    innodb use atomic writes    ON
    innodb use native aio   ON
    innodb version  10.3.29
    innodb write io threads 4
    interactive timeout 28,800
    join buffer size    262,144
    join buffer space limit 2,097,152
    join cache level    2
    keep files on create    OFF
    key buffer size 134,728
    key cache age threshold 300
    key cache block size    1,024
    key cache division limit    100
    key cache file hash size    512
    key cache segments  0
    large files support ON
    large page size 0
    large pages OFF
    lc messages en_US
    lc messages dir 
    lc time names   en_US
    license GPL
    local infile    ON
    lock wait timeout   3,153,600
    locked in memory    OFF
    log bin OFF
    log bin basename    
    log bin compress    OFF
    log bin compress min len    256
    log bin index   
    log bin trust function creators OFF
    log disabled statements sp
    log error   /var/lib/MysqL/_logs/error.err
    log output  FILE
    log queries not using indexes   ON
    log slave updates   OFF
    log slow admin statements   ON
    log slow disabled statements    sp
    log slow filter admin,filesort,filesort_on_disk,filesort_priority_queue,full_join,full_scan,not_using_index,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk
    log slow rate limit 5
    log slow slave statements   ON
    log slow verbosity  query_plan,explain
    log tc size 24,576
    log warnings    2
    long query time 5
    low priority updates    OFF
    lower case file system  OFF
    lower case table names  1
    master verify checksum  OFF
    max allowed packet  268,435,456
    max binlog cache size   18,446,744,709,547,520
    max binlog size 1,824
    max binlog stmt cache size  18,520
    max connect errors  100
    max connections 10,000
    max delayed threads 20
    max digest length   1,024
    max error count 64
    max heap table size 16,216
    max insert delayed threads  20
    max join size   18,551,616
    max length for sort data    1,024
    max long data size  268,456
    max prepared stmt count 16,382
    max recursive iterations    4,295
    max relay log size  1,824
    max seeks for key   4,295
    max session mem used    9,854,775,808
    max sort length 1,024
    max sp recursion depth  0
    max statement time  0
    max tmp tables  32
    max user connections    0
    max write lock count    4,295
    Metadata locks cache size   1,024
    Metadata locks hash instances   8
    min examined row limit  0
    mrr buffer size 262,144
    multi range count   256
    myisam block size   1,024
    myisam data pointer size    6
    myisam max sort file size   9,232
    myisam mmap size    18,616
    myisam recover options  BACKUP,QUICK
    myisam repair threads   1
    myisam sort buffer size 134,216,704
    myisam stats method NULLS_UNEQUAL
    myisam use mmap OFF
    MysqL56 temporal format ON
    net buffer length   16,384
    net read timeout    1,800
    net retry count 10
    net write timeout   1,800
    old OFF
    old alter table DEFAULT
    old mode    
    old passwords   OFF
    open files limit    32,768
    optimizer prune level   1
    optimizer search depth  62
    optimizer selectivity sampling limit    100
    optimizer switch    index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on
    optimizer use condition selectivity 1
    performance schema  OFF
    performance schema accounts size    -1
    performance schema digests size -1
    performance schema events stages history long size  -1
    performance schema events stages history size   -1
    performance schema events statements history long size  -1
    performance schema events statements history size   -1
    performance schema events waits history long size   -1
    performance schema events waits history size    -1
    performance schema hosts size   -1
    performance schema max cond classes 80
    performance schema max cond instances   -1
    performance schema max digest length    1,024
    performance schema max file classes 50
    performance schema max file handles 32,768
    performance schema max file instances   -1
    performance schema max mutex classes    200
    performance schema max mutex instances  -1
    performance schema max rwlock classes   40
    performance schema max rwlock instances -1
    performance schema max socket classes   10
    performance schema max socket instances -1
    performance schema max stage classes    160
    performance schema max statement classes    200
    performance schema max table handles    -1
    performance schema max table instances  -1
    performance schema max thread classes   50
    performance schema max thread instances -1
    performance schema session connect attrs size   -1
    performance schema setup actors size    100
    performance schema setup objects size   100
    performance schema users size   -1
    pid file    /var/lib/MysqL/kb-malga-sql1.pid
    plugin dir  /usr/lib64/MysqL/plugin/
    plugin maturity gamma
    port    3,306
    preload buffer size 32,768
    profiling   OFF
    profiling history size  15
    progress report time    5
    protocol version    10
    proxy protocol networks 
    query alloc block size  16,384
    query cache limit   1,576
    query cache min res unit    4,096
    query cache size    1,576
    query cache strip comments  OFF
    query cache type    OFF
    query cache wlock invalidate    OFF
    query prealloc size 24,576
    range alloc block size  4,096
    read binlog speed limit 0
    read buffer size    131,072
    read only   OFF
    read rnd buffer size    262,144
    relay log   
    relay log basename  
    relay log index 
    relay log info file relay-log.info
    relay log purge ON
    relay log recovery  OFF
    relay log space limit   0
    replicate annotate row events   ON
    replicate do db 
    replicate do table  
    replicate events marked for skip    REPLICATE
    replicate ignore db 
    replicate ignore table  
    replicate wild do table 
    replicate wild ignore table 
    report host 
    report password 
    report port 3,306
    report user 
    rowid merge buff size   8,608
    rpl semi sync master enabled    OFF
    rpl semi sync master timeout    10,000
    rpl semi sync master trace level    32
    rpl semi sync master wait no slave  ON
    rpl semi sync master wait point AFTER_COMMIT
    rpl semi sync slave delay master    OFF
    rpl semi sync slave enabled OFF
    rpl semi sync slave kill conn timeout   5
    rpl semi sync slave trace level 32
    secure auth ON
    secure file priv    
    secure timestamp    NO
    server id   1
    session track schema    ON
    session track state change  OFF
    session track system variables  autocommit,character_set_client,character_set_connection,character_set_results,time_zone
    session track transaction info  OFF
    skip external locking   ON
    skip name resolve   OFF
    skip networking OFF
    skip show database  OFF
    slave compressed protocol   OFF
    slave ddl exec mode IDEMPOTENT
    slave domain parallel threads   0
    slave exec mode STRICT
    slave load tmpdir   /tmp
    slave max allowed packet    1,824
    slave net timeout   1,800
    slave parallel max queued   131,072
    slave parallel mode conservative
    slave parallel threads  0
    slave parallel workers  0
    slave run triggers for rbr  NO
    slave skip errors   OFF
    slave sql verify checksum   ON
    slave transaction retries   10
    slave transaction retry errors  1213,1205
    slave transaction retry interval    0
    slave type conversions  
    slow launch time    2
    slow query log  OFF
    slow query log file /var/lib/MysqL/_logs/slow
    socket  /var/lib/MysqL/MysqL.sock
    sort buffer size    2,152
    sql auto is null    OFF
    sql big selects ON
    sql buffer result   OFF
    sql log bin ON
    sql log off OFF
    sql mode    ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    sql notes   ON
    sql quote show create   ON
    sql safe updates    OFF
    sql select limit    18,616
    sql slave skip counter  0
    sql warnings    OFF
    ssl ca  
    ssl capath  
    ssl cert    
    ssl cipher  
    ssl crl 
    ssl crlpath 
    ssl key 
    standard compliant cte  ON
    storage engine  InnoDB
    stored program cache    256
    strict password validation  ON
    sync binlog 0
    sync frm    ON
    sync master info    10,000
    sync relay log  10,000
    sync relay log info 10,000
    system time zone    EDT
    system versioning alter history ERROR
    system versioning asof  DEFAULT
    table deFinition cache  400
    table open cache    2,000
    table open cache instances  5
    tcp keepalive interval  0
    tcp keepalive probes    0
    tcp keepalive time  0
    thread cache size   256
    thread concurrency  10
    thread handling one-thread-per-connection
    thread pool idle timeout    60
    thread pool max threads 65,536
    thread pool oversubscribe   3
    thread pool prio kickup timer   1,000
    thread pool priority    auto
    thread pool size    2
    thread pool stall limit 500
    thread stack    299,008
    time format %H:%i:%s
    time zone   SYstem
    timed mutexes   OFF
    tmp disk table size 18,616
    tmp memory table size   16,216
    tmp table size  16,216
    tmpdir  /tmp
    transaction alloc block size    8,192
    transaction prealloc size   4,096
    tx isolation    REPEATABLE-READ
    tx read only    OFF
    unique checks   ON
    updatable views with limit  YES
    use stat tables NEVER
    userstat    OFF
    version 10.3.29-MariaDB
    version comment MariaDB Server
    version compile machine x86_64
    version compile os  Linux
    version malloc library  system
    version source revision 4f143a88bcb36e94e9edba8a3c5b4a350dcd9bf9
    version ssl library OpenSSL 1.0.2k-fips 26 Jan 2017
    wait timeout    1,800
    wsrep osu method    TOI
    wsrep auto increment control    ON
    wsrep causal reads  OFF
    wsrep certification rules   strict
    wsrep certify nonpk ON
    wsrep cluster address   
    wsrep cluster name  my_wsrep_cluster
    wsrep convert lock to trx   OFF
    wsrep data home dir /var/lib/MysqL/
    wsrep dbug option   
    wsrep debug OFF
    wsrep desync    OFF
    wsrep dirty reads   OFF
    wsrep drupal 282555 workaround  OFF
    wsrep forced binlog format  NONE
    wsrep gtid domain id    0
    wsrep gtid mode OFF
    wsrep load data splitting   ON
    wsrep log conflicts OFF
    wsrep max ws rows   0
    wsrep max ws size   2,147,483,647
    wsrep MysqL replication bundle  0
    wsrep node address  
    wsrep node incoming address AUTO
    wsrep node name kb-malga-sql1
    wsrep notify cmd    
    wsrep on    OFF
    wsrep patch version wsrep_25.24
    wsrep provider  none
    wsrep provider options  
    wsrep recover   OFF
    wsrep reject queries    NONE
    wsrep replicate myisam  OFF
    wsrep restart slave OFF
    wsrep retry autocommit  1
    wsrep slave fk checks   ON
    wsrep slave uk checks   OFF
    wsrep slave threads 1
    wsrep sst auth  
    wsrep sst donor 
    wsrep sst donor rejects queries OFF
    wsrep sst method    rsync
    wsrep sst receive address   AUTO
    wsrep start position    00000000-0000-0000-0000-000000000000:-1
    wsrep sync wait 0

编辑

PHP.ini 中:

    max_execution_time: 1600
    max_input_time: 1600
    memory_limit: 4096M
    session.gc_maxlifetime: 10800

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?