News for hackers. Stuff that matters.
Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by nvarsj on Wednesday August 05, 2020 @09:22AM (#24060476)
> Who was it that turned GC off entirely, minimized allocation and just restarted their VMs when they ran out of RAM every couple of hours, was that Netflix?

This was common practice in trading firms that got on the Java hype train. Turn off GC and just restart the JVM outside of trading hours.

> Either way. It makes me excited for Rust and the languages it'll inspire, all this labor gone away.

The JVM gives GC a bad name. There are plenty of GC languages which don’t have the level of pain of hotspot except in extreme cases. For the vast majority of GC languages you never even think about it. Rust / C++ are great when you need full control but it’s not necessary for most things.

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by pron on Wednesday August 05, 2020 @10:11AM (#24060926)
No runtime has a better GC than Java's, certainly in the current version (14) which is worlds better than Java 8. The reason you don't think about it in other languages is because if you use other languages, you probably don't care too much about performance in the first place.
Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by nvarsj on Wednesday August 05, 2020 @10:53AM (#24061453)
So if I care about performance, I would use the JVM? I spent years as a performance engineer on HFT trading systems tuning JVMs. It’s possible to get very good performance on the JVM, but it is also hard and for the layman almost impossible. Yes, it has great throughput, but only because it has to. The design of hotspot / JVM and the languages that run on it encourages massive heap allocations of gigabytes a second. I can’t think of any other language or runtime that is comparable in terms of its memory bloat. Even if you control allocations, and have happy path GCs, hotspot GC still causes occasional pauses of 10-100s milliseconds. And this is considered good.

I know that lots of people have built careers on the JVM and defend it vigorously. Whenever I make a comment that is negative on the JVM, I always get downvoted without fail on HN. I used to be one of these people, after all, so I can relate.

If I truly cared about performance these days, I’d use C++ or Rust. Otherwise, I’d use a language like golang with reasonable default GC behavior and allocation patterns - where I know the daemon I write won’t use more than 100-200Mb, and probably even less, and will typically have sub-ms pauses. I think even most scripting languages, like Ruby/Python, have reasonable memory usage and GC patterns for web development, but I’m not as familiar with them.

I probably care more about energy consumption these days though. And again, the JVM is the worst offender. The average developer building a Java web app will create something which consumes gigabytes of memory usually. These apps tend to spend the majority of their CPU time allocating and GCing memory. I can only guess how much server time has been consumed to satiate the memory hungry needs of the JVM.

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by pron on Wednesday August 05, 2020 @10:57AM (#24061508)
> So if I care about performance, I would use the JVM?

No. If you use the JVM you might well care about performance. If you care about performance, you should consider the JVM.

> I spent years as a performance engineer on HFT trading systems tuning JVMs.

The JVM is not designed to give you 100% performance (of the ideal offered by the hardware). It's designed to give you the easiest means of achieving ~95%, provided you're OK with some nondeterminism.

> I’d use a language like golang with reasonable default GC behavior and allocation patterns - where I know the daemon I write won’t use more than 100-200Mb, and probably even less, and will typically have sub-ms pauses.

You'd be wrong, because JDK 14 will most likely give you substantially better performance than Go out of the box; JDK 15 and 16 even more so.

BTW, the footprint and performance profile of JDK 14 is worlds apart from JDK 8. The JVM has been undergoing some very big changes in the last couple of years.

> And again, the JVM is the worst offender

Nope. https://greenlab.di.uminho.pt/wp-content/uploads/2017/09/pap...

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by nvarsj on Wednesday August 05, 2020 @11:24AM (#24061839)
Thanks for the paper. The data tables for it just proves my point. For example, in the binary-trees test, Java used 1120 Mb. Go used 228, Rust used 180, Lisp used 373, Haskell used 494 Mb. Only Jruby and Erlang seem to require more memory usage. If a webapp performs similar to this experiment, I could rewrite it in almost any other language and I’d cut the required number of servers in half or more.
Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by pron on Wednesday August 05, 2020 @11:41AM (#24062037)
Java absolutely requires more memory; less so in 14, but still. That does not, however, make your point about either performance or energy, both of which are wrong.

> If a webapp performs similar to this experiment, I could rewrite it in almost any other language and I’d cut the required number of servers in half or more.

Nope. Because you gain in performance where you lose on memory. If you add more RAM, you'd pay for less hardware and consume less energy.

Anyway, if you last experienced Java in version 8, try 14. It's not what you might remember. You'd likely see a 10-40% reduction in cost-per-transaction, plus very low pauses with the new GCs. OpenJDK's VM in 14 is just significantly different from what it was in 8.

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by merb on Wednesday August 05, 2020 @05:47PM (#24065985)
well no matter what you are trying to say, but without valhalla and other techniques to reduce allocations java will always be slower than the languages the other poster said.

no matter how good a gc gets, if it does need to do double the work of another gc it is not a problem of the gc. it is that too much allocation is needed even for simple things. java tried to tune their gc over and over instead of just fixing the problem. allocations.

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by pron on Wednesday August 05, 2020 @08:01PM (#24066906)
> java will always be slower than the languages the other poster said

That's true, and while Valhalla will help close the gap, it is important to understand that Java's goal is not to be the fastest language, but to be the language where it's easiest to get to 95% of full performance potential. I don't think any other language achieves that as well as Java. The question, then is how much you're willing to pay for that extra 5%.

In other words, for every Java program X, there exists a C/C++ program Y that's at least as fast. But is the cost of writing Y worth it given the particular performance benefit? The reason Java is so popular is that the answer is very, very often no. And remember that the lower Java costs are not just in the "coding costs" of writing and maintaining, but also in observability. These days, thanks to the Java Flight Recorder, Java gives you unparalleled insight into what your application is doing for very little overhead.

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by merb on Thursday August 06, 2020 @01:12PM (#24073038)
well it shouldn't be a rant. for my company java would've been fast enough. however we invested heavily in dotnet core, since it's easier to scale people in our region with dotnet.

we are basically struggeling to find people in the java domain, the amount of people with c# knowledge in my area is so much bigger.

---

however I'm personally a heavy java user (or scala should I say) unfortunatly the more things I did in c# the more I missed stuff especially in plain java. I thing the oracle takeover of java held the language back a bit for a few years. I mean if I look at the releases, they started to catch up with their new model, etc. which is good.

and I think what java these days are missing is a project like django/ror or aspnet.core which drives the web forward with a fully integrated web framework that does not suck. don't get me wrong spring looks promising, but it tries to fullfil every role by being "flexible" which it probably shouldn't be. enforce something. give us a nice little ORM that is not enterprise, look at linq. and especially don't be so enterprisy.

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by pjmlp on Thursday August 06, 2020 @03:05AM (#24068760)
GUIs are a good example of that, once C++ ruled in such domains, now managed languages own it, with C and C++ left for those 5% doing the glue code with OS drivers and 3D APIs.
Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by pythonaut_16 on Wednesday August 05, 2020 @11:31AM (#24061937)
You're not really refuting the points so much as just saying "You're wrong".

Granted the parent was anecdotal with their own experiences too, you could at least address the points. E.g. to the point of achieving 100-200Mb daemons, you might reference what RAM footprint you typically expect/experience from a similar program running in JDK 14-16. Rather than just:

> You'd be wrong, because JDK 14 will most likely give you substantially better performance than Go

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by cogman10 on Wednesday August 05, 2020 @10:45AM (#24061351)
* better GCs (plural)

Probably the best thing about the JVM that, AFAIK, no other platform does is it gives you an option for which GC you use. Not only is that an option, but you are spoiled with options. ZGC, G1GC, Shenandoah, The parallel collector, the serial collector. Pick the right one for the job!

But beyond that, they are infinitely tuneable (Not that you should usually). Again, not something that almost any other platform offers.

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by saberience on Wednesday August 05, 2020 @11:34AM (#24061959)
Dotnet's GC is way better than Java, Java has been trying to catch up in recent years but it's still miles off.
Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by pjmlp on Wednesday August 05, 2020 @01:11PM (#24063119)
I do both since they exist, in no way is .NET GC able to handle multi-TB heaps with ms pauses.

What helps .NET is the design since the early days to support value types and the introduction of Midori learnings into C# 7 and later for low level programming.

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by darksaints on Wednesday August 05, 2020 @09:26AM (#24060498)
I'd say it's more the language design than anything. Heap allocating everything, and then throwing in inheritance 30 levels deep makes for some very poor GC behavior.
Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by wokkel on Wednesday August 05, 2020 @09:49AM (#24060690)
What relationship do you see between inheritance and GC ? Creating An instance of some object 30 levels deep in the inheritance chain does not allocate 29 extra objects.
Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by darksaints on Wednesday August 05, 2020 @10:11PM (#24067542)
It's not always that simple. For example, if you inherit from a class that has private members, you are actually going to allocate both the parent and child.

https://stackoverflow.com/questions/27813539/what-happens-in...

Also, if you don't mark your methods and classes as final, you're gonna be allocating functions everywhere as well.

Re:Sub-10 ms Latency in Java: Concurrent GC with Green Threads by haxen on Thursday August 06, 2020 @01:37AM (#24068396)
> you are actually going to allocate both the parent and child.

You're going to allocate a single memory block that contains all the state of that object, which of course includes the superclass state. But that has nothing to do with the depth of the class hiererarchy.

> you're gonna be allocating functions everywhere as well.

If by "function" you mean a "Java method", they are code and not data, and they are not allocated dynamically at all.

In any case, this would have nothing to do with them being private or final. These options decide whether there will be an invokevirtual or invokespecial instruction to call them, where invokevirtual has more cost only before getting JIT-optimized.