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, basically 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.

Answers


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.


Need Your Help

MSBuild from Powershell

powershell msbuild

I'm trying to run a Sync from MSBuild (From Powershell) that also includes Pre Sync Commands.

Using PHP to group and display MySQL entries by week

php mysql group-by

I'm building a site with several 'one-liners'. These are added using a simple PHP5 form, stored in a MySQL 5 database. Each row has an 'id' (auto_increment), 'title', 'description', 'status' (1 or ...