在Docker容器中运行数据库的性能问题 [英] Performance issues running a database in a docker container

查看:569
本文介绍了在Docker容器中运行数据库的性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人注意到在Docker容器中运行数据库(MySQL或Postgres)的任何性能问题,我被告知会出现严重的性能下降。



请指教。

解决方案

Docker本身施加了很少的开销,只是将进程与主机上的其他进程隔离开来。但是,您可以做很多事情来降低容器的性能:


  1. 在Windows / MacOS中运行它,而只提供嵌入式虚拟机是父OS的内存/ CPU的一小部分。

  2. 限制容器内的CPU或内存资源。

  3. 启动大量容器在你的主机上Docker不是魔术,如果每个使用2个gig的ram的10个实例使主机在容器外面爬行,他们将不会在容器内运行更好。

  4. 网络并发症。默认情况下,每个容器都会在隔离的网桥上旋转,其中IO可能需要更多的时间才能使用额外的跳数。如果您的DNS配置不正确,您可能会在查找失败时看到额外的延迟。

  5. 在Docker中默认情况下,不允许使用直接磁盘访问的裸机要求。您可以授予对特定设备的访问权限,否则容器版本的应用程序将被有意隔离。

  6. 卷中的数据可能位于效率较低的位置。默认情况下,这是您的/ var / lib / docker文件系统,但是您可以轻松地将其指向NFS安装,性能将会更糟。

  7. 配置错误的数据库,例如忘记创建一个索引。

简而言之,容器本身不太可能是问题,但确保你正在做一个苹果对苹果比较。


Has anyone noticed any performance issues running a database (MySQL or Postgres) in a docker container, I'm told that severe performance degradation occurs.

Please advise.

解决方案

Docker itself imposes very little overhead, it's just isolating the process from other processes on the host. However, there are lots of things you can do to degrade the performance of a container:

  1. Run it inside Windows/MacOS while only giving the embedded VM a fraction of the memory/CPU of the parent OS.
  2. Restrict CPU or memory resources inside the container.
  3. Launch a lot of containers on your host. Docker isn't magic, if 10 instances of Java each using 2 gigs of ram bring the host to a crawl outside of container, they won't run any better inside of containers.
  4. Networking complications. Each container is by default spun up on an isolated network bridge, where IO may take a little longer with the extra hops. And if your DNS isn't properly configured, you may see extra delays from failed lookups.
  5. Bare metal requirements like direct disk access aren't allowed by default in Docker. You can give access to specific devices, but otherwise the containerized version of the app is isolated intentionally.
  6. Data in volumes may reside in a less efficient location. By default it's your /var/lib/docker filesystem, but you could easily point this to an NFS mount where the performance would be even worse.
  7. Misconfigured DB, e.g. forgetting to create an index.

In short, the container is unlikely to be the issue itself, but make sure you're doing an apples to apples comparison.

这篇关于在Docker容器中运行数据库的性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