1

Process 3 Million rows data for every 5 minutes.

Data flow: LoadData from network to tmp table. Do some kind of group up and save to ~10 different table. Max 7 session running for saving data to different table at the same time.

What I tired.

  1. Create 100GB memory disk with /etc/fstab. [tmpfs /mnt/ramDisk tmpfs size=100G 0 0] and link to my database dir. Makes 30% faster.
  2. Create 50GB memory disk with '/etc/fstab', using for tmpdir.that makes db 15% faster.
  3. Each table may have 100M rows, Insert 1M rows for every 5min. I tried Innodb. seems one insert never ends. so I use MYISAM for All table. normally finish in 30 seconds.
  4. For Mysql memory engine is fixed length, I have some varchar(256) column, so I use MYISAM table in memory disk. use only 1/4 memory space compare to memory engine.
  5. Mysql config
    • datadir=/data/MySQL
    • tmpdir = /mnt/sqlTmp
    • socket=/var/lib/mysql/mysql.sock
    • symbolic-links=0
    • log-error=/var/log/mysqld.log
    • pid-file=/var/run/mysqld/mysqld.pid
    • tmp_table_size=20G
    • max_heap_table_size=20G
    • max_connections = 20
    • key_buffer_size = 1G
    • sort_buffer_size = 2M
    • sql-mode = "NO_ZERO_IN_DATE"
    • secure-file-priv=""
    • innodb_buffer_pool_size = 1M
    • innodb_max_undo_log_size = 1M
    • innodb_log_file_size = 1M
    • innodb_flush_log_at_trx_commit = 0
    • character-set-client-handshake = FALSE
    • character-set-server = latin1
    • collation-server = latin1_bin
  6. CPU:E5-2620 2.1GHz * 32 Core RAM:164GB Disk:Raid10 10TB Mysql 5.7.26
  7. Show Processlist
    • User sleep SET @null = SLEEP(2)
    • Opening tables SET @ret = sys_exec(...
    • Creating sort index INSERT t_sav_day_hst(...
    • Creating sort index INSERT t_sav_day_uri(...
    • User sleep SET @null = SLEEP(2)
    • executing LOAD DATA INFILE ...
  8. There are still space in Memory, not even used as cache. Checked with htop.
  9. I put everything in memory,so there is no Disk I/O traffic. I checked with glances.
  10. There won't be table lock during process, I schedule it well.
  11. Most sql is insert on duplicate 1M data to table which has 40M row.

My question. I run max 7 sql query at same time. but if I run less query at same time. every query runs faster. what is the bottleneck. how could I make it run faster? ( All table in memory, mysql tmpdir in memory, no table lock)

Some more info. Data flow: 1. Load Data from formatted text file to 'Temp' table. as ETL process. 2. Group by temp table and save to different 'Staging' table with IODKU. 3. Update Id to temp table from staging table.Due to I record count. so I use IODKU instead of Insert ignore.

Staging table.

   CREATE TABLE `t_sav_day_uri` (
  `_utDay` smallint(5) unsigned NOT NULL,
  `_uid` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `_md5` binary(16) NOT NULL,  # MD5 of a URI
  `_uriTc` varchar(255) NOT NULL,
  `_uriTail` varchar(512) NOT NULL,
  `_did` int(10) unsigned NOT NULL,
  `_hid` int(10) unsigned NOT NULL,
  `_attrUri` tinyint(3) unsigned NOT NULL,
  `_tfcTot` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `_tfcSlfCln` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `_tfcOthCln` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `_tfcEmlCln` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `_tfcHtpCln` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `_tfcHtpSpm` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `_tfcMltCln` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `_tfcMltSpm` mediumint(8) unsigned NOT NULL DEFAULT '0',
  `_seeIdyFst` smallint(3) unsigned NOT NULL DEFAULT '0',
  `_seeIdyLst` smallint(3) unsigned NOT NULL DEFAULT '0',
  `_seeSlt` smallint(5) unsigned NOT NULL DEFAULT '0',
  `_evl` tinyint(3) NOT NULL DEFAULT '0',
  PRIMARY KEY (`_utDay`,`_uid`),
  UNIQUE KEY `iu_sdu_md5` (`_utDay`,`_md5`) USING BTREE,
  KEY `ix_sdu_hid` (`_utDay`,`_hid`) USING BTREE,
  KEY `ix_sdu_uid` (`_utDay`,`_did`) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY RANGE (_utDay) # Divide by day.
(PARTITION p18015 VALUES LESS THAN (18016) ENGINE = MyISAM),
(PARTITION p18016 VALUES LESS THAN (18017) ENGINE = MyISAM) */

Insert to Staging table from temp table.

INSERT t_sav_day_uri(_utDay, _md5, _uriTc, _uriTail, _did, _hid, _attrUri, _tfcTot, _tfcSlfCln, _tfcOthCln, _tfcEmlCln
                    , _tfcHtpCln, _tfcHtpSpm, _tfcMltCln, _tfcMltSpm, _seeSlt, _seeIdyFst, _seeIdyLst)
            SELECT utDay_,_md5, LEFT(ANY_VALUE(_uriTc), 255), LEFT(ANY_VALUE(_uriTail), 255)
              , ANY_VALUE(_did), ANY_VALUE(_hid), ANY_VALUE(_attrUri) AS _attrUri   
              , SUM(1) AS _tfcTot, SUM(_attrSig & 1 = 0 ) AS _tfcSlfCln, SUM(_attrSig & 32 = 0 ) AS _tfcOthCln, SUM(_attrSig & 33 = 0 ) AS _tfcEmlCln
              , SUM(_attrUri & 8+16 > 0 AND _attrSig & 1 = 0) AS _tfcHtpCln , SUM(_attrUri & 8+16 > 0 AND _attrSig & 1 > 0) AS _tfcHtpSpm # Http(s)
              , SUM(_attrUri & 32 > 0   AND _attrSig & 1 = 0) AS _tfcMltCln , SUM(_attrUri & 32 > 0   AND _attrSig & 1 > 0) AS _tfcMltSpm # MailTo
              , 1, utIdy_, utIdy_
            FROM t_ipt3_uri
            GROUP BY _md5
            ON DUPLICATE KEY UPDATE 
                t_sav_day_uri._tfcTot    = t_sav_day_uri._tfcTot    + VALUES(_tfcTot)   , t_sav_day_uri._tfcSlfCln = t_sav_day_uri._tfcSlfCln + VALUES(_tfcSlfCln)
              , t_sav_day_uri._tfcOthCln = t_sav_day_uri._tfcOthCln + VALUES(_tfcOthCln), t_sav_day_uri._tfcEmlCln = t_sav_day_uri._tfcEmlCln + VALUES(_tfcEmlCln)
              , t_sav_day_uri._tfcHtpCln = t_sav_day_uri._tfcHtpCln + VALUES(_tfcHtpCln), t_sav_day_uri._tfcHtpSpm = t_sav_day_uri._tfcHtpSpm + VALUES(_tfcHtpSpm)
              , t_sav_day_uri._tfcMltCln = t_sav_day_uri._tfcMltCln + VALUES(_tfcMltCln), t_sav_day_uri._tfcMltSpm = t_sav_day_uri._tfcMltSpm + VALUES(_tfcMltSpm)
              , t_sav_day_uri._seeIdyFst = IF(t_sav_day_uri._seeIdyFst = 0, VALUES(_seeIdyFst), t_sav_day_uri._seeIdyFst)
              , t_sav_day_uri._seeSlt    = t_sav_day_uri._seeSlt + VALUES(_seeSlt)
              , t_sav_day_uri._seeIdyLst = VALUES(_seeIdyLst);

Update ID to temp table with Staging table.

UPDATE t_ipt3_uri AS A INNER JOIN t_sav_day_uri AS B ON B._utDay = utDay_ AND B._md5 = A._md5 SET A._uid = B._uid;

Show global variables

Aborted_clients 2
Aborted_connects    0
Binlog_cache_disk_use   0
Binlog_cache_use    0
Binlog_stmt_cache_disk_use  0
Binlog_stmt_cache_use   0
Bytes_received  2791677
Bytes_sent  27106941
Com_admin_commands  2073
Com_assign_to_keycache  0
Com_alter_db    0
Com_alter_db_upgrade    0
Com_alter_event 0
Com_alter_function  0
Com_alter_instance  0
Com_alter_procedure 0
Com_alter_server    0
Com_alter_table 56
Com_alter_tablespace    0
Com_alter_user  0
Com_analyze 0
Com_begin   0
Com_binlog  0
Com_call_procedure  18889
Com_change_db   39
Com_change_master   0
Com_change_repl_filter  0
Com_check   0
Com_checksum    0
Com_commit  3
Com_create_db   0
Com_create_event    0
Com_create_function 0
Com_create_index    0
Com_create_procedure    15
Com_create_server   0
Com_create_table    0
Com_create_trigger  0
Com_create_udf  0
Com_create_user 0
Com_create_view 0
Com_dealloc_sql 56
Com_delete  5
Com_delete_multi    0
Com_do  0
Com_drop_db 0
Com_drop_event  0
Com_drop_function   0
Com_drop_index  0
Com_drop_procedure  15
Com_drop_server 0
Com_drop_table  0
Com_drop_trigger    0
Com_drop_user   0
Com_drop_view   0
Com_empty_query 0
Com_execute_sql 56
Com_explain_other   0
Com_flush   0
Com_get_diagnostics 0
Com_grant   0
Com_ha_close    0
Com_ha_open 0
Com_ha_read 0
Com_help    0
Com_insert  11088
Com_insert_select   6548
Com_install_plugin  0
Com_kill    1
Com_load    1774
Com_lock_tables 0
Com_optimize    0
Com_preload_keys    0
Com_prepare_sql 56
Com_purge   0
Com_purge_before_date   0
Com_release_savepoint   0
Com_rename_table    254
Com_rename_user 0
Com_truncate    3584
Com_uninstall_plugin    0
Com_unlock_tables   0
Com_update  18131
Com_update_multi    4539
Com_xa_commit   0
Com_xa_end  0
Com_xa_prepare  0
Com_xa_recover  0
Com_xa_rollback 0
Com_xa_start    0
Com_stmt_reprepare  0
Connection_errors_accept    0
Connection_errors_internal  0
Connection_errors_max_connections   0
Connection_errors_peer_address  0
Connection_errors_select    0
Connection_errors_tcpwrap   0
Connections 4953
Created_tmp_disk_tables 30226
Created_tmp_files   12633
Created_tmp_tables  41280
Delayed_errors  0
Delayed_insert_threads  0
Delayed_writes  0
Flush_commands  1
Handler_commit  6
Handler_delete  26
Handler_discover    0
Handler_external_lock   387085
Handler_mrr_init    0
Handler_prepare 0
Handler_read_first  31240
Handler_read_key    6192720949
Handler_read_last   81
Handler_read_next   2874072
Handler_read_prev   23328
Handler_read_rnd    971388179
Handler_read_rnd_next   10165355981
Handler_rollback    0
Handler_savepoint   0
Handler_savepoint_rollback  0
Handler_update  4704620682
Handler_write   3945992025
Innodb_buffer_pool_dump_status  Dumping of buffer pool not started
Innodb_buffer_pool_load_status  Buffer pool(s) load completed at 190502  7:20:33
Innodb_buffer_pool_resize_status    
Innodb_buffer_pool_pages_data   256
Innodb_buffer_pool_bytes_data   4194304
Innodb_buffer_pool_pages_dirty  0
Innodb_buffer_pool_bytes_dirty  0
Innodb_buffer_pool_pages_flushed    4870
Innodb_buffer_pool_pages_free   63
Innodb_buffer_pool_pages_misc   0
Innodb_buffer_pool_pages_total  319
Innodb_buffer_pool_read_ahead_rnd   0
Innodb_buffer_pool_read_ahead   0
Innodb_buffer_pool_read_ahead_evicted   0
Innodb_buffer_pool_read_requests    698107
Innodb_buffer_pool_reads    333
Innodb_buffer_pool_wait_free    0
Innodb_buffer_pool_write_requests   605312
Innodb_data_fsyncs  7
Innodb_data_pending_fsyncs  0
Innodb_data_pending_reads   0
Innodb_data_pending_writes  0
Innodb_data_read    5526016
Innodb_data_reads   364
Innodb_data_writes  4887
Innodb_data_written 79824896
Innodb_dblwr_pages_written  2
Innodb_dblwr_writes 1
Innodb_log_waits    0
Innodb_log_write_requests   0
Innodb_log_writes   2
Innodb_os_log_fsyncs    4
Innodb_os_log_pending_fsyncs    0
Innodb_os_log_pending_writes    0
Innodb_os_log_written   1024
Innodb_page_size    16384
Innodb_pages_created    114
Innodb_pages_read   332
Innodb_pages_written    4870
Innodb_row_lock_current_waits   0
Innodb_row_lock_time    0
Innodb_row_lock_time_avg    0
Innodb_row_lock_time_max    0
Innodb_row_lock_waits   0
Innodb_rows_deleted 0
Innodb_rows_inserted    32571
Innodb_rows_read    32382
Innodb_rows_updated 0
Innodb_num_open_files   23
Innodb_truncated_status_writes  0
Innodb_available_undo_logs  128
Key_blocks_not_flushed  67119
Key_blocks_unused   0
Key_blocks_used 857368
Key_read_requests   38701216831
Key_reads   696303355
Key_write_requests  4199909370
Key_writes  499809131
Locked_connects 0
Max_execution_time_exceeded 0
Max_execution_time_set  0
Max_execution_time_set_failed   0
Max_used_connections    14
Max_used_connections_time   2019-05-02 18:14:57
Not_flushed_delayed_rows    0
Ongoing_anonymous_transaction_count 0
Open_files  1255
Open_streams    0
Open_table_definitions  514
Open_tables 1378
Opened_files    81694
Opened_table_definitions    8281
Opened_tables   13980
Performance_schema_accounts_lost    0
Performance_schema_cond_classes_lost    0
Performance_schema_cond_instances_lost  0
Performance_schema_digest_lost  0
Performance_schema_socket_instances_lost    0
Performance_schema_stage_classes_lost   0
Performance_schema_statement_classes_lost   0
Performance_schema_table_handles_lost   0
Performance_schema_table_instances_lost 0
Performance_schema_table_lock_stat_lost 0
Performance_schema_thread_classes_lost  0
Performance_schema_thread_instances_lost    0
Performance_schema_users_lost   0
Prepared_stmt_count 0
Qcache_free_blocks  1
Qcache_free_memory  1031832
Qcache_hits 0
Qcache_inserts  0
Qcache_lowmem_prunes    0
Qcache_not_cached   7177
Qcache_queries_in_cache 0
Qcache_total_blocks 1
Queries 738581212
Questions   16826
Select_full_join    397
Select_full_range_join  0
Select_range    0
Select_range_check  0
Select_scan 47338
Slave_open_temp_tables  0
Slow_launch_threads 0
Slow_queries    0
Sort_merge_passes   9874
Sort_range  0
Sort_rows   966371535
Sort_scan   7333
Table_locks_immediate   181314
Table_locks_waited  49
Table_open_cache_hits   203447
Table_open_cache_misses 13980
Table_open_cache_overflows  3287
Tc_log_max_pages_used   0
Tc_log_page_size    0
Tc_log_page_waits   0
Threads_cached  3
Threads_connected   9
Threads_created 272
Threads_running 8
Uptime  88667
Uptime_since_flush_status   88667

Show variables

auto_increment_increment    1
auto_increment_offset   1
autocommit  ON
automatic_sp_privileges ON
avoid_temporal_upgrade  OFF
back_log    54
basedir /usr/
big_tables  OFF
bind_address    *
binlog_cache_size   32768
binlog_checksum CRC32
binlog_direct_non_transactional_updates OFF
binlog_error_action ABORT_SERVER
binlog_format   ROW
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_row_image    FULL
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
character_set_client    utf8
character_set_connection    utf8
character_set_database  latin1
character_set_filesystem    binary
character_set_results   utf8
character_set_server    latin1
character_set_system    utf8
character_sets_dir  /usr/share/mysql/charsets/
check_proxy_users   OFF
collation_connection    utf8_general_ci
collation_database  latin1_bin
collation_server    latin1_bin
completion_type NO_CHAIN
concurrent_insert   AUTO
connect_timeout 10
core_file   OFF
datadir /data/mysql/
date_format %Y-%m-%d
datetime_format %Y-%m-%d %H:%i:%s
default_authentication_plugin   mysql_native_password
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
error_count 0
event_scheduler OFF
expire_logs_days    0
explicit_defaults_for_timestamp OFF
external_user   
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    /data/mysql/localhost.log
group_concat_max_len    1024
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    YES
have_statement_timeout  YES
have_symlink    DISABLED
host_cache_size 148
hostname    localhost.localdomain
identity    0
ignore_builtin_innodb   OFF
ignore_db_dirs  
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    1
innodb_buffer_pool_chunk_size   5242880
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    1
innodb_buffer_pool_load_abort   OFF
innodb_buffer_pool_load_at_startup  ON
innodb_buffer_pool_load_now OFF
innodb_buffer_pool_size 5242880
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_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    
innodb_deadlock_detect  ON
innodb_default_row_format   dynamic
innodb_disable_sort_file_cache  OFF
innodb_doublewrite  ON
innodb_fast_shutdown    1
innodb_file_format  Barracuda
innodb_file_format_check    ON
innodb_file_format_max  Barracuda
innodb_file_per_table   ON
innodb_fill_factor  100
innodb_flush_log_at_timeout 1
innodb_flush_log_at_trx_commit  0
innodb_flush_method 
innodb_flush_neighbors  1
innodb_flush_sync   ON
innodb_flushing_avg_loops   30
innodb_force_load_corrupted OFF
innodb_force_recovery   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_large_prefix ON
innodb_lock_wait_timeout    50
innodb_locks_unsafe_for_binlog  OFF
innodb_log_buffer_size  16777216
innodb_log_checksums    ON
innodb_log_compressed_pages ON
innodb_log_file_size    4194304
innodb_log_files_in_group   2
innodb_log_group_home_dir   ./
innodb_log_write_ahead_size 8192
innodb_lru_scan_depth   1024
innodb_max_dirty_pages_pct  75.000000
innodb_max_dirty_pages_pct_lwm  0.000000
innodb_max_purge_lag    0
innodb_max_purge_lag_delay  0
innodb_max_undo_log_size    10485760
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   2000
innodb_optimize_fulltext_only   OFF
innodb_page_cleaners    1
innodb_page_size    16384
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_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_sample_pages   8
innodb_stats_transient_sample_pages 8
innodb_status_output    OFF
innodb_status_output_locks  OFF
innodb_strict_mode  ON
innodb_support_xa   ON
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   10000
innodb_tmpdir   
innodb_undo_directory   ./
innodb_undo_log_truncate    OFF
innodb_undo_logs    128
innodb_undo_tablespaces 0
innodb_use_native_aio   ON
innodb_version  5.7.26
innodb_write_io_threads 4
insert_id   0
interactive_timeout 28800
internal_tmp_disk_storage_engine    InnoDB
join_buffer_size    262144
keep_files_on_create    OFF
key_buffer_size 1073741824
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
last_insert_id  0
lc_messages en_US
lc_messages_dir /usr/share/mysql/
lc_time_names   en_US
license GPL
local_infile    ON
lock_wait_timeout   31536000
locked_in_memory    OFF
log_bin OFF
log_bin_basename    
log_bin_index   
log_bin_trust_function_creators OFF
log_bin_use_v1_row_events   OFF
log_builtin_as_identified_by_password   OFF
log_error   /var/log/mysqld.log
log_error_verbosity 3
log_output  FILE
log_queries_not_using_indexes   OFF
log_slave_updates   OFF
log_slow_admin_statements   OFF
log_slow_slave_statements   OFF
log_statements_unsafe_for_binlog    ON
log_syslog  OFF
log_syslog_facility daemon
log_syslog_include_pid  ON
log_syslog_tag  
log_throttle_queries_not_using_indexes  0
log_timestamps  UTC
log_warnings    2
long_query_time 10.000000
low_priority_updates    OFF
lower_case_file_system  OFF
lower_case_table_names  0
master_info_repository  FILE
master_verify_checksum  OFF
max_allowed_packet  4194304
max_binlog_cache_size   18446744073709547520
max_binlog_size 1073741824
max_binlog_stmt_cache_size  18446744073709547520
max_connect_errors  100
max_connections 20
max_delayed_threads 20
max_digest_length   1024
max_error_count 64
max_execution_time  0
max_heap_table_size 21474836480
max_insert_delayed_threads  20
max_join_size   18446744073709551615
max_length_for_sort_data    1024
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_tmp_tables  32
max_user_connections    0
max_write_lock_count    18446744073709551615
metadata_locks_cache_size   1024
metadata_locks_hash_instances   8
min_examined_row_limit  0
multi_range_count   256
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
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
old_passwords   0
open_files_limit    5000
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
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    16384
optimizer_trace_offset  -1
parser_max_mem_size 18446744073709551615
performance_schema  ON
performance_schema_accounts_size    -1
performance_schema_digests_size 10000
performance_schema_events_stages_history_long_size  10000
performance_schema_events_stages_history_size   10
performance_schema_events_statements_history_long_size  10000
performance_schema_events_statements_history_size   10
performance_schema_events_transactions_history_long_size    10000
performance_schema_events_transactions_history_size 10
performance_schema_events_waits_history_long_size   10000
performance_schema_events_waits_history_size    10
performance_schema_hosts_size   -1
performance_schema_max_cond_classes 80
performance_schema_max_cond_instances   -1
performance_schema_max_digest_length    1024
performance_schema_max_file_classes 80
performance_schema_max_file_handles 32768
performance_schema_max_file_instances   -1
performance_schema_max_index_stat   -1
performance_schema_max_memory_classes   320
performance_schema_max_metadata_locks   -1
performance_schema_max_mutex_classes    210
performance_schema_max_mutex_instances  -1
performance_schema_max_prepared_statements_instances    -1
performance_schema_max_program_instances    -1
performance_schema_max_rwlock_classes   50
performance_schema_max_rwlock_instances -1
performance_schema_max_socket_classes   10
performance_schema_max_socket_instances -1
performance_schema_max_sql_text_length  1024
performance_schema_max_stage_classes    150
performance_schema_max_statement_classes    193
performance_schema_max_statement_stack  10
performance_schema_max_table_handles    -1
performance_schema_max_table_instances  -1
performance_schema_max_table_lock_stat  -1
performance_schema_max_thread_classes   50
performance_schema_max_thread_instances -1
preload_buffer_size 32768
profiling   OFF
profiling_history_size  15
protocol_version    10
proxy_user  
pseudo_slave_mode   OFF
pseudo_thread_id    4747
query_alloc_block_size  8192
query_cache_limit   1048576
query_cache_min_res_unit    4096
query_cache_size    1048576
query_cache_type    OFF
query_cache_wlock_invalidate    OFF
query_prealloc_size 8192
range_alloc_block_size  4096
range_optimizer_max_mem_size    8388608
rbr_exec_mode   STRICT
read_buffer_size    131072
read_only   OFF
read_rnd_buffer_size    262144
relay_log   
relay_log_basename  /data/mysql/localhost-relay-bin
relay_log_index /data/mysql/localhost-relay-bin.index
relay_log_info_file relay-log.info
relay_log_info_repository   FILE
relay_log_purge ON
relay_log_recovery  OFF
relay_log_space_limit   0
report_host 
report_password 
report_port 3306
report_user 
require_secure_transport    OFF
rpl_stop_slave_timeout  31536000
secure_auth ON
secure_file_priv    
server_id   0
server_id_bits  32
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
sha256_password_proxy_users OFF
show_compatibility_56   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
slow_launch_time    2
slow_query_log  OFF
slow_query_log_file /data/mysql/localhost-slow.log
socket  /var/lib/mysql/mysql.sock
sort_buffer_size    2097152
sql_auto_is_null    OFF
sql_big_selects ON
sql_buffer_result   OFF
sql_log_bin ON
sql_log_off OFF
sql_mode    NO_ZERO_IN_DATE
sql_notes   ON
sql_quote_show_create   ON
sql_safe_updates    ON
sql_select_limit    18446744073709551615
table_definition_cache  1400
table_open_cache    2000
table_open_cache_instances  16
thread_cache_size   8
thread_handling one-thread-per-connection
thread_stack    262144
time_format %H:%i:%s
time_zone   SYSTEM
timestamp   1556895579.021091
tls_version TLSv1,TLSv1.1
tmp_table_size  21474836480
tmpdir  /mnt/sqlTmp
transaction_alloc_block_size    8192
transaction_allow_batching  OFF
transaction_isolation   REPEATABLE-READ
transaction_prealloc_size   4096
transaction_read_only   OFF
transaction_write_set_extraction    OFF
tx_isolation    REPEATABLE-READ
tx_read_only    OFF
unique_checks   ON
updatable_views_with_limit  YES
version 5.7.26
version_comment MySQL Community Server (GPL)
version_compile_machine x86_64
version_compile_os  Linux
wait_timeout    28800
warning_count   0

migrated from stackoverflow.com May 2 at 19:54

This question came from our site for professional and enthusiast programmers.

  • 1
    So the queries, the SHOW CREATE TABLE {tablename} for the tables, and EXPLAIN {query}. With innodb_buffer_pool_size=1M its not surprising innodb times out. MyISAM is the wrong solution at it locks at the table level and you can't get concurrent inserts/updates (except in limited conditions). – danblack May 2 at 23:29
  • @danblack - unless the inserts are single-threaded, as in with LOAD DATA. Still, InnoDB has been clocked as faster than MEMORY or MyISAM in some high-speed ingestion scenarios. – Rick James May 3 at 4:31
0

For Mysql memory engine is fixed length

8.0 no longer converts VARCHAR to CHAR

Have you shrunken all the datatypes as much as practical?

Have you gotten rid of redundant/unnecessary indexes?

What steps are happening in the ETL process?

Is the ingestion single-threaded or multi-threaded? This has some tips on such.

Creating sort index

That seems strange for an INSERT; please provide more info.

Let's see SHOW GLOBAL STATUS; and SHOW VARIABLES; -- there may be some clues there.

You say a table has 100M rows and is loaded 1M at a time? What happens when gets 'full'? Do you purge old data? Or what?

Your innodb settings are unworkably tiny.

How many different MEMORY tables do you need at once? You have a lot of RAM, but the 20G limit may eat it up fast.

Is the IODKU running one row at a time? Or multiple rows? Or from a SELECT?

Big transactions in InnoDB

INSERT INTO .. SELECT ... ON DUPLICATE KEY ..

If the SELECT generates a million rows, then there are probably a large number of inserts and of updates. I know that a million updates (or even 100K updates) in a single transaction is rather slow. This is because of hanging onto the old row in order to recover just in case there is a crash. This is essentially unavoidable in InnoDB, but there may be a workaround...

If you do the IODKU 1K (or maybe 10K) rows at a time, each transaction is more manageable, and might run faster in spite of the overhead of looping. This discusses chunking of deletes, but most of it applies to updates.

Another tip on a big IODKU (chunked or not) is to sort the incoming data (via ORDER BY on the SELECT) so that the rows are fed to IODKU in PRIMARY KEY or UNIQUE order.

Oops, your table is MyISAM...

Big IODKU in MyISAM

The chunking (above) is probably not useful.

Table t_sav_day_uri will be locked for the entire million rows.

I see that you are using the MyISAM feature with the AI column second in the PK.

I assume _utDay has the same value for the entire million rows?

The UNIQUE key becomes the critical one. Because of the MD5() the tests and inserts into that index will be very random. I compute that each entry in that index will be 27 bytes, leading to an average of 26 rows per 1K index block (after allowing for BTree fragmentation). Those blocks are cached in the key_buffer, which has size 1GB. The first million index entries will take about 40MB in the key_buffer. But, after about 25M rows, thrashing will begin. It will be slight at first, but grow in intensity. Changing key_buffer_size to 4G would solve that. But there is still more. There are 3 other indexes that need caching in the key_buffer. The PK (with an AI) could survive with room for only one leaf node. I don't know the patterns of the other indexes. On the safe side,

key_buffer_size = 12G

(and adjust some other memory usage as needed)

Or, if you sort the SELECT, you could drop back to perhaps 8G. However the cost of the ORDER BY is a tradeoff to weigh.

What does SHOW TABLE STATUS show for that table?

Meanwhile, the data will either be thrashed or cached. If most of the IODKUs are INSERTs, then the caching of the data is not a big deal.

But if it is mostly updates,... A row might be 200 bytes. 100M rows would be 20GB. Every row to update would have to be read-modified-written. This happens in the OS, using its block size (4KB?). So, if there is upwards of 20GB (15 is probably sufficient) left over after MySQL, the OS, and anything else, then the data will be as efficient as is practical.

It gets messy if the length of a MyISAM row changes due to an update. I don't want to attempt analyzing it.

  • 1
    Thanks for you tips. Please see my edited post. 100 rows load 1M at a time. they have duplicate, and partitioned by day. I use memory disk which has max 100GB. IODKU run from a SELECT. – wa56 May 3 at 14:55
  • @wa56 - "100 rows load 1M at a time" -- Perhaps you mean "100 processes ..."? That many processes would stumble over each other; 32 might be a safer limit. – Rick James May 3 at 16:16
  • 1
    Sorry, I wanna say IODKU 1M rows to a table which has 100M rows. – wa56 May 3 at 16:54
  • @wa56 - more analysis added to my Answer. – Rick James May 3 at 23:29
0

Rate Per Second=RPS - Suggestions to consider for my.cnf [mysqld] section ALL are Dynamic Global Variables and with root can be SET var_name=value

key_age_threshold=7200  # from 300 seconds to reduce key_reads RPS of 7,853
key_cache_division_limit=50  # from 100 for Hot/Warm caching
key_cache_block_size=16384  # from 1024 to free more entries when aged out
read_rnd_buffer_size=131072  # from 256K to reduce handler_read_rnd_next RPS of 114,648
innodb_io_capacity=1500  # from 200 to allow higher IOPS
thread_cache_size=24  # from 8 to reduce threads_created overhead for 11 RPHour

Disclaimer: I am the content author of web site mentioned in my profile, Network profile and can provide additional suggestions and free Utility Scripts via contact information.

  • @wa56 Have any of the suggestions been implemented? Please post results, positive or negative. Thanks – Wilson Hauck May 17 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.