ActionCable on Production

#3 ActionCable on Production
7/20/2015

Summary

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

Summary

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__)
    Rails.application.eager_load!

    require 'action_cable/process/logging'
    Faye::WebSocket.load_adapter('thin')
    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
    make test
    sudo make install
    cd utils
    sudo ./install_server.sh

    sudo service redis_6379 start
    sudo service redis_6379 stop
3416976?v=3&s=64
zulhfreelancer said over 1 year 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?

635114?v=3&s=64
kobaltz said over 1 year 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.

3416976?v=3&s=64
zulhfreelancer said over 1 year ago:

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

635114?v=3&s=64
kobaltz said over 1 year 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.

7865030?v=3&s=64
Schwad said 9 months ago:

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