Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Communicating between two processes on heroku (what port to use)

I have a Procfile like so:

web:     bundle exec rails server -p $PORT
em:      script/eventmachine

The em process fires up an eventmachine with start_server (port ENV['PORT']) and my web process occasionally needs to communicate with it.

My question is how does the web process know what port to communicate with it on? If I understand heroku correctly it assigns you a random port when the process starts up (and it can change if the ps is killed or restarted). Thanks!

like image 888
Brian Armstrong Avatar asked Mar 05 '12 05:03

Brian Armstrong


2 Answers

According to Heroku documentation,

Two processes running on the same dyno can communicate over TCP/IP using whatever ports they want.

Two processes running on different dynos cannot communicate over TCP/IP at all. They need to use memcached, or the database, or one of the Heroku plugins, to communicate.

like image 69
ChrisPhoenix Avatar answered Sep 30 '22 13:09

ChrisPhoenix


Processes are isolated and cannot communicate directly with each other.

http://www.12factor.net/processes

There are, however, a few other ways. One is to use a backing service such as Redis, or Postgres to act as an intermediary - another is to use FIFO to communicate.

http://en.wikipedia.org/wiki/FIFO

It is a good thing that your processes are isolated and share-nothing, but you do need to architecture your application slightly differently to accommodate this.

like image 45
Neil Middleton Avatar answered Sep 30 '22 13:09

Neil Middleton