用 docker-compose 构建了一个服务,mongodb 里面载入了几百万数据,数据查询慢的无法忍受, 但是实体机上几乎是瞬间完成, docker 就非常非常慢, 我的 docker 版本是:17.03.1-ce,
mongodb_1 | 2017-06-14T08:33:53.167+0000 I QUERY [conn84] query Info.info_b query: { geoname_id: 7533614 } planSummary: COLLSCAN cursorid:10038145745 ntoreturn:0 ntoskip:0 keysExamined:0 docsExamined:1818459 keyUpdates:0 writeConflicts:0 numYields:14206 nreturned:101 reslen:5141 locks:{ Global: { acquireCount: { r: 28414 } }, Database: { acquireCount: { r: 14207 } }, Collection: { acquireCount: { r: 14207 } } } 613ms
mongodb_1 | 2017-06-14T08:33:53.559+0000 I QUERY [conn84] getmore Info.info_b query: { geoname_id: 7533614 } cursorid:10038145745 ntoreturn:0 cursorExhausted:1 keyUpdates:0 writeConflicts:0 numYields:8854 nreturned:219 reslen:11230 locks:{ Global: { acquireCount: { r: 17710 } }, Database: { acquireCount: { r: 8855 } }, Collection: { acquireCount: { r: 8855 } } } 389ms
mongodb_1 | 2017-06-14T08:33:53.569+0000 I NETWORK [conn84] end connection 172.18.0.4:60124 (0 connections now open)
mongodb_1 | 2017-06-14T08:33:53.570+0000 I NETWORK [initandlisten] connection accepted from 172.18.0.4:60128 #85 (1 connection now open)
mongodb_1 | 2017-06-14T08:33:54.555+0000 I QUERY [conn85] query Info.info_b query: { geoname_id: 8223931 } planSummary: COLLSCAN ntoreturn:0 ntoskip:0 keysExamined:0 docsExamined:2951856 cursorExhausted:1 keyUpdates:0 writeConflicts:0 numYields:23061 nreturned:2 reslen:119 locks:{ Global: { acquireCount: { r: 46124 } }, Database: { acquireCount: { r: 23062 } }, Collection: { acquireCount: { r: 23062 } } } 984ms
mongodb_1 | 2017-06-14T08:33:54.557+0000 I NETWORK [conn85] end connection 172.18.0.4:60128 (0 connections now open)
mongodb_1 | 2017-06-14T08:33:54.557+0000 I NETWORK [initandlisten] connection accepted from 172.18.0.4:60130 #86 (1 connection now open)
mongodb_1 | 2017-06-14T08:33:55.534+0000 I QUERY [conn86] query Info.info_b query: { geoname_id: 8223932 } planSummary: COLLSCAN ntoreturn:0 ntoskip:0 keysExamined:0 docsExamined:2951856 cursorExhausted:1 keyUpdates:0 writeConflicts:0 numYields:23061 nreturned:34 reslen:1746 locks:{ Global: { acquireCount: { r: 46124 } }, Database: { acquireCount: { r: 23062 } }, Collection: { acquireCount: { r: 23062 } } } 976ms
docker-compose:
version: '2'
services:
shmserver:
build:
context: ../
dockerfile: Dockerfile
ports:
- "18081:18081"
links:
- redis:redis
- mongodb:mongodb
depends_on:
- redis
- mongodb
redis:
image: redis:latest
volumes:
- /home/database:/var/lib/redis
ports:
- "6479:6379"
mongodb:
image: mongo
volumes:
- /home/db:/home/db
ports:
- "27017:27017"
command: --storageEngine wiredTiger --dbpath /home/db
怎么才能提升性能呢?
1
leandre 2017-06-14 16:53:02 +08:00
docker 使用的是网络目录挂载,也就是配置文件中`/home/db`实际上是走虚拟网络读取数据,性能会降低。
|
2
SlipStupig OP @leandre 有什么解决办法吗?
|
3
Chingim 2017-06-14 17:03:48 +08:00 via Android
宿主是什么系统?
|
4
Chingim 2017-06-14 17:05:56 +08:00
如果是 OSX, 可能要看看这个 issue:
https://github.com/docker/for-mac/issues/77#issuecomment-280396677 |
5
SlipStupig OP @Chingim ubuntu
|
7
hljjhb 2017-06-14 20:50:14 +08:00
数据库不要放在 docker 里= =
|
8
swcat 2017-06-14 23:38:06 +08:00 via iPhone
数据库不要放 docker 里面
|
9
SlipStupig OP |
10
oyyd 2017-06-15 08:27:36 +08:00
试一下使用宿主机的网络`docker run --net=host`
|
11
oyyd 2017-06-15 18:01:47 +08:00
@SlipStupig 我这边未来也会有类似的事情,我很在意你们在 docker 里面运行 mongodb 到底有没有性能影响(之前看别人的帖子得到的反馈应该是没有太大的影响)
|
12
SlipStupig OP @oyyd 有影响,但是很小,之前这个问题在我,我那个索引没建立,会非常慢
|
13
SlipStupig OP @oyyd 数据不要直接构建到容器里面而是要放在磁盘上
|
14
oyyd 2017-06-16 11:54:13 +08:00
@SlipStupig 感谢告知
|
15
swcat 2017-06-17 00:20:27 +08:00 via iPhone
@SlipStupig 能力达不到😂
|