ActionCable on Production

#3 ActionCable on Production


Taking a look at ActionCable and switching from Puma to Thin. On server reboot, spin up the ActionCable service.
streaming rails websockets


Gemfile    gem 'actioncable', github: 'rails/actioncable'
    gem 'thin'
    gem 'whenever', :require => false
One thing that I neglected to mention is that you do need to write to your crontab once you have made your changes to the `schedule.rb` file. You can do this by running `whenever -w` in your application directory on the production machine.

bash    touch bin/cable
    chmod +x bin/cable
Change out the `puma` server startup script to `thin`

bin/cable    # /bin/bash
    bundle exec thin start -C config/cable.yml
Be sure to add the `thin` adapter to the Faye Websocket.

cable/    require ::File.expand_path('../../config/environment',  __FILE__)

    require 'action_cable/process/logging'
    run ActionCable.server
Create your `cable.yml` file and put the appropriate settings for your server.

config/cable.yml    ---
    chdir: /home/user/drifting_ruby
    environment: production
    port: 8443
    timeout: 30
    log: log/thin.log
    pid: tmp/pids/
    max_conns: 8192
    max_persistent_conns: 8192
    require: []
    wait: 30
    threadpool_size: 4
    servers: 1
    daemonize: true
    ssl: true
    ssl-disable-verify: true
    ssl_key_file: ssl/ssl.key
    ssl_cert_file: ssl/ssl.crt
    rackup: cable/
Some notes for installing Redis. These instructions work on Ubuntu 14.04, but may work on other Debian-based distributions.

bash    sudo apt-get update
    sudo apt-get install build-essential
    sudo apt-get install tcl8.5

    tar xzf redis-stable.tar.gz
    cd redis-stable
    make test
    sudo make install
    cd utils
    sudo ./

    sudo service redis_6379 start
    sudo service redis_6379 stop
zulhfreelancer said 5 months ago:

I've question at 4:11. Does the max_conns means maximum concurrency connection of the web socket at one time my application can handle?

kobaltz said 5 months ago:

No, `max_conns` is the maximum number of file descriptors that can be open where as `max-persistent-conns` is the maximum number of persistent connections you're referring to. Depending on your configuration, you could have a dedicated web socket server balanced by an HAPROXY server. This would allow for much greater number of connections while all serving at the same endpoint.

zulhfreelancer said 5 months ago:

So, you put '8192' for both. Should I put same number for both too? Can they be different?

kobaltz said 5 months ago:

With concurrency in mind, `max_conn` could probably be left at the default of 1024. However, the default for `max_persistent_conns` is 100.

Login to Comment