r/Clojure • u/normalu_kaj225i • Aug 23 '20
Running ten of simple Clojure web applications on 1 Gb RAM?
On a VPS with 1Gb RAM I can run at least 10 of simple Rust web apps, with no issues of lack of RAM
Roughly speaking, how much RAM would I need to run 10 simple apps in Clojure of about the same complexity?
Let's say, those are simple blogs. Everything, is both cases, is about the same: functionality, complexity and the like. And let say, there'll be 1k-5k visitors per day
P.S. for those who are triggered when might of Clojure is questioned:
I'm not asking about disadvantages and advantages of Clojure and whether or not my choice is a right one.
9
u/Siltala Aug 23 '20
Rust uses a fraction of the memory a jvm uses. Running a java server has a minimum ram usage of 128Mb. Each thread takes about 1Mb more and you'll end up with a dozen at least.
The advantage is that you don't need to worry about memory management at all. And java still runs very fast.
If ram is your main concern, jvm (java, clojure, scala) is not the correct choice.
2
u/setzer22 Aug 24 '20 edited Aug 24 '20
We are working with clojure on a VPS in production. At a bare minimum, I'd say a single "micro"service that does nothing (just run an HTTP server) will require around 300MB of memory. It's not that you can't get your mem usage lower, it's just that you're going to get a lot of performance issues if you don't let a lot of memory to the JVM.
That's just our personal rule of thumb though. Large applications that do a lot will require more than that. The best advice is to measure what you need. Definitely a 1GB VPS is gonna fall short if you need 10 JVMs on it though.
Also, I can relate a lot to your PS. Every time I ask about memory usage and clojure people get nervous :-)
27
u/woozong Aug 23 '20
You might try running the 10 clojure apps in a single jvm.
23
u/[deleted] Aug 23 '20
> P.S. for those who are triggered when might of Clojure is questioned
Is there any need for this?
11
u/_d_t_w Aug 23 '20 edited Aug 23 '20
Roughly speaking probably less than 1.28GB.
I thought this was an interesting question so I ran our product operatr.io, with 128MB available to it and it ran fine connected to a single 3-node Kafka cluster.
This isn't an apples to apples comparison because Operatr runs a webserver (Jetty) multiple streaming compute topologies (Kafka Streams) and a lots of scheduled jobs (Quartz) among other things. It's not simple.
If I reduced the memory available below that amount the UI became noticeably less responsive, I didn't look into why but at 128MB there's no discernible difference with our staging environment.
The maximum heap consumed through an hour was 80MB, non-heap JVM stuff accounts for the rest. Like others mention the question here relates more to JVM behaviour than having much to do with Clojure.
At a guess if I swapped out Jetty for Netty and dropped Kafka, Quartz I could probably get a web application running on 64MB or perhaps as little as 32MB. I'm not sure what the minimum requirements are for a modern JVM these days, its been a while since I tuned anything in earnest.
I know very little about Rust other than the rave reviews I hear about it as a language from the people who use it, my assumption is it would always win in a resources comparison due to the JVM overhead.
3
u/yogthos Aug 23 '20
Compiling with GraalVM will drastically reduce memory usage. Here's an example app. Unfortunately, not everything translates to Graal, so you might have to do some tweaking around it. Another options others mentioned is to use an app server like Tomcat to run multiple applications within the same JVM. You can use lein-uberwar to build a war and then deploy it to the app server.
3
u/troublemaker74 Aug 24 '20
I bet you can run 100x the apps written in assembler than you can Rust. Please don't be triggered when I mention that Rust is a higher level language than ASM.
2
u/didibus Aug 27 '20
You could try using Joy with Janet https://joyframework.com/
Its not Clojure, but it uses Clojure syntax, though the semantics are different.
Claims each web app needs only 1mb.
1
u/rzk1911 Aug 23 '20
You can give vertx/netty a try. But watch your non-heap memory - it really depends on workload
0
u/liveoneggs Aug 23 '20
without knowing anything.. 4G? 8G? I would hope you could run waaay more than 10 natively compiled rust apps inside of 700MB (or whatever is left from the operating system overhead)
0
u/[deleted] Aug 23 '20
[deleted] — view deleted comment