简体   繁体   English

使用 windows 上的 docker 卷(仅在 docker 容器内部)或与主机操作系统安装/共享卷时,读/写性能是否更好?

[英]Is read/write performance better with docker volumes on windows (inside of a docker container only) or a mounted / shared volume with host OS?

I have read that there is a significant hit to performance when mounting shared volumes on windows.我已经读到在 windows 上安装共享卷时性能会受到重大影响。 How does this compared to only having say the postgres DB inside of a docker volume (not shared with host OS) or the rate of reading/writing from/to flat files?这与只说 docker 卷(不与主机操作系统共享)或从/向平面文件读取/写入的速率相比如何?

Has anyone found any concrete numbers around this?有没有人找到任何具体的数字? I think even a 4x slowdown would be acceptable for my usecase if it is only for disc IO performance... I get the impression that mounted + shared volumes are significantly slower on windows... so I want to know if foregoing this sharing component help improve matters into an acceptable range.如果仅用于磁盘IO性能,我认为即使是 4 倍的减速也可以接受帮助将事情改善到可接受的范围内。

Also if I left Postgres on bare metal can all of my docker apps access Postgres still that way?此外,如果我将 Postgres 留在裸机上,我的所有 docker 应用程序仍能以这种方式访问 Postgres 吗? (That's probably preferred I would imagine - I have seen reports of 4x faster read/write staying bare metal) - but I still need to know... because my apps deal with lots of copy / read / moving of flat files as well... so need to know what is best for that. (这可能是我想像的首选——我已经看到关于保持裸机读/写速度提高 4 倍的报告)——但我仍然需要知道......因为我的应用程序也处理大量平面文件的复制/读取/移动。 ..所以需要知道什么是最好的。

For example, if shared volumes are really bad vs keeping it only on the container, then I have options to push files over the network to avoid the need for a shared mounted volume as a bottleneck...例如,如果共享卷真的很糟糕,而不是只保留在容器上,那么我可以选择通过网络推送文件以避免需要共享安装卷作为瓶颈......

Thanks for any insights感谢您的任何见解

You only pay this performance cost for bind-mounted host directories.您只需为绑定安装的主机目录支付此性能成本。 Named Docker volumes or the Docker container filesystem will be much faster.命名为 Docker 卷或 Docker 容器文件系统将快得多。 The standard Docker Hub database images are configured to always use a volume for storage, so you should use a named volume for this case.标准 Docker Hub 数据库映像配置为始终使用卷进行存储,因此在这种情况下您应该使用命名卷。

docker volume create pgdata
docker run -v pgdata:/var/lib/postgresql/data -p 5432:5432 postgres:12

You can also run PostgreSQL directly on the host.您也可以直接在主机上运行 PostgreSQL。 On systems using the Docker Desktop application you can access it via the special hostname host.docker.internal .在使用 Docker 桌面应用程序的系统上,您可以通过特殊的主机名host.docker.internal访问它。 This is discussed at length in From inside of a Docker container, how do I connect to the localhost of the machine?这在从 Docker 容器内部进行了详细讨论,如何连接到机器的本地主机? . .

If you're using the Docker Desktop application, and you're using volumes for:如果您使用 Docker 桌面应用程序,并且您将卷用于:

  • Opaque database storage, like the PostgreSQL data: use a named volume;不透明的数据库存储,如 PostgreSQL 数据:使用命名卷; it will be faster and you can't usefully directly access the data even if you did have it on the host它会更快,即使您在主机上确实有数据,您也无法有效地直接访问数据
  • Injecting individual config files: use a bind mount;注入单个配置文件:使用绑定挂载; these are usually only read once at startup so there's not much of a performance cost这些通常只在启动时读取一次,因此没有太多的性能成本
  • Exporting log files: use a bind mount;导出日志文件:使用绑定挂载; if there is enough log I/O to be a performance problem you're probably actively debugging如果有足够的日志 I/O 成为性能问题,您可能正在积极调试
  • Your application source code: don't use a volume at all, run the code that's in the image, or use a native host development environment您的应用程序源代码:根本不使用卷,运行映像中的代码,或使用本机主机开发环境

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM