使用LOAD DATA INFILE导入大数据文件时如何保持MYSQL性能?

发布于 2024-10-11 01:28:29 字数 248 浏览 14 评论 0原文

我正在使用一个大型数据库(某些表有 500000000+ 行)。每天应使用 LOAD DATA INFILE 替换 3-1000 万行,每次导入大约 100 万行(因此使用 CRON 每天 3-10 次)。 问题是,在导入如此大的文件时,MySQL 会占用 80% 的 CPU,并且来自网站的所有常见查询都变得非常慢或网站性能下降。 站点在 Amazon 的 EC2 Windows 2008 服务器下运行。 有谁知道如何在一个EC2实例中解决这个问题(不拆分数据库) 谢谢。

I'm working with a large database (some tables 500000000+ rows) . Each day 3-10 millions rows should be replaced and each import is about 1 million rows (so 3-10 times a day with CRON) using LOAD DATA INFILE.
The problem is, that while making such big file import, MySQL eats 80% of CPU and all common queries going from website became very slow or website performance falls down.
Site is running under Amazon's EC2 Windows 2008 server.
Does anyone know how to solve this problem within one EC2 instance (without splitting database)
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若言繁花未落 2024-10-18 01:28:29

一个快速而肮脏的黑客...如何将源文件分割成更小的负载,然后将其作为数据库加载操作进行定时,每次加载之间有 5 分钟的休息时间?一次管理1000万条记录会耗尽许多服务器和数据库资源,从而导致崩溃。如果您有一台具有大量内存的大型服务器,仅使用 50-100K 的负载可能还不错。

A quick and dirty hack... What about splitting the source files into smaller loads, which are then cron'ned as a DB load operation, with a 5 minute break between each load? Managing 10 million records at a time will exhaust many server and DB resources, and hence the crash. Using loads of only 50-100K may not be too bad if you have a large server with lots of memory.

愁以何悠 2024-10-18 01:28:29

分销似乎是可行的方法(这就是Facebook的做法)

不知道你不这样做的理由是什么,预算限制?

其他可能的方法

  • 放弃使用Windows - Windows 的限制
  • 在通过 cron 导入期间设置 mysql 复制
  • ,防止所有查询命中 master,反之亦然。一旦导入完成(比如设置两个标志文件,如果master标志存在,则使用slave,如果slave标志文件存在,则使用master,两者都不存在,则两者都可以查询)
  • 考虑分区
  • 丢弃所有索引(承担后果)

很大程度上取决于您的数据库使用情况,如果不是关键任务,则进行离线导入非常合适

distribution seems the way to go (that's how facebook does things)

not sure what is the rational for you not to do so, budget constraints?

other possible approaches

  • discard use of windows - limitation of windows
  • setup mysql replication
  • during import via cron, prevent all query hit to master,and vice versus. once the import is completed (something like set two flag files, if master flag exist, use slave, if slave flag file exist, use master, both not exist, then both can be query)
  • consider partition?
  • discard all index (bear the consequence)

is much depend on your database usage, if not mission critical, do an offline import much suitable

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文