Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Container running very slow for Rails Application on development mode

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.

like image 937
Rohit Lingayat Avatar asked Aug 29 '19 11:08

Rohit Lingayat


1 Answers

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

like image 130
Rohit Lingayat Avatar answered Oct 19 '22 14:10

Rohit Lingayat