1. 程式人生 > >ActionCable的部署(參考Gorails)

ActionCable的部署(參考Gorails)

Gorails視訊

https://gorails.com/deploy/actioncable

 

Action Cable – Integrated WebSockets for Rails

https://github.com/rails/rails/tree/master/actioncable

 

Passenger官網文章:

Tuning for Server Sent Events and WebSockets(on Passenger + Nginx)

Integrating Action Cable with Passenger + Nginx

 


 

Ruby併發微調

Passenger的高度優化load balancer負載平衡: Ruby apps 可以處理1個併發連線(或者執行緒限制的數量)。

但是終端deal with SSE/Websockets可以處理更多的併發連線,因此需要改變:

使用: force max concurrent requests per process configuration option 。

例子:如何設定併發來取消對special_websocket_endpoint的限制

server {
   listen 80;
   server_name www.example.com;
   root 
/webapps/my_app/public; passenger_enabled on; # Use default concurrency for the app. But for the endpoint # /special_websocket_endpoint, force a different concurrency. location /special_websocket_endpoint { passenger_app_group_name foo_websocket; passenger_force_max_concurrent_requests_per_process
0
; } }

⚠️
/special_websocket_endpoint改成你的cable名字,一般用/cable
⚠️:passenger_app_group_name後面是你的app_group_name
 

 

如果使用的是Rails ,看 Integrating Action Cable with Passenger + Nginx

There are two ways to setup Action Cable with Passenger + Nginx:

  1. Running the Action Cable server on the same host and port, under a sub-URI
  2. Running the Action Cable server on a different host or port

需要使用:

Passenger 5.0.24以上

Redis, PostgreSQL或其他inter-process adapter supported by Cable。

 

。。暫時等待。。


 

 

git文件 

重點:

Consumer Configuration

In any case, to vary the WebSocket URL between environments, add the following configuration to each environment: 3步驟

config.action_cable.url = "xxxxxx"

Then add the following line to your layout before your JavaScript tag:

<%= action_cable_meta_tag %>

 

And finally, create your consumer like so:

App.cable = ActionCable.createConsumer()

 

 

Allowed Request Origins

Action Cable將只接受那些指定源頭specific origins的請求 。

在server端的config/environments/production.rb中設定:

config.action_cable.allowed_request_origins = ['http://xxxxxx.com']
⚠️也可以是"http://111.xxx.xx.xx"的ip。取消檔案中的註釋並修改即可。

然後改寫:config.aciton_cable.url = '/cable'
這是為使用者連線設定server url。

 

 

步驟:具體見https://gorails.com/deploy/actioncable