Closed timurkhafizov closed 1 year ago
It would, and it would be very bad.
In fact Heroku recycles dynos and I believe we do see very brief moments where you're having two instances running.
I've been thinking about how to deal with this. For Heroku I think the easiest would be to declare the number of working dynos in ENV and distribute load that way. The next step is probably to have a more transactional way of "starting" a service and having dynos compete for locks on start, then try to rebalance at runtime automagically. That problem alone could be a great Ruby gem.
Basically we have https://github.com/schneems/the_lone_dyno which can help us to isolate thread in a single dyno while puma's workers can run in a multiple.
Did you ever count how much websocket connections server can handle in a standard Heroku dyno?
I think isolating workers to 1 dyno won't do much for slack-gamebot unless someone starts heavily using the API.
I think we should be able to do many hundreds at the very least. Right now I have an instance on http://playplay.io that isn't breaking a sweat with stable RAM at about 300MB (bot classes are singletons) with 100+ teams.
The constructs we need from each dynos perspective is:
The system should be stable, ie. the optimal number should be a little bigger than total connections / number of workers so that connections don't constantly get shutdown and restarted elsewhere.
Yeah, I was thinking the same. Anyway we should store connection ids somewhere then. It maybe Redis and we can just store bot token there or something similar.
The only thing I aware of is that we can't see if dyno crashed and did not update that info in Redis.
Probably it can be any another NoSQL DB providing persistence.
Slack-gamebot already has a MongoDB store, you can use atomic updates and https://github.com/afeld/mongoid-locker. Would love some PRs!
I've introduced https://github.com/dblock/slack-gamebot/blob/master/Procfile.heroku which can be used to split the web and the worker process, so now web ones can be scaled horizontally. You still don't want multiple workers.
As far as I see web sockets run in a single thread within web dyno. What if i need to increase dyno size? Will app open dup connections?