【问题标题】:MySQL partitioning vs changing to MongoDBMySQL 分区与更改为 MongoDB
【发布时间】: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


【解决方案1】:

您有 128GB,请使用它! innodb_buffer_pool_size=2G -- 更改为大约 70% 的 RAM。

我敢打赌,你不能给我看一个使用 KEY instaID (instaID(50))EXPLAIN。前缀索引几乎总是不用。

打开慢日志,收集一些数据,运行 pt-query-digest,然后向我们展示“最差”的查询。为它提供EXPLAIN SELECT ...

id int(20) NOT NULL AUTO_INCREMENT, -- 我希望你不要期待 20 位数字。这将超过 20 亿。

如果我们无法优化您的查询,那么我们将转向数据仓库技术,例如汇总表——它们往往可以提供 10 倍的加速。

【讨论】:

  • 人们通常会错过 buffer_pool,很好,你提到了 :) 有我的支持。
  • 是的,我已经厌倦了指出这一点,所以我写了一个博客,主要细节:mysql.rjweb.org/doc.php/memory
【解决方案2】:

如果不了解您如何使用它或您将首先面临什么瓶颈,这真的是不可能回答的。

请记住,如果您不时不时优化表,Innodb 的大小会出现一些问题。

【讨论】:

  • 否 -- InnoDB 几乎不需要 OPTIMIZE TABLE。
  • @RickJames 在这里实际上是正确的。不需要OPTIMIZE。文档可能暗示它是,但事实并非如此。 InnoDB 上的OPTIMIZE 将执行重新创建和分析。它将删除表格并重新插入所有内容。如果表没有被大量删除或更新,那么这一步是没有用的,它只会增加服务器的负载而实际上没有收获。请记住,适合工作的工具。 OP 的场景中不需要 OPTIMIZE。他需要做的是 Rick 在他的回答中提到的 - 增加缓冲池。
  • OP 在我写了关于优化的文章后改变了他的主题。所以我无法知道它是否正在执行大量删除操作。并且“InnoDB 几乎不需要 OPTIMIZE TABLE”。是一个更笼统的陈述,这是完全错误的。如果我们有时不对其进行优化,我们的数据库将有超过 100 GB 的开销。
猜你喜欢
  • 1970-01-01
  • 2011-03-24
  • 1970-01-01
  • 2021-08-07
  • 1970-01-01
  • 2019-12-27
  • 2011-03-27
  • 2021-12-29
  • 2010-10-30
相关资源
最近更新 更多