Простой MySQL SELECT может иногда зависать как «отправка данных» бесконечно - PullRequest
0 голосов
/ 21 марта 2020

В моем приложении nodejs я общаюсь с mySQL в экземпляре AWS RDS с помощью mysql -connection-pool-manager.

В случайные моменты (это может быть после несколько часов или несколько дней), запросы, следуя шаблону, описанному ниже, начинают составлять как MySQL процессы со статусом «отправка данных» до тех пор, пока не будет доступно соединение, и ЦП сервера БД не достигнет своего максимума.

    let sql = `SELECT * FROM jobs WHERE hash = "${hash}" AND (expiryDate = -1 OR expiryDate > "${moment().format('YYYY-MM-DD HH:mm:ss')}") ORDER BY createdDate DESC LIMIT ${limit};`

В обычное время выполнение запросов занимает менее 100 мс. Никакой другой запрос в моем коде не вызывает такого поведения.

Вот что дает EXPLAIN:

    id  select_type table   partitions  type    possible_keys   key key_len ref rows    filtered    Extra
    -------------------------------------------------------------------------------------------
    1   SIMPLE  jobs    NULL    ref hash,expiryDate hash    41  const   38  1.45    Using index condition; Using where; Using filesort

Вот моя NodeJS конфигурация:


    import PoolManager from 'mysql-connection-pool-manager';

    const mySQLSettings = {
        connectionLimit : 30,
        host     : MYSQL_HOST,
        user     : MYSQL_USER,
        password : MYSQL_PWD,
        port     : MYSQL_PORT, 
        database : MYSQL_DB,
        debug    : false
    }

    const options = {
        idleCheckInterval: 1000,
        maxConnextionTimeout: 30000,
        idlePoolTimeout: 3000,
        errorLimit: 5,
        preInitDelay: 50,
        sessionTimeout: 60000,
        stringifyObjects: true,
        mySQLSettings
    }

    const dbPool = PoolManager(options)

    const sql = `SELECT * FROM jobs WHERE hash = "${hash}" AND (expiryDate = -1 OR expiryDate > "${moment().format('YYYY-MM-DD HH:mm:ss')}") ORDER BY createdDate DESC LIMIT ${limit}`

    const res = new Promise( ( resolve, reject ) => {
                dbPool.query(sql, (results, error) => {
                    if (error) reject(error);
                    resolve(results)
                });
            })

My AWS Сервер:

  • vCPU: 1
  • ОЗУ: 2 ГБ
  • Тип хранилища: Универсальный (SSD)

