V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
SlipStupig
V2EX  ›  程序员

mongodb docker 性能特别差怎么才能提升呢?

  •  
  •   SlipStupig · 2017-06-14 16:42:30 +08:00 · 4722 次点击
    这是一个创建于 2725 天前的主题,其中的信息可能已经有所发展或是发生改变。

    用 docker-compose 构建了一个服务,mongodb 里面载入了几百万数据,数据查询慢的无法忍受, 但是实体机上几乎是瞬间完成, docker 就非常非常慢, 我的 docker 版本是:17.03.1-ce,


    • log 如下:
    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
    

    怎么才能提升性能呢?

    15 条回复    2017-06-17 00:20:27 +08:00
    leandre
        1
    leandre  
       2017-06-14 16:53:02 +08:00
    docker 使用的是网络目录挂载,也就是配置文件中`/home/db`实际上是走虚拟网络读取数据,性能会降低。
    SlipStupig
        2
    SlipStupig  
    OP
       2017-06-14 16:58:27 +08:00
    @leandre 有什么解决办法吗?
    Chingim
        3
    Chingim  
       2017-06-14 17:03:48 +08:00 via Android
    宿主是什么系统?
    Chingim
        4
    Chingim  
       2017-06-14 17:05:56 +08:00
    SlipStupig
        5
    SlipStupig  
    OP
       2017-06-14 17:22:57 +08:00
    @Chingim ubuntu
    billlee
        6
    billlee  
       2017-06-14 20:43:14 +08:00
    @leandre #1 volumes 默认是 aufs 吧,和网络有什么关系
    hljjhb
        7
    hljjhb  
       2017-06-14 20:50:14 +08:00
    数据库不要放在 docker 里= =
    swcat
        8
    swcat  
       2017-06-14 23:38:06 +08:00 via iPhone
    数据库不要放 docker 里面
    SlipStupig
        9
    SlipStupig  
    OP
       2017-06-15 07:24:02 +08:00
    @hljjhb
    @swcat 只能在物理机里面操作?没有什么办法提高性能么?
    oyyd
        10
    oyyd  
       2017-06-15 08:27:36 +08:00
    试一下使用宿主机的网络`docker run --net=host`
    oyyd
        11
    oyyd  
       2017-06-15 18:01:47 +08:00
    @SlipStupig 我这边未来也会有类似的事情,我很在意你们在 docker 里面运行 mongodb 到底有没有性能影响(之前看别人的帖子得到的反馈应该是没有太大的影响)
    SlipStupig
        12
    SlipStupig  
    OP
       2017-06-16 11:46:11 +08:00
    @oyyd 有影响,但是很小,之前这个问题在我,我那个索引没建立,会非常慢
    SlipStupig
        13
    SlipStupig  
    OP
       2017-06-16 11:46:49 +08:00   ❤️ 1
    @oyyd 数据不要直接构建到容器里面而是要放在磁盘上
    oyyd
        14
    oyyd  
       2017-06-16 11:54:13 +08:00
    @SlipStupig 感谢告知
    swcat
        15
    swcat  
       2017-06-17 00:20:27 +08:00 via iPhone
    @SlipStupig 能力达不到😂
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2859 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 06:37 · PVG 14:37 · LAX 22:37 · JFK 01:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.