【发布时间】:2015-05-26 18:33:17
【问题描述】:
我们在 MySQL 数据库中有 4 个相当大的表。它们大约为 50、35、6 和 5 Gb,其他表没有那么大。这些表充满了分析数据,每 10 分钟由 cron 任务附加。随着时间的推移,这些表将继续增长。
这是数据表的架构
CREATE TABLE `instpld` (
`id` int(20) NOT NULL AUTO_INCREMENT,
`insID` varchar(100) NOT NULL,
`dbID` int(10) NOT NULL,
`type` varchar(1) NOT NULL,
`timestamp` int(11) NOT NULL,
`count` text NOT NULL,
`comment_count` int(10) NOT NULL,
PRIMARY KEY (`id`),
KEY `insID` (`insID`(50)),
KEY `dbID` (`dbID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
我知道字段类型可能会更好。问题是什么更好 - 在表上添加一些分区或将所有内容切换到 MongoDB,因为它更快?
我正在寻找每个选项的优缺点。
# Misc Settings
# -------------
datadir=/var/lib/mysql
tmpdir=/var/lib/mysqltmp
socket=/var/lib/mysql/mysql.sock
#skip-locking
skip-name-resolve
#table_cache=2048
thread_cache_size=16
back_log=100
max_connect_errors=10000
open-files-limit=20000
interactive_timeout=3600
wait_timeout=600
#max_connections=200
# Added to prevent DNS lookups from causing performance issues
skip-name-resolve
# Set this to change the way MySQL handles validation, data
# conversion, etc. Be careful with this setting as it can
# cause unexpected results and horribly break some applications!
# Note, too, that it can be set per-session and can be hard set
# in stored procedures.
#sql_mode=NO_ENGINE_SUBSTITUTION
# Slow Query Log Settings
# -----------------------
#log-slow-queries=/var/lib/mysqllogs/slow-log
#long_query_time=2
#log-queries-not-using-indexes
# Global, Non Engine-Specific Buffers
# -----------------------------------
max_allowed_packet=16M
tmp_table_size=64M
max_heap_table_size=64M
# Generally, it is unwise to set the query cache to be
# larger than 64-128M as this can decrease performance
# since the penalty for flushing the cache can become
# significant.
query_cache_size=32M
skip-name-resolve
# Set this to change the way MySQL handles validation, data
# conversion, etc. Be careful with this setting as it can
# cause unexpected results and horribly break some applications!
# Note, too, that it can be set per-session and can be hard set
# in stored procedures.
#sql_mode=NO_ENGINE_SUBSTITUTION
# Slow Query Log Settings
# -----------------------
#log-slow-queries=/var/lib/mysqllogs/slow-log
#long_query_time=2
#log-queries-not-using-indexes
# Global, Non Engine-Specific Buffers
# -----------------------------------
max_allowed_packet=16M
tmp_table_size=64M
max_heap_table_size=64M
# Generally, it is unwise to set the query cache to be
# larger than 64-128M as this can decrease performance
# since the penalty for flushing the cache can become
# significant.
query_cache_size=32M
# Per-Thread Buffers
# ------------------
sort_buffer_size=1M
read_buffer_size=1M
read_rnd_buffer_size=8M
join_buffer_size=1M
key_buffer_size=64M
# This setting controls the size of the buffer that is allocated when
# sorting MyISAM indexes during a REPAIR TABLE or when creating indexes
# with CREATE INDEX or ALTER TABLE.
myisam_sort_buffer_size=64M
# InnoDB
# ------
# Note: While most settings in MySQL can be set at run-time, InnoDB
# variables require restarting MySQL to apply.
# If the customer already has InnoDB tables and wants to change the
# size of the InnoDB tablespace and InnoDB logs, then:
# 1. Run a full backup with mysqldump
# 2. Stop MySQL
# 3. Move current ibdata and ib_logfiles out of /var/lib/mysql
# 4. Uncomment the below innodb_data_file_path and innodb_log_file_size
# 5. Start MySQL (it will recreate new InnoDB files)
# 6. Restore data from backup
#innodb_data_file_path=ibdata1:2000M;ibdata2:10M:autoextend
innodb_log_file_size=100M
innodb_buffer_pool_size=2G
........
【问题讨论】:
-
MySQL 使用硬盘存储数据。 MongoDB 使用硬盘来存储数据。 MySQL 从磁盘读取数据。 MongoDB 从磁盘读取数据。出于某种原因,您显然认为 MongoDB 有一些秘密代码可以让它更好地使用磁盘。它没有。如果你把它移到那里,它不会工作得更快。它只会容易丢失数据,而且您会认为它更快。像您所拥有的那样优化表取决于您的服务器、可用 RAM 和磁盘的整体速度。您提供的信息不足,您应该包含 MySQL 实例的配置变量。
-
感谢您的评论。我们有 128 gb 的内存服务器,当前数据库使用了大约 110 gb。我会尽快用配置更新帖子。
-
Intel(R) Xeon(R) CPU E5-2640 0 @ 2.50GHz 步进 07
-
如果我能多次支持 N.B. 的评论,我会的。 Mongodb 是 受到与 mysql 相同的限制。但是从您提供的信息来看,似乎有很多 的空间可以加快您的数据库,并且有很多证据表明您没有花费太多精力来加快它的速度。但是如何调整你的分贝是一个太复杂的问题,无法在这里回答。你可以先运行 mysqltuner.pl
-
@symcbean -- 我为你(和我)投了赞成票。
标签: mysql mongodb optimization bigdata database-partitioning