如何让 mysqld 使用超过 24.9% 的 CPU?

Jos*_*cey 6 mysql linux

我有一个运行在 RHEL 上的 Web 服务器,它运行着 Apache 和 MySQL。它有一个四核 3.2Ghz Xeon CPU 和 8 Gigs RAM 大多数时候,我们根本没有任何问题。

我们的 Web 应用程序是非常密集的数据库。当我们的使用量变得非常大时,MySQL 将使用 24.9% 的 CPU。大多数时候,它徘徊在 5% 以下。我推测它只使用了 CPU 的一个核心,并且它正在钉住那个核心,但 TOP 在 cpu 列中向我显示,即使使用率保持在 24.9%,mysqld 也会更改核心。当它这样做时,MySQL 在排队查询时会变得非常缓慢 是否有一些神奇的配置会告诉 mysql 在需要时使用更多的 cpu?此外,关于我的配置的任何其他建议都会有所帮助。

我们在这台服务器上运行两个应用程序。一个运行 Innodb 但没有得到太多使用(它已被另一个应用程序取代),一个运行 MyIsam 并得到大量使用。总的来说,如果这很重要的话,我们的整个 mysql 数据目录就像 13Gigs。

这是我的配置:

[root@ProductionLinux root]# cat /etc/my.cnf
[mysqld]
服务器 ID = 71
log-bin = /var/log/mysql/mysql-bin.log
binlog-do-db = 旧应用程序
binlog-do-db = 新应用程序
binlog-do-db = 支持
线程缓存大小 = 30
key_buffer_size = 256M
table_cache = 256
sort_buffer_size = 4M
read_buffer_size = 1M
跳过名称解析

