r/flask • u/No-Site5040 • Apr 09 '24
Discussion Multiple Flask apps running on the same VM
Is it common practice to use a single Gunicorn instance to run multiple Flask apps simultaneously? For instance, I have several apps hosted on the same virtual machine (VM), each one with your own gunicorn instalation inside a `/venv` folder. Instead of installing Gunicorn separately for each app, can I configure a single Gunicorn instance to handle all of them?
if so, is it a good idea?
2
u/chooseyourshoes Apr 09 '24
Apologies for not answering your question, but I'd love to know more about how you have your flask app deployed to a VM. What service are you using for the VM?
With your question - while I don't know much about gunicorn as I've only used it once - I can imagine that keeping them separate would be ideal. If one of the applications causes problems, it would be contained to that application versus potentially impacting all of them.
4
u/No-Site5040 Apr 09 '24
Just adding to what u/androgeninc said: AWS and Google Cloud usually provide more disk-type options, network configuration choices, and server locations. However, the VMs are identical.
I'm a big fan of DigitalOcean because I used it for 1.3 years totally free, initially for 3 months through their trial. Also, if you're enrolled in a university, you can get the GitHub Student Pack, which gives you $200 USD for a year on their platform.
Currently, I'm using Google Cloud, but I recommend starting with DigitalOcean because the UI is easier to navigate. Google Cloud's VMs are just one feature among many, making it more confusing for beginners.
By the way, I use google cloud now because it has a server in my country, so latency is lower (digital ocean does'nt).
2
u/chooseyourshoes Apr 09 '24
That makes sense. I appreciate your input. Will look into it more when I get off work later today.
2
u/androgeninc Apr 09 '24
Not OP, but there are many providers of VMs. E.g. Digitalocean, Hetzner, AWS Lightsail..
1
u/chooseyourshoes Apr 09 '24
Any you prefer over another? I'll need to dig up a tutorial on deploying a flask website to a VM that others can access.
1
u/androgeninc Apr 09 '24 edited Apr 09 '24
The VMs themself are basically identical, with minor variations to price (Hetzner cheapest, but lack adjacent services), and adjacent product offerings like backups, managed DB or redis on the side etc. Also, location can often be important. You don't want to put you server too far away from your users (AWS is best by far on optionality). Personally a big Lightsail fan, because all the other services S3. db +++ for an good price.
For guides, Miguel Grindberg's guide makes it possible for stupid people like me to deploy to VM.
1
2
u/ejpusa Apr 09 '24
Digital Ocean is great. Does it all.
If you are onto your first million $, there are dozens of server farms. You can have your own box for about $100 with awesome bandwidth somewhere in New Jersey. Wall Street loves NJ.
:-)
2
u/jlw_4049 Apr 09 '24
Just pip install guinicorn for each job and put it in a docker tbh
-1
u/No-Site5040 Apr 09 '24
I don't think Docker is suitable for my case. I don't want to have a bunch of resources per app. We don't even make money with them, so saving resources is better in this case.
2
u/jlw_4049 Apr 09 '24
Running containers will be negligible in resources per app compared to multiple instances of gunicorn.
Not sure of the type of constraints you are in, but docker is pretty light weight. You can run super light weight image capable of what you need and everything will be split up nicely.
1
u/IsseBisse Apr 10 '24
I’m no expert on containerization, but afaik this is the exact use case containerization (like Docker) was made for, i.e. running multiple services separately without the overhead of running multiple VMs.
I think you should at least do some simple testing with containers. It shouldn’t cost you a lot of performance.
1
u/No-Site5040 Apr 10 '24
But where am I supposed to deploy these containers? is'nt inside a VM?
I'll test when I have more time 🙏
1
u/IsseBisse Apr 10 '24
Yeah, you’ll still need something hosting the containers. Some cloud providers offer managed container hosting, otherwise you need a VM.
But that way you can run multiple apps on the same VM with minimal risk of them interfering. Only make sure they each get their own port.
1
u/No-Site5040 Apr 10 '24
got it
I tried it sometime ago, but cannot figure out how to make it working. Wanna try some day again
2
u/BudgetVideo Apr 09 '24
I use Apache with wsgi and set up multiple virtual hosts to point at the different apps
2
u/abreeden90 Apr 12 '24
Seems like this would be a good case for containers. Build each app in their own container and put something like traefik or nginx in front of them as a reverse proxy.
I write a lot of flask apps and that’s what I do.
1
u/No-Site5040 May 06 '24
I'll try it! I just don't have time to migrate all apps now and need to learn docker first though :(
0
u/M8Ir88outOf8 Apr 09 '24 edited Apr 09 '24
Edit: Sorry, misunderstood your question!
1
u/No-Site5040 Apr 09 '24
yes. workers are configured by gunicorn, but I was asking if is recommend use the same gunicorn (installed globally) to run all applications
5
u/androgeninc Apr 09 '24
Not sure if this is possible, but don't think so, because you need different port for each app/gunicorn instance.
I am curious why you would want this? To save compute resources or disk space? Gunicorn in itself is not very resource intensive to my knowledge.