Docker Container running very slow for Rails Application on development mode
Asked Answered
D

1

10

I am facing an issue on docker container. Rails Application is running very slow(means pages taking too much time to load on the browsers).

Application details:

Rails Version: 4.2.0 Ruby version: 2.2.0

When I checked the status of memory by command docker stats, it is showing that the CPU utilization is very high for the main container(1). Sometimes it goes to 50% of utilization.

I tried with the few configurations i.e increase the CPU allocation for the docker, the performance get increased a little bit.

version: '3.7'

services:
  selenium:
    image: selenium/standalone-chrome-debug:3.141.59-krypton
    ports: ['4444:4444', '5900:5900']
    logging:
      driver: none
  redis:
    image: redis:3.0.0
  elastic:
    image: elasticsearch:1.5.2
  db:
    image: postgres:9.3.10
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
      - .:/home
  XYZ:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    stdin_open: true
    tty: true
    volumes:
      - .:/home
    ports:
      - "3000:3000"
    depends_on:
      - db
      - redis
      - elastic
      - selenium
    environment:
      - REDIS_URL=redis://redis:6379/0
      - ELASTICSEARCH_URL=elastic://elastic:9200/0
      - SELENIUM_HOST=selenium
      - SELENIUM_PORT=4444
      - TEST_APP_HOST=XYZ
      - TEST_PORT=3000

And I observed that the js files which are loading on browser taking too much time to load approx 1.3 min, e.g If there are 4 js files, each file taking more that 1 min to load

What I feel is docker is running slow on a mac machine, because the same application is running very well on Linux machine, might be I am wrong, but this is the observation which I saw.

Any help will be appreciated.

Difficulty answered 29/8, 2019 at 11:19 Comment(7)
can you also iclude the result of top commandMourant
docker on mac is not native but HyperKit, a lightweight macOS virtualization solution built on top of Hypervisor.framework. This might have something to do with the performance differenceDavao
have you try to play with cached and delegated [1] ? have you tried external tools like docker-sync ? could you do a test with a container without volume ? [1] : docs.docker.com/docker-for-mac/osxfs-cachingBurnaby
@Burnaby I haven't tried with the docker-sync let me try with this will let you knowDifficulty
hello @jmny, thanks for your suggestion, docker-sync actually worked on my scenario, now it much better now. But now I am facing an issue that it does not sync the latest code when I refresh the page. can you please let me know what I am missing?Difficulty
you have an example here : medium.com/devcupboard/…Burnaby
@jmnyI tried the same way, but it is not syncing the latest codeDifficulty
D
4

I resolved my issue by setting up the docker-sync. I followed this article to setup the docker-sync

Steps to solve the issue:

step1: sudo gem install docker-sync

step2: create a docker-sync.yml file

version: "2"
options:
  verbose: true
syncs:
  #IMPORTANT: ensure this name is unique and does not match your other application container name
  XYZ-sync: #tip: add -sync and you keep consistent names as a convention
    src: .
    sync_host_ip: 'localhost'
    sync_host_port: 10872
sync_strategy: 'rsync'

step3: update the docker-compose.yml file with below details

...
    volumes:
      - xyz-sync:/home:nocopy

volumes:
  XYZ-sync:
    external: true

step4: brew install rsync

step5: docker-sync-stack start

Difficulty answered 30/8, 2019 at 8:10 Comment(2)
I explained the entire process to setup docker-sync betterprogramming.pub/…Difficulty
This didn't work for me because docker-sync seems to have an issue github.com/EugenMayer/docker-sync/issues/509 None of the solutions there worked for me. Not sure if there is a step missingVillanelle

© 2022 - 2024 — McMap. All rights reserved.