Результат ШОУ ГЛОБАЛЬНОГО СТАТУСА

    Variable_name   Value
    Aborted_clients 5971
    Aborted_connects    1206
    Acl_cache_items_count   0
    Binlog_cache_disk_use   214
    Binlog_cache_use    3787500
    Binlog_stmt_cache_disk_use  0
    Binlog_stmt_cache_use   1
    Bytes_received  1944750318
    Bytes_sent  75256661478
    Connection_errors_accept    0
    Connection_errors_internal  0
    Connection_errors_max_connections   191
    Connection_errors_peer_address  0
    Connection_errors_select    0
    Connection_errors_tcpwrap   0
    Connections 49377
    Created_tmp_disk_tables 8
    Created_tmp_files   221
    Created_tmp_tables  7450
    Delayed_errors  0
    Delayed_insert_threads  0
    Delayed_writes  0
    Flush_commands  2
    Handler_commit  10819429
    Handler_delete  437
    Handler_discover    0
    Handler_external_lock   14188461
    Handler_mrr_init    0
    Handler_prepare 7559400
    Handler_read_first  30870
    Handler_read_key    18064567
    Handler_read_last   563
    Handler_read_next   3943222118
    Handler_read_prev   41737711
    Handler_read_rnd    4263804
    Handler_read_rnd_next   299831370
    Handler_rollback    1937
    Handler_savepoint   0
    Handler_savepoint_rollback  0
    Handler_update  490733316
    Handler_write   3499046
    Innodb_buffer_pool_dump_status  Dumping of buffer pool not started
    Innodb_buffer_pool_load_status  Buffer pool(s) load completed at 200321  8:57:36
    Innodb_buffer_pool_resize_status    
    Innodb_buffer_pool_pages_data   53529
    Innodb_buffer_pool_bytes_data   877019136
    Innodb_buffer_pool_pages_dirty  8713
    Innodb_buffer_pool_bytes_dirty  142753792
    Innodb_buffer_pool_pages_flushed    11092409
    Innodb_buffer_pool_pages_free   7970
    Innodb_buffer_pool_pages_misc   4037
    Innodb_buffer_pool_pages_total  65536
    Innodb_buffer_pool_read_ahead_rnd   0
    Innodb_buffer_pool_read_ahead   10580
    Innodb_buffer_pool_read_ahead_evicted   108
    Innodb_buffer_pool_read_requests    14672318239
    Innodb_buffer_pool_reads    41762328
    Innodb_buffer_pool_wait_free    6540
    Innodb_buffer_pool_write_requests   1086398728
    Innodb_data_fsyncs  10205996
    Innodb_data_pending_fsyncs  2
    Innodb_data_pending_reads   3
    Innodb_data_pending_writes  0
    Innodb_data_read    732931462144
    Innodb_data_reads   44734741
    Innodb_data_writes  36085334
    Innodb_data_written 443458075648
    Innodb_dblwr_pages_written  11097749
    Innodb_dblwr_writes 1068518
    Innodb_log_waits    0
    Innodb_log_write_requests   1025512278
    Innodb_log_writes   23806089
    Innodb_os_log_fsyncs    6351503
    Innodb_os_log_pending_fsyncs    1
    Innodb_os_log_pending_writes    0
    Innodb_os_log_written   53159322624
    Innodb_page_size    16384
    Innodb_pages_created    672546
    Innodb_pages_read   44734579
    Innodb_pages_written    11097905
    Innodb_row_lock_current_waits   5
    Innodb_row_lock_time    704388224
    Innodb_row_lock_time_avg    482
    Innodb_row_lock_time_max    51989
    Innodb_row_lock_waits   1458909
    Innodb_rows_deleted 437
    Innodb_rows_inserted    559616
    Innodb_rows_read    4290990284
    Innodb_rows_updated 490722627
    Innodb_num_open_files   86
    Innodb_truncated_status_writes  0
    Innodb_undo_tablespaces_total   2
    Innodb_undo_tablespaces_implicit    2
    Innodb_undo_tablespaces_explicit    0
    Innodb_undo_tablespaces_active  1
    Key_blocks_not_flushed  0
    Key_blocks_unused   13396
    Key_blocks_used 0
    Key_read_requests   0
    Key_reads   0
    Key_write_requests  0
    Key_writes  0
    Locked_connects 0
    Max_execution_time_exceeded 0
    Max_execution_time_set  0
    Max_execution_time_set_failed   0
    Max_used_connections    153
    Max_used_connections_time   2020-03-22 10:52:05
    Not_flushed_delayed_rows    0
    Ongoing_anonymous_transaction_count 2
    Open_files  8
    Open_streams    0
    Open_table_definitions  125
    Open_tables 1558
    Opened_files    4645
    Opened_table_definitions    147
    Opened_tables   1580
    Queries 14098826
    Questions   7197343
    Secondary_engine_execution_count    0
    Select_full_join    18
    Select_full_range_join  2
    Select_range    364705
    Select_range_check  0
    Select_scan 32275
    Slave_open_temp_tables  0
    Slow_launch_threads 0
    Slow_queries    0
    Sort_merge_passes   2835
    Sort_range  10184
    Sort_rows   12303451
    Sort_scan   373080
    Table_locks_immediate   447
    Table_locks_waited  0
    Table_open_cache_hits   7092678
    Table_open_cache_misses 1580
    Table_open_cache_overflows  0
    Tc_log_max_pages_used   0
    Tc_log_page_size    0
    Tc_log_page_waits   0
    Threads_cached  9
    Threads_connected   92
    Threads_created 23589
    Threads_running 46
    Uptime  132019
    Uptime_since_flush_status   132019

