Scaling/vCPU core usage of Directus in Cloudron
-
Hello everyone,
I want to use Directus installed via Cloudron as data and content management system for a web project. I was wondering how many concurrent requests this setup could handle with a server that has multiple virtual CPU cores.
This led me to the question how scaling in Cloudron and Directus actually works.The Directus backend runs with node and is single threaded. In the following GitHub discussion the tech lead of Directus, Rijk van Zanten, says that directus has no vertical node process scaling and that they use horizontal scaling of multiple container instances. https://github.com/directus/directus/discussions/9781#discussioncomment-1645326.
When I get the idea of Cloudron right, then there is one single container running for every app and there is no option to run multiple container instances of one app.
Actual Question
So am I getting it right that Directus on Cloudron always uses only one virtual CPU Core?
So when I have a server with 4 vCPUs and run Cloudron with only Directus installed on it, 3 vCPUs of them are needless?Thanks for any help
Philipp -
-
-
-
@pbischoff by default, a container uses all cores. Of course, an app can use multiple cores at the same time, only if it's designed to (with multiple threads/processes).
I think your hunch is correct. Directus on Cloudron will only use one core. Atleast for nodejs, the usual way this is solved is by using cluster mode.
-
@girish thank you for your answer.
I did a little bit of load testing and that confirmed me again, that only one vCPU core is used.
But this is a problem for almost every node.js app of the cloudron App Store, isn't it? Do they all use only one vCPU core?
Then I came across this project pm2 https://pm2.keymetrics.io/, a process manager for node.js with integrated load balancer. I've never took a deeper look on how you package your Apps on Cloudron, but would it theoretically be possible to include pm2 in the Directus app setup for Cloudron or do you have any conditions that forbid "external" dependencies like pm2. Or are there any other obstacles that would speak against that?
I was thinking about playing a little bit around with it.Thanks for your help again and best regards
Philipp -
@pbischoff said in Scaling/vCPU core usage of Directus in Cloudron:
But this is a problem for almost every node.js app of the cloudron App Store, isn't it? Do they all use only one vCPU core?
Apps like NodeBB (this forum) support so called cluster mode - https://nodejs.org/api/cluster.html . Essentially, this creates worker threads to spread load across CPU. This is part of nodejs.
But to keep in mind, nodejs by itself can handle quite a bit of parallelism with just one CPU. Most of the work done by the main process is just http request processing. This is usually I/O bound and not CPU bound. Nodejs being asynchronous can handle requests in parallel in just one process quite easily. We are talking about 1000s of requests a second.
Many other nodejs apps like Cloudron code itself, peertube, offload the processing of static assets to a side installation of nginx. So, when downloading images/css files etc, it doesn't even hit nodejs. When node code has to do heavy work, it usually just puts it in a queue and the queue handler is a separate process (which can thus be restarted and killed easily). The queue handler will use another cpu core.
For directus, I am not an expert on the app. But, you want to maybe use some worker thread or queue or something like that to make use of more CPUs.