#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 6:13


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/config.ru    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/thin.pid
    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/config.ru
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

    wget http://download.redis.io/releases/redis-stable.tar.gz
    tar xzf redis-stable.tar.gz
    cd redis-stable
    make test
    sudo make install
    cd utils
    sudo ./install_server.sh

    sudo service redis_6379 start
    sudo service redis_6379 stop
zulhfreelancer said over 3 years ago on ActionCable on Production :

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 PRO said over 3 years ago on ActionCable on Production :

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 over 3 years ago on ActionCable on Production :

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

kobaltz PRO said over 3 years ago on ActionCable on Production :

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

Schwad said almost 3 years ago on ActionCable on Production :

This was really cool. I may have to start playing with actioncable with some toy apps to get more familiar with it before trying to figure my way around it in production at work. Thanks for the screencast.

Login to Comment