Результаты ШОУ ГЛОБАЛЬНЫХ ПЕРЕМЕННЫХ через 24 часа


    Variable_name   Value
    activate_all_roles_on_login OFF
    admin_address   
    admin_port  33062
    auto_generate_certs ON
    auto_increment_increment    1
    auto_increment_offset   1
    autocommit  ON
    automatic_sp_privileges ON
    avoid_temporal_upgrade  OFF
    back_log    150
    basedir /rdsdbbin/mysql-8.0.15.R1/
    big_tables  OFF
    bind_address    *
    binlog_cache_size   32768
    binlog_checksum CRC32
    binlog_direct_non_transactional_updates OFF
    binlog_encryption   OFF
    binlog_error_action ABORT_SERVER
    binlog_expire_logs_seconds  2592000
    binlog_format   MIXED
    binlog_group_commit_sync_delay  0
    binlog_group_commit_sync_no_delay_count 0
    binlog_gtid_simple_recovery ON
    binlog_max_flush_queue_time 0
    binlog_order_commits    ON
    binlog_rotate_encryption_master_key_at_startup  OFF
    binlog_row_event_max_size   8192
    binlog_row_image    FULL
    binlog_row_metadata MINIMAL
    binlog_row_value_options    
    binlog_rows_query_log_events    OFF
    binlog_stmt_cache_size  32768
    binlog_transaction_dependency_history_size  25000
    binlog_transaction_dependency_tracking  COMMIT_ORDER
    block_encryption_mode   aes-128-ecb
    bulk_insert_buffer_size 8388608
    caching_sha2_password_auto_generate_rsa_keys    ON
    character_set_client    utf8mb4
    character_set_connection    utf8mb4
    character_set_database  utf8mb4
    character_set_filesystem    binary
    character_set_results   utf8mb4
    character_set_server    utf8mb4
    character_set_system    utf8
    character_sets_dir  /rdsdbbin/mysql-8.0.15.R1/share/charsets/
    check_proxy_users   OFF
    collation_connection    utf8mb4_0900_ai_ci
    collation_database  utf8mb4_0900_ai_ci
    collation_server    utf8mb4_0900_ai_ci
    completion_type NO_CHAIN
    concurrent_insert   AUTO
    connect_timeout 10
    core_file   OFF
    create_admin_listener_thread    OFF
    cte_max_recursion_depth 1000
    default_password_lifetime   0
    default_storage_engine  InnoDB
    default_tmp_storage_engine  InnoDB
    default_week_format 0
    delay_key_write ON
    delayed_insert_limit    100
    delayed_insert_timeout  300
    delayed_queue_size  1000
    disabled_storage_engines    
    disconnect_on_expired_password  ON
    div_precision_increment 4
    end_markers_in_json OFF
    enforce_gtid_consistency    OFF
    eq_range_index_dive_limit   200
    event_scheduler ON
    expire_logs_days    0
    explicit_defaults_for_timestamp ON
    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
    group_concat_max_len    1024
    group_replication_consistency   EVENTUAL
    gtid_executed   
    gtid_executed_compression_period    1000
    gtid_mode   OFF_PERMISSIVE
    gtid_owned  
    gtid_purged 
    have_compress   YES
    have_dynamic_loading    YES
    have_geometry   YES
    have_openssl    YES
    have_profiling  YES
    have_query_cache    NO
    have_rtree_keys YES
    have_ssl    YES
    have_statement_timeout  YES
    have_symlink    DISABLED
    histogram_generation_max_mem_size   20000000
    host_cache_size 278
    hostname    ip-10-4-0-44
    information_schema_stats_expiry 86400
    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 150000
    innodb_api_bk_commit_interval   5
    innodb_api_disable_rowlock  OFF
    innodb_api_enable_binlog    OFF
    innodb_api_enable_mdl   OFF
    innodb_api_trx_level    0
    innodb_autoextend_increment 64
    innodb_autoinc_lock_mode    2
    innodb_buffer_pool_chunk_size   134217728
    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_in_core_file ON
    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 1073741824
    innodb_change_buffer_max_size   25
    innodb_change_buffering all
    innodb_checksum_algorithm   crc32
    innodb_cmp_per_index_enabled    OFF
    innodb_commit_concurrency   0
    innodb_compression_failure_threshold_pct    5
    innodb_compression_level    6
    innodb_compression_pad_pct_max  50
    innodb_concurrency_tickets  5000
    innodb_data_file_path   ibdata1:12M:autoextend
    innodb_data_home_dir    /rdsdbdata/db/innodb
    innodb_deadlock_detect  ON
    innodb_dedicated_server OFF
    innodb_default_row_format   dynamic
    innodb_directories  
    innodb_disable_sort_file_cache  OFF
    innodb_doublewrite  ON
    innodb_fast_shutdown    1
    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 O_DIRECT
    innodb_flush_neighbors  0
    innodb_flush_sync   ON
    innodb_flushing_avg_loops   30
    innodb_force_load_corrupted OFF
    innodb_force_recovery   0
    innodb_fsync_threshold  0
    innodb_ft_aux_table 
    innodb_ft_cache_size    8000000
    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 2000
    innodb_ft_result_cache_limit    2000000000
    innodb_ft_server_stopword_table 
    innodb_ft_sort_pll_degree   2
    innodb_ft_total_cache_size  640000000
    innodb_ft_user_stopword_table   
    innodb_io_capacity  200
    innodb_io_capacity_max  2000
    innodb_lock_wait_timeout    50
    innodb_log_buffer_size  8388608
    innodb_log_checksums    ON
    innodb_log_compressed_pages ON
    innodb_log_file_size    134217728
    innodb_log_files_in_group   2
    innodb_log_group_home_dir   /rdsdbdata/log/innodb
    innodb_log_spin_cpu_abs_lwm 80
    innodb_log_spin_cpu_pct_hwm 50
    innodb_log_wait_for_flush_spin_hwm  400
    innodb_log_write_ahead_size 8192
    innodb_lru_scan_depth   1024
    innodb_max_dirty_pages_pct  90.000000
    innodb_max_dirty_pages_pct_lwm  10.000000
    innodb_max_purge_lag    0
    innodb_max_purge_lag_delay  0
    innodb_max_undo_log_size    1073741824
    innodb_monitor_disable  
    innodb_monitor_enable   
    innodb_monitor_reset    
    innodb_monitor_reset_all    
    innodb_numa_interleave  OFF
    innodb_old_blocks_pct   37
    innodb_old_blocks_time  1000
    innodb_online_alter_log_max_size    134217728
    innodb_open_files   4000
    innodb_optimize_fulltext_only   OFF
    innodb_page_cleaners    4
    innodb_page_size    16384
    innodb_parallel_read_threads    4
    innodb_print_all_deadlocks  OFF
    innodb_print_ddl_logs   OFF
    innodb_purge_batch_size 300
    innodb_purge_rseg_truncate_frequency    128
    innodb_purge_threads    1
    innodb_random_read_ahead    OFF
    innodb_read_ahead_threshold 56
    innodb_read_io_threads  4
    innodb_read_only    OFF
    innodb_redo_log_encrypt OFF
    innodb_replication_delay    0
    innodb_rollback_on_timeout  OFF
    innodb_rollback_segments    128
    innodb_sort_buffer_size 1048576
    innodb_spin_wait_delay  6
    innodb_stats_auto_recalc    ON
    innodb_stats_include_delete_marked  OFF
    innodb_stats_method nulls_equal
    innodb_stats_on_metadata    OFF
    innodb_stats_persistent ON
    innodb_stats_persistent_sample_pages    20
    innodb_stats_transient_sample_pages 8
    innodb_status_output    OFF
    innodb_status_output_locks  OFF
    innodb_strict_mode  ON
    innodb_sync_array_size  1
    innodb_sync_spin_loops  30
    innodb_table_locks  ON
    innodb_temp_data_file_path  ibtmp1:12M:autoextend
    innodb_temp_tablespaces_dir ./#innodb_temp/
    innodb_thread_concurrency   0
    innodb_thread_sleep_delay   10000
    innodb_tmpdir   
    innodb_undo_directory   ./
    innodb_undo_log_encrypt OFF
    innodb_undo_log_truncate    ON
    innodb_undo_tablespaces 2
    innodb_use_native_aio   ON
    innodb_version  8.0.15
    innodb_write_io_threads 4
    interactive_timeout 28800
    internal_tmp_disk_storage_engine    InnoDB
    internal_tmp_mem_storage_engine TempTable
    join_buffer_size    262144
    keep_files_on_create    OFF
    key_buffer_size 16777216
    key_cache_age_threshold 300
    key_cache_block_size    1024
    key_cache_division_limit    100
    keyring_operations  ON
    large_files_support ON
    large_page_size 0
    large_pages OFF
    lc_messages en_US
    lc_time_names   en_US
    license GPL
    local_infile    ON
    lock_wait_timeout   31536000
    locked_in_memory    OFF
    log_bin ON
    log_error_suppression_list  
    log_error_verbosity 2
    log_output  TABLE
    log_queries_not_using_indexes   OFF
    log_slave_updates   ON
    log_slow_admin_statements   OFF
    log_slow_extra  OFF
    log_slow_slave_statements   OFF
    log_timestamps  UTC
    long_query_time 10.000000
    low_priority_updates    OFF
    lower_case_file_system  OFF
    lower_case_table_names  0
    mandatory_roles 
    master_info_repository  TABLE
    master_verify_checksum  OFF
    max_allowed_packet  67108864
    max_binlog_cache_size   18446744073709547520
    max_binlog_size 134217728
    max_binlog_stmt_cache_size  18446744073709547520
    max_connect_errors  100
    max_connections 150
    max_delayed_threads 20
    max_digest_length   1024
    max_error_count 1024
    max_execution_time  0
    max_heap_table_size 16777216
    max_insert_delayed_threads  20
    max_join_size   18446744073709551615
    max_length_for_sort_data    4096
    max_points_in_geometry  65536
    max_prepared_stmt_count 16382
    max_relay_log_size  0
    max_seeks_for_key   18446744073709551615
    max_sort_length 1024
    max_sp_recursion_depth  0
    max_user_connections    0
    max_write_lock_count    18446744073709551615
    min_examined_row_limit  0
    myisam_data_pointer_size    6
    myisam_max_sort_file_size   9223372036853727232
    myisam_mmap_size    18446744073709551615
    myisam_recover_options  OFF
    myisam_repair_threads   1
    myisam_sort_buffer_size 8388608
    myisam_stats_method nulls_unequal
    myisam_use_mmap OFF
    mysql_native_password_proxy_users   OFF
    mysqlx_bind_address *
    mysqlx_connect_timeout  30
    mysqlx_document_id_unique_prefix    0
    mysqlx_idle_worker_thread_timeout   60
    mysqlx_interactive_timeout  28800
    mysqlx_max_allowed_packet   1048576
    mysqlx_max_connections  100
    mysqlx_min_worker_threads   2
    mysqlx_port 33060
    mysqlx_port_open_timeout    0
    mysqlx_read_timeout 28800
    mysqlx_socket   /tmp/mysqlx.sock
    mysqlx_ssl_ca   
    mysqlx_ssl_capath   
    mysqlx_ssl_cert 
    mysqlx_ssl_cipher   
    mysqlx_ssl_crl  
    mysqlx_ssl_crlpath  
    mysqlx_ssl_key  
    mysqlx_wait_timeout 28800
    mysqlx_write_timeout    60
    net_buffer_length   16384
    net_read_timeout    30
    net_retry_count 10
    net_write_timeout   60
    new OFF
    ngram_token_size    2
    offline_mode    OFF
    old OFF
    old_alter_table OFF
    open_files_limit    65535
    optimizer_prune_level   1
    optimizer_search_depth  62
    optimizer_switch    index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=on,block_nested_loop=on,batched_key_access=off,materialization=on,semijoin=on,loosescan=on,firstmatch=on,duplicateweedout=on,subquery_materialization_cost_based=on,use_index_extensions=on,condition_fanout_filter=on,derived_merge=on,use_invisible_indexes=off,skip_scan=on
    optimizer_trace enabled=off,one_line=off
    optimizer_trace_features    greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=on
    optimizer_trace_limit   1
    optimizer_trace_max_mem_size    1048576
    optimizer_trace_offset  -1
    parser_max_mem_size 18446744073709551615
    password_history    0
    password_require_current    OFF
    password_reuse_interval 0
    performance_schema  OFF
    performance_schema_accounts_size    0
    performance_schema_digests_size 0
    performance_schema_error_size   0
    performance_schema_events_stages_history_long_size  0
    performance_schema_events_stages_history_size   0
    performance_schema_events_statements_history_long_size  0
    performance_schema_events_statements_history_size   0
    performance_schema_events_transactions_history_long_size    0
    performance_schema_events_transactions_history_size 0
    performance_schema_events_waits_history_long_size   0
    performance_schema_events_waits_history_size    0
    performance_schema_hosts_size   0
    performance_schema_max_cond_classes 0
    performance_schema_max_cond_instances   0
    performance_schema_max_digest_length    0
    performance_schema_max_digest_sample_age    60
    performance_schema_max_file_classes 0
    performance_schema_max_file_handles 0
    performance_schema_max_file_instances   0
    performance_schema_max_index_stat   0
    performance_schema_max_memory_classes   0
    performance_schema_max_metadata_locks   0
    performance_schema_max_mutex_classes    0
    performance_schema_max_mutex_instances  0
    performance_schema_max_prepared_statements_instances    0
    performance_schema_max_program_instances    0
    performance_schema_max_rwlock_classes   0
    performance_schema_max_rwlock_instances 0
    performance_schema_max_socket_classes   0
    performance_schema_max_socket_instances 0
    performance_schema_max_sql_text_length  0
    performance_schema_max_stage_classes    0
    performance_schema_max_statement_classes    0
    performance_schema_max_statement_stack  0
    performance_schema_max_table_handles    0
    performance_schema_max_table_instances  0
    performance_schema_max_table_lock_stat  0
    performance_schema_max_thread_classes   0
    performance_schema_max_thread_instances 0
    performance_schema_session_connect_attrs_size   0
    performance_schema_setup_actors_size    0
    performance_schema_setup_objects_size   0
    performance_schema_users_size   0
    persist_only_admin_x509_subject 
    persisted_globals_load  OFF
    preload_buffer_size 32768
    profiling   OFF
    profiling_history_size  15
    protocol_version    10
    query_alloc_block_size  8192
    query_prealloc_size 8192
    range_alloc_block_size  4096
    range_optimizer_max_mem_size    8388608
    rbr_exec_mode   STRICT
    read_buffer_size    262144
    read_only   OFF
    read_rnd_buffer_size    524288
    regexp_stack_limit  8000000
    regexp_time_limit   32
    relay_log_info_file relay-log.info
    relay_log_info_repository   TABLE
    relay_log_purge ON
    relay_log_recovery  ON
    relay_log_space_limit   0
    report_host 
    report_password 
    report_port 3306
    report_user 
    require_secure_transport    OFF
    rpl_read_size   8192
    rpl_stop_slave_timeout  31536000
    schema_definition_cache 256
    secure_file_priv    /tmp/
    server_id   1952235274
    server_id_bits  32
    server_uuid e48cd9eb-9e7f-11e6-9c68-0617407abcd3
    session_track_gtids OFF
    session_track_schema    ON
    session_track_state_change  OFF
    session_track_system_variables  time_zone,autocommit,character_set_client,character_set_results,character_set_connection
    session_track_transaction_info  OFF
    show_create_table_verbosity OFF
    show_old_temporals  OFF
    skip_external_locking   ON
    skip_name_resolve   OFF
    skip_networking OFF
    skip_show_database  OFF
    slave_allow_batching    OFF
    slave_checkpoint_group  512
    slave_checkpoint_period 300
    slave_compressed_protocol   OFF
    slave_exec_mode IDEMPOTENT
    slave_load_tmpdir   /tmp
    slave_max_allowed_packet    1073741824
    slave_net_timeout   60
    slave_parallel_type DATABASE
    slave_parallel_workers  0
    slave_pending_jobs_size_max 134217728
    slave_preserve_commit_order OFF
    slave_rows_search_algorithms    INDEX_SCAN,HASH_SCAN
    slave_skip_errors   OFF
    slave_sql_verify_checksum   ON
    slave_transaction_retries   10
    slave_type_conversions  
    slow_launch_time    2
    slow_query_log  OFF
    slow_query_log_file /rdsdbdata/log/slowquery/mysql-slowquery.log
    socket  /tmp/mysql.sock
    sort_buffer_size    262144
    sql_auto_is_null    OFF
    sql_big_selects ON
    sql_buffer_result   OFF
    sql_log_off OFF
    sql_mode    NO_ENGINE_SUBSTITUTION
    sql_notes   ON
    sql_quote_show_create   ON
    sql_require_primary_key OFF
    sql_safe_updates    OFF
    sql_select_limit    18446744073709551615
    sql_slave_skip_counter  0
    sql_warnings    OFF
    stored_program_cache    256
    stored_program_definition_cache 256
    super_read_only OFF
    sync_binlog 1
    sync_master_info    10000
    sync_relay_log  10000
    sync_relay_log_info 10000
    system_time_zone    UTC
    table_definition_cache  2000
    table_open_cache    4000
    table_open_cache_instances  16
    tablespace_definition_cache 256
    temptable_max_ram   1073741824
    thread_cache_size   9
    thread_handling one-thread-per-connection
    thread_stack    262144
    time_zone   UTC
    tls_version TLSv1,TLSv1.1,TLSv1.2
    tmp_table_size  16777216
    tmpdir  /rdsdbdata/tmp
    transaction_alloc_block_size    8192
    transaction_isolation   REPEATABLE-READ
    transaction_prealloc_size   4096
    transaction_read_only   OFF
    transaction_write_set_extraction    XXHASH64
    unique_checks   ON
    updatable_views_with_limit  YES
    version 8.0.15
    version_comment Source distribution
    version_compile_machine x86_64
    version_compile_os  Linux
    version_compile_zlib    1.2.11
    wait_timeout    28800
    windowing_use_high_precision    ON

