开发者

Starting socket server in ruby on rails on cloud environments (heroku)

I'm using heroku, and I can push a Ruby on Rails app just fine, I'm trying to convert this to a Socket server, basi开发者_如何学JAVAcally I would need to bind to an open port, in this case, I know Heroku only does 80 22 and 443.

Is it possible to bind to port 80 on those environments?

Also, how would I setup the entry point for this socket server, all I know is that when script/server it boots up the app.

Do I have to put the function call there? How can a socket server start instead of the rails app on top of whatever webserver heroku has.


Currently there's no way to route non-HTTP traffic to your app. Heroku binds Ruby web servers to various ports and hosts behind the scenes and then routes traffic to those processes based on the Host in your HTTP header. Requests lasting longer than 30s are assumed to be hung, and are terminated.

From a design perspective, long running queries present a significant performance problem. With a single dyno, any request that lasts 30 seconds (or even 2 seconds) is preventing any other user from accessing your site for the entire duration. Instead, a more performant design is to quickly serve a page in a base state and use a worker thread to process the content in the background while pulling results in via javascript. This can be done simply using modern web development tools.

In the event that you have a long-running process that you don't need to communicate with via a socket you can simply use a worker. I'd recommend a tool like MongoDB for storing results of computations and a library like Delayed::Job for queuing.

Having said all that, there are definitely reasonable use cases which demand longer running processes and non-HTTP traffic, but at the moment Heroku doesn't support them.


I don't think this is possible on Heroku. They don't support this kind of architecture and you have limited control over the kinds of things you can run in the environment.

Might be worth having a look at Node.js support just announced ... currently in Beta, but might give you something to work with.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