heroku multiple dyno socket.io - heroku

I am developing a node.js application with Socket.io and deploying same on Heroku Dyno. Socket.io is using RedisStore with its PUB/SUB. Socket.io client works perfectly fine with one dyno in heroku. But when I increase the number of dyno to more than one (say two), socket io client request does not work.
Please let me know if any specific configuration on client side is needed while setting up heroku for multiple web dyno having socket.io support.

Sorry, but heroku doesn't support sticky session and it's not supported by Socket.io
Sticky load balancing If you plan to distribute the load of
connections among different processes or machines, you have to make
sure that requests associated with a particular session id connect to
the process that originated them.
Using multiple nodes

There's a great thread in an issue on the engine.io github. Helped me understand the issue of sticky sessions, engine.io, and heroku a lot better.

Sticky Sessions are now supported by Heroku - but only if you join their development (beta) program.
In my experience Heroku works well with socket.io when combined with the Socket.io_Redis plugin and that enabled setting.

Related

Heroku: Pretending to be another domain?

First off, let me explain what I'm doing. I'm trying to build a website that replaces PokeVision, a service that connects to Pokémon Go servers and maps it.
Problem is, Niantic has blocked many popular hosting sites, including Heroku and Amazon. I use heroku.
Tldr; A server I'm trying to request and send data to is blocking my host, Heroku.
So... How would I pretend to be another domain? I'd say proxy but I'm not sure if that's the correct term in this case. Thank you so much!

django server replies synchronously to multiple ajax get requests

I have a web page who sends multiple ajax get request to a django server.
The server does some internet crawling for each request it gets and returns a response to the client once it finishes.
It seems that the server replies to the requests one after another.
I'm considering to send each request to a Celery worker to make the server's responses asynchronous but I'm not sure if it will solve the problem.
Also I'm using django on heroku and not sure how to combine celery with django on heroku.
The Heroku Django tutorial app uses gunicorn as the server, as you can see here:
https://github.com/heroku/python-getting-started/blob/master/Procfile
There is no special gunicorn config in the tutorial app, so you are running with gunicorn default settings. You can see what they are here:
http://docs.gunicorn.org/en/stable/settings.html#worker-processes
You'll note that this means you have a single worker process, of the sync type (i.e. no greenlets magic to enable concurrency within the single Python process)
It does say you can scale gunicorn to use multiple processes (still on a single Heroku dyno) by setting the WEB_CONCURRENCY environment variable, on Heroku this is easily done from your local shell using the cli tools:
$ heroku config:set WEB_CONCURRENCY=4
Gunicorn docs suggest setting this to "A positive integer generally in the 2-4 x $(NUM_CORES) range." Your basic Heroku dyno will be a single core.

How should I communicate with my server on Heroku if I don't know the port?

From what I have understood, Heroku assigns a port every time you deploy. I have an android app that is supposed to communicate with my server that I will deploy to Heroku.
But if I don't know the port, how do I make a POST call?
Does that mean Heroku is not suitable for this application?
I am using Java Spark, if that's relevant.
Your dyno internally uses a random port. Only the heroku router should communicate with that port.
You instead need to use the appname.herokuapp.com subdomain provided with your app, on port 80 or 443.
The router will then automatically forward the request to one of your dynos in random.
So yes, you can use heroku for your android app. Just make requests on the herokuapp.com subdomain like you would do anywhere else.

Can I have multiple heroku subdomains for my app?

Say you have two apps hosted on heroku: appA and appB. They will be accessible at appA.herokuapp.com and appB.herokuapp.com. Is there a way to "share" the subdomains? As in, can I have appA listening on both urls?
I suppose I could have appB forward all its traffic to appA, but I'm more curious if it can be done through some heroku setting.
Thanks!
No, this cannot be done through a heroku setting. You either need one of the two apps acting as a reverse proxy to the other app, or else you need a third server running a dedicated reverse proxy such as nginx.
Heroku support once suggested using a third heroku app as an nginx reverse proxy with a custom buildpack to accomplish this, although I decided not to go that route. It is unfortunate that there is no systematic support for multiple apps on the same domain at Heroku, but that would add significant complexity to their currently predictable and transparent routing platform (which is itself a non-configurable reverse proxy).

Heroku Static IP for SFTP

I have an application deployed to Heroku. I'm using a service that requires me to access their SFTP server using a static ip address. I know Heroku dynos are unreliable in this regard. I have successfully achieved this using the Proximo addon, however, its too expensive for the amount of traffic that I'll be sending (around 500 MB/month). Is there an alternate to this? I'm inclined towards using an EC2 instance but not quite sure what's required to create a proxy or whatever.
I'd go with an EC2 micro instance; pushing bits around doesn't really consume much CPU, so it's unlikely to get throttled. I would then give that instance an elastic IP address and communicate that address to the other service. (Whatever I choose to do later, I can always spin up another instance and associate it to that IP.) I would then deploy a SOCKS proxy (Dante?); SOCKS has pretty widespread application support, and it can handle SFTP just fine.
From here, there are a couple details specific to Heroku -- for one, you'll want to configure your proxy server's EC2 security group such that Heroku can access it (see Dynos and the Dyno Manifold). You'll also want to enable authentication on the SOCKS server, since granting Heroku access to your proxy grants everyone in Heroku access to your proxy. Then, heroku config:set SOME_SERVICE_SOCKS_PROXY=socks://user:pass#ip-10-1-2-3.ec2.internal, and have your application look for that environment variable and do the right thing.
You'll likely be paying $0.01/GB for intra-region data transfer between your proxy and Heroku, since statistically, your application will be in a different availability zone most of the time. Heroku dynos last about 24 hours in production, so while the exact location will dance around unpredictably, it'll probably land in the $0.008/GB range in aggregate. You'll also be paying for the micro instance itself (though reserved instances make them stupid cheap) as well as the usual AWS Internet data transfer rates.

Resources