Извлечение ШОУ ПРОЦЕССЛИСТА с проблемами c запросов: enter image description here

SHOW CREATE TABLE заданий:

CREATE TABLE `jobs` (
  `id` binary(36) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
  `status` tinytext CHARACTER SET latin1 COLLATE latin1_swedish_ci,
  `url` text,
  `host` text CHARACTER SET latin1 COLLATE latin1_swedish_ci,
  `hash` binary(40) DEFAULT NULL,
  `selectors` json DEFAULT NULL,
  `options` json DEFAULT NULL,
  `retries` int(11) DEFAULT NULL,
  `steelMode` tinyint(1) DEFAULT NULL,
  `jsRendering` tinyint(1) DEFAULT NULL,
  `createdDate` datetime DEFAULT NULL,
  `executionStartedDate` datetime DEFAULT NULL,
  `finishedDate` datetime DEFAULT NULL,
  `executionDurationMs` int(11) DEFAULT NULL,
  `totalDurationMs` int(11) DEFAULT NULL,
  `apiRequestId` binary(36) DEFAULT NULL,
  `errorCode` text,
  `errorContent` text CHARACTER SET latin1 COLLATE latin1_swedish_ci,
  `expiryDate` datetime DEFAULT NULL,
  `inputType` tinytext,
  PRIMARY KEY (`id`),
  KEY `url` (`url`(80)),
  KEY `createdDate` (`createdDate`),
  KEY `executionStartedDate` (`executionStartedDate`),
  KEY `finishedDate` (`finishedDate`),
  KEY `executionDurationMs` (`executionDurationMs`),
  KEY `totalDurationMs` (`totalDurationMs`),
  KEY `apiRequestId` (`apiRequestId`),
  KEY `status` (`status`(10)),
  KEY `retries` (`retries`),
  KEY `host` (`host`(50)),
  KEY `steelMode` (`steelMode`),
  KEY `hash` (`hash`),
  KEY `expiryDate` (`expiryDate`),
  KEY `inputType` (`inputType`(8))
) ENGINE=InnoDB DEFAULT CHARSET=latin1

