码迷,mamicode.com
首页 > 其他好文 > 详细

ActionCable的部署(参考Gorails)

时间:2018-11-03 12:36:34      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:The   webapp   ruby   running   dep   res   平衡   name   inf   

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

 

ActionCable的部署(参考Gorails)

标签:The   webapp   ruby   running   dep   res   平衡   name   inf   

原文地址:https://www.cnblogs.com/chentianwei/p/9900012.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!