multithreading - Docker sidekiq 比原生操作系统慢得多

标签 multithreading performance docker sidekiq

我一直在使用 docker compose 运行我的应用程序有一段时间了。应用程序最繁重的部分之一是后台任务。

我注意到我的大多数后台任务(使用 sidekiq 运行)运行速度比我同事的一台计算机(不使用 docker)慢得多。

使用 docker,相同的后台任务在 40 seconds 中运行.在 native 操作系统上,它在 12 seconds 中运行.我自己在我的机器上尝试过这个并在 native 操作系统上运行它,我可以确认它要快得多。

docker 信息:

Containers: 14
 Running: 4
 Paused: 0
 Stopped: 10
Images: 42
Server Version: 17.12.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 89623f28b87a6004d4b785663257362d1658a729
runc version: b2567b37d7b75eb4cf325b77297b140ea686ce8f
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.60-linuxkit-aufs
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 7.786GiB
Name: linuxkit-025000000001
ID: CFFM:EFLI:4A5K:XTPG:E27S:KXJT:26SS:ZAPE:ZAFW:3BRM:E6YK:MVAA
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 76
 Goroutines: 129
 System Time: 2018-02-09T14:13:44.910242335Z
 EventsListeners: 3
HTTP Proxy: docker.for.mac.http.internal:3128
HTTPS Proxy: docker.for.mac.http.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

docker 组成:
version: '3.4'

services:
  sidekiq-1:
    build: .
    command: bundle exec sidekiq -c 4 -L log/sidekiq-1.log
    tty: true
    stdin_open: true
    volumes:
      - '.:/app'
    environment:
      - DATABASE_URL=postgres://username@postgres/database
      - REDIS_URL=redis://redis:6379
  sidekiq-2:
    build: .
    command: bundle exec sidekiq -c 4 -L log/sidekiq-2.log
    tty: true
    stdin_open: true
    volumes:
      - '.:/app'
    environment:
      - DATABASE_URL=postgres://username@postgres/database
      - REDIS_URL=redis://redis:6379

我对可能发生的事情有点迷茫。

我注意到的一件事是,即使我已将 8 个内核分配给 docker ,只有 4 个线程同时在 sidekiq 上运行和 CPU 使用率使用 docker stats这两个容器永远不会超过 80%。

任何帮助表示赞赏。

最佳答案

Docker for Mac 已知某些文件系统密集型工作负载的性能问题。见 herehere获取官方信息。使用 Mac 安装的卷往往是最差的。在安装中型 Django + 节点项目并尝试获取 runserver 时,我看到了类似的性能下降。命令响应(剧透,在这种情况下不是很好,fs开销太多)。

您可以尝试一些方法,而不是挂载整个应用程序目录,而是尽可能少地挂载。很难说不知道项目是什么样子会有多大帮助。您还应该能够通过不使用绑定(bind)挂载来提高性能; COPY您的文件通过 Dockerfile 保存,然后使用命名卷来保存它们。这会给您的开发工作流程带来一点阻碍,但我认为它会显着加快 sidekiq 的性能。

关于multithreading - Docker sidekiq 比原生操作系统慢得多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48707996/

相关文章:

docker - Dockerfile vim安装不起作用

python - 多线程 cstringio 在 ubuntu 14.04 上慢 17%

Python队列组合

performance - Flutter,Future.delay 或 Timer 性能更好?

java - 设计网络应用程序 : where should business logic reside?

docker-compose 尝试拉取已经存在的图像

python - Django - 默认端口 0 而不是 3306 - 无法连接到 '127.0.0.1' 上的 MySQL 服务器 (61)

java - 在 Android 中使用线程时出现错误

java - 无限循环的线程会导致CPU占用率过高吗

java - ExecutorService 未及时终止