1 Ответ

0 голосов
/ 29 марта 2020

Имея доступные данные, опубликованные на сегодняшний день,

Для вашего запроса, давайте sql = SELECT * FROM jobs WHERE hash = "${hash}" AND (expiryDate = -1 OR expiryDate > "${moment().format('YYYY-MM-DD HH:mm:ss')}") ORDER BY createdDate DESC LIMIT ${limit};

Наблюдения, A) будет $ {hash} тип данных BINARY (40)? чтобы не тратить время на преобразования типов данных для сопоставления

B) сделайте момент () детерминировать c, используя $ mynow datetime = NOW (), вместо того, чтобы переходить к ОС в каждой строке для текущего момента (), переформатированного д / т .

C) в 8.0.15 вы можете создать индекс как DES C с ADD KEY к таблице заданий KEY jobs_createdDate_desc (createDate DESC), чтобы избежать сортировки файлов в EXPLAIN

D) Использование SELECT * означает, что в этом случае 38 выбранных строк должны были go через длину строки AVG * 38 = выбранный размер во временную память. Было бы разумно ВЫБРАТЬ только столбцы, необходимые для обработки?

С 4 типами данных text и 2 json возможно, что некоторые данные будут храниться «вне основной страницы» в вашей таблице заданий innodb, составляя минимум Для чтения pu sh во временное хранилище требуется 2 чтения, может быть намного больше в зависимости от даты последнего АНАЛИЗА или ОПТИМИЗАЦИИ заданий.

Пожалуйста, поделитесь результатами findfragtables. sql и find-избыточных индексов . sql, чтобы мы могли получить представление о текущем состоянии ваших таблиц ПЕРЕД выполнением ANALYZE или OPTIMIZE.

E) db.t2.micro имеет 1 ЦП и 1 ГБ ОЗУ на https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.DBInstanceClass.html. примерно на 1/3 от верхней части документа.

Если это так, нам нужно сократить innodb_buffer_pool_size до 512M.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...