Hm, I how can we take a 175 LOC project as something relevant in any way?
Hm, I how can we take a 175 LOC project as something relevant in any way?
I wish they provided the JVM startup info and stats to compare. Maybe JVM's resource usage could be shrunk, too.
The number of LOC has no bearing on how much memory something will consume. For all you know the service could just be poorly implemented.
And not sure what JIT space is.
Still, that's time and effort, and in Go you get all of those things for free. There's far fewer janky edges (I spent hours figuring out the problems with signed jars, shaded jars, and symlinks when trying to deploy)
_This particular_ 175 LOC Java project takes up an enormous amount of memory. For all you know it was just coded poorly and the Go one is a bit more reasonable.
> the JVM is this super-heavyweight thing that's really just inherently inappropriate for a lot of applications.
The JVM introduces overhead but not so much that you can make these sorts of extrapolations.
I'm not going to install the JDK just to verify, but feel free to report back if you get different results.
Not sure what the golang overhead is, by comparison.
1. the JVM itself imposes a high floor (hotspot, many shared libs loaded, ...)
2. the Java language is full of overhead at every level (boxed types are a pet peeve of mine)
3. the Java ecosystem has a tendency to regard memory as an inexhaustible resource, which lead a lot of waste in many 3rd party libraries
The core point is that optimizing this particular Java program (and the others that followed) would have been more time-consuming than a Golang rewrite and would have probably increased the complexity whereas a Golang rewrite reduced it.Optimization was the original goal, increased maintainability was a pleasant result.
Value types would help so much with this issue. I know they're coming one day. I hope Java/JVM can replicate memory efficiency and cache coherence of C++ std::vector for small objects.
There are enough solutions (e.g. servlet containers) where you can run multiple services in one VM, with isolation, and security hardening (using security manager).
With regards to memory footprint - the difference here is that Java uses a minimum and maximum heap size that can be tuned with parameters. This has downsides (typically more memory use) and upsides (upper bound on the maximum memory use of a process).
Most notably, all services will share the same heap, so one ill-behaved service can bring down all the other services. The only way to prevent this, is to run each service in a separate VM.
And at that point, you are once again comparing one Go runtime per service with one JVM per service.
If you're running a Go app in a container, you can use also tune the upper bound on memory use by restricting the available memory for the container.
The whole Netflix is based on the JVM and Java. They are enormously big, they have high CPU and I/O requirements in many cases, and yet, they manage well on Java.
I'm not a big fan of Java as language (to say the least), but the JVM as a runtime is very-very sophisticated.
You just need the Server JRE which is 57MB tarball + 157MB uncompressed.
The other servers that went through a rewrite also ended up being significantly smaller in go but that's a story for another day.
But just because you wrote just 200 LOC, that doesn't free you from bugs and regressions in the remaning thousands of lines of code you rely on.
As an anecdote, at a previous work place we had a program that parsed CVS-files for import into an SQL database. This particular program was written by a researcher (meaning: someone with great domain knowledge, but perhaps not a very strong software engineer) in Visual Basic.
The program worked great, but we had to upgrade the server that ran it to newer versions of windows, and at some point needed to recompile the code (I don't thing this was releated to a bugfix, IIRC it was simply a run-time/linking issue).
As it turned out, the code compiled, but the program didn't work -- MS had changed the API for CVS handling (probably fixing a bug). I don't recall exactly what it was, might have been how floating numbers were parsed/handled, possibly an edge case with Norwegian/English localization or something.
Net result, we had a pretty though debugging job on our hands, for a very small program...
(I feel a bit bad for singling out MS for this -- as I understand it, they are generally very good about maintaining backwards compatibility -- even to the extent that that becomes a problem. I guess we just hit on a corner case with our use-case and this particular old VB code).
I suspect the same (or greater) linecount gains could have been gotten by using a language even more pithy. How much you wanna bet the equivalent Clojure or Scala versio would be half again as many lines?
263 lines?
Clojure is quite terse, and Scala can be when you're using the right toolsets.