innodb_data_home_dir = /usr/local/mysql/data/
innodb_data_file_path = InnoDB:100M:autoextend
设置变量 = innodb_buffer_pool_size=70M
设置变量 = innodb_additional_mem_pool_size=10M
设置变量 = max_connections=500
innodb_log_group_home_dir = /usr/local/mysql/data
innodb_log_arch_dir = /usr/local/mysql/data
设置变量 = innodb_log_file_size=20M
设置变量 = innodb_log_buffer_size=8M
innodb_flush_log_at_trx_commit = 1
日志查询不使用索引
日志错误= /var/log/mysql/mysql-error.log
mysql> 显示变量;
+---------------------------------+--------------- -------------------------------------------------- -------------+
| 变量名 | 价值 |
+---------------------------------+--------------- -------------------------------------------------- -------------+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
| automatic_sp_privileges | 开 |
| back_log | 50 |
| 基础 | /usr/local/mysql-standard-5.0.18-linux-x86_64-glibc23/ |
| binlog_cache_size | 32768 |
| 批量插入缓冲区大小| 8388608 |
| character_set_client | 拉丁语1 |
| 字符集连接| 拉丁语1 |
| 字符集数据库| 拉丁语1 |
| character_set_results | 拉丁语1 |
| character_set_server | 拉丁语1 |
| 字符集系统| utf8 |
| character_sets_dir | /usr/local/mysql-standard-5.0.18-linux-x86_64-glibc23/share/mysql/charsets/ |
| collat​​ion_connection | latin1_swedish_ci |
| collat​​ion_database | latin1_swedish_ci |
| collat​​ion_server | latin1_swedish_ci |
| 完成类型| 0 |
| concurrent_insert | 1 |
| 连接超时| 5 |
| 数据目录 | /usr/local/mysql/data/ |
| 日期格式| %Y-%m-%d |
| 日期时间格式| %Y-%m-%d %H:%i:%s |
| default_week_format | 0 |
| delay_key_write | 开 |
| delay_insert_limit | 100 |
| delay_insert_timeout | 300 |
| delay_queue_size | 1000 |
| div_precision_increment | 4 |
| engine_condition_pushdown | 关闭 |
| expire_logs_days | 0 |
| 冲洗 | 关闭 |
| 冲洗时间 | 0 | |
| ft_max_word_len | 84 |
| ft_min_word_len | 4 |
| ft_query_expansion_limit | 20 |
| ft_stopword_file | (内置) |
| group_concat_max_len | 1024 |
| have_archive | 是 |
| have_bdb | 否 |
| have_blackhole_engine | 否 |
| have_compress | 是 |
| have_crypt | 是 |
| have_csv | 否 |
| have_example_engine | 否 |
| have_federated_engine | 否 |
| have_geometry | 是 |
| have_innodb | 是 |
| have_isam | 否 |
| have_ndbcluster | 否 |
| have_openssl | 否 |
| have_query_cache | 是 |
| have_raid | 否 |
| have_rtree_keys | 是 |
| have_symlink | 是 |
| init_connect | |
| init_file | |
| init_slave | |
| innodb_additional_mem_pool_size | 10485760 |
| innodb_autoextend_increment | 8 |
| innodb_buffer_pool_awe_mem_mb | 0 |
| innodb_buffer_pool_size | 73400320 |
| innodb_checksums | 开 |
| innodb_commit_concurrency | 0 |
| innodb_concurrency_tickets | 500 |
| innodb_data_file_path | InnoDB:100M:autoextend |
| innodb_data_home_dir | /usr/local/mysql/data/ |
| innodb_doublewrite | 开 |
| innodb_fast_shutdown | 1 |
| innodb_file_io_threads | 4 |
| innodb_file_per_table | 关闭 |
| innodb_flush_log_at_trx_commit | 1 |
| innodb_flush_method | |
| innodb_force_recovery | 0 |
| innodb_lock_wait_timeout | 50 |
| innodb_locks_unsafe_for_binlog | 关闭 |
| innodb_log_arch_dir | /usr/local/mysql/data |
| innodb_log_archive | 关闭 |
| innodb_log_buffer_size | 8388608 |
| innodb_log_file_size | 20971520 |
| innodb_log_files_in_group | 2 |
| innodb_log_group_home_dir | /usr/local/mysql/data |
| innodb_max_dirty_pages_pct | 90 |
| innodb_max_purge_lag | 0 |
| innodb_mirrored_log_groups | 1 |
| innodb_open_files | 300 |
| innodb_support_xa | 开 |
| innodb_sync_spin_loops | 20 |
| innodb_table_locks | 开 |
| innodb_thread_concurrency | 20 |
| innodb_thread_sleep_delay | 10000 |
| Interactive_timeout | 28800 |
| join_buffer_size | 131072 |
| key_buffer_size | 268435456 |
| key_cache_age_threshold | 300 |
| key_cache_block_size | 1024 |
| key_cache_division_limit | 100 |
| 语言 | /usr/local/mysql-standard-5.0.18-linux-x86_64-glibc23/share/mysql/english/ |
| large_files_support | 开 |
| large_page_size | 0 |
| large_pages | 关闭 |
| 许可证 | GPL |
| local_infile | 开 |
| 锁定内存| 关闭 |
| 日志 | 关闭 |
| log_bin | 开 |
| log_bin_trust_function_creators | 关闭 |
| 日志错误| /var/log/mysql/mysql-error.log |
| log_slave_updates | 关闭 |
| log_slow_queries | 关闭 |
| log_warnings | 1 |
| long_query_time | 10 |
| low_priority_updates | 关闭 |
| lower_case_file_system | 关闭 |
| lower_case_table_names | 0 |
| max_allowed_pa​​cket | 1048576 |
| max_binlog_cache_size | 18446744073709551615 |
| max_binlog_size | 1073741824 |
| max_connect_errors | 10 |
| max_connections | 500 |
| max_delayed_threads | 20 |
| max_error_count | 64 |
| max_heap_table_size | 16777216 |
| max_insert_delayed_threads | 20 |
| max_join_size | 18446744073709551615 |
| max_length_for_sort_data | 1024 |
| 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 |
| multi_range_count | 第256话
| myisam_data_pointer_size | 6 |
| myisam_max_sort_file_size | 9223372036854775807 |
| myisam_recover_options | 关闭 |
| myisam_repair_threads | 1 |
| myisam_sort_buffer_size | 8388608 |
| myisam_stats_method | nulls_unequal |
| net_buffer_length | 16384 |
| net_read_timeout | 30 |
| net_retry_count | 10 |
| net_write_timeout | 60 |
| 新 | 关闭 |
| old_passwords | 关闭 |
| open_files_limit | 2510 |
| optimizer_prune_level | 1 |
| optimizer_search_depth | 62 |
| pid_file | /usr/local/mysql/data/ProductionLinux.pid |
| 港口| 3306 |
| preload_buffer_size | 32768 |
| 协议版本| 10 |
| query_alloc_block_size | 8192 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 0 |
| query_cache_type | 开 |
| query_cache_wlock_invalidate | 关闭 |
| query_prealloc_size | 8192 |
| range_alloc_block_size | 2048 |
| read_buffer_size | 1044480 |
| 只读 | 关闭 |
| read_rnd_buffer_size | 262144 |
| relay_log_purge | 开 |
| 中继日志空间限制| 0 |
| rpl_recovery_rank | 0 |
| 安全认证| 关闭 |
| server_id | 71 |
| skip_external_locking | 开 |
| 跳过网络| 关闭 |
| skip_show_database | 关闭 |
| slave_compressed_protocol | 关闭 |
| slave_load_tmpdir | /tmp/ |
| slave_net_timeout | 3600 |
| slave_skip_errors | 关闭 |
| slave_transaction_retries | 10 |
| slow_launch_time | 2 |
| 插座 | /tmp/mysql.sock |
| sort_buffer_size | 4194296 |
| sql_mode | |
| sql_notes | 开 |
| sql_warnings | 开 |
| storage_engine | 我的ISAM |
| sync_binlog | 0 |
| sync_frm | 开 |
| sync_replication | 0 |
| sync_replication_slave_id | 0 |
| sync_replication_timeout | 10 |
| system_time_zone | 科技委 |
| table_cache | 第256话
| table_lock_wait_timeout | 50 |
| 表类型 | 我的ISAM |
| thread_cache_size | 30 |
| 线程堆栈| 262144 |
| 时间格式| %H:%i:%s |
| 时区 | 系统 |
| timed_mutexes | 关闭 |
| tmp_table_size | 33554432 |
| tmpdir | |
| transaction_alloc_block_size | 8192 |
| transaction_prealloc_size | 4096 |
| tx_isolation | 可重复阅读 |
| updatetable_views_with_limit | 是 |
| 版本| 5.0.18-标准日志|
| version_comment | MySQL 社区版 - 标准 (GPL) |
| version_compile_machine | x86_64 |
| version_compile_os | 未知-linux-gnu |
| 等待超时| 28800 |
+---------------------------------+--------------- -------------------------------------------------- -------------+
210 行(0.00 秒)

Jav*_*ier 6

这似乎是更新单个 MyISAM 表的明显效果。整个表在写入期间被锁定。

要么使用更多的表,要么将那些有大量写入的表切换到 InnoDB。由于表引擎的选择是针对每个表,而不是针对每个数据库,因此您可以选择最适合每个表的引擎。

请记住,MyISAM 对于大多数读取的表来说速度很快,而 InnoDB 对于几乎所有其他表都是最好的。

此外,如果您有一个包含如此多写入的单个表,请考虑更改您的架构。检查队列管理器(将这些更新发送到非交互式任务),或仅附加引擎(对于日志或存档,如果这是您正在做的,则很快),或用于紧张工作的不同类型的服务器(例如 in -memory DB 如果您在将最终结果写入更持久的存储之前进行了大量临时处理)


Ked*_*are 1

因为您使用的是旧版本的 MySQL,它不能很好地扩展多核。

尝试升级:)