Why low-latency Java still requires discipline?

(chronicle.software)

38 points | by theanonymousone 2 hours ago

6 comments

  • motoboi 1 hour ago
    I found claude and GPT very helpful on this, because java have a very sofisticated monitoring harness. Just ask the agent to connect to the running application (on kubernetes or whatever) on prod and do a java flight recording then analyze allocations.

    I managed to improve some applications of ours from several garbage collections per second to several minutes between collections. That _really_ improves p99.

    • haglin 15 minutes ago
      I work on OpenJDK, so I may be biased, but I’ve also found that JFR works really well with LLMs.

        $ java -XX:StartFlightRecording:maxsize=10M,filename=dump.jfr -jar app.jar
      
        $ jfr view all-views dump.jfr > report.txt
      
        $ jfr print dump.jfr > all.txt
      
      Then ask Codex, or whatever AI tool you use, to analyze report.txt for issues and use all.txt to dig deeper, if needed.
    • exabrial 3 minutes ago
      Take a peek at jolokia if you've never used it :) Attach it as a JVM agent to _any_ process to expose it's JMX attributes as http calls, and it even gives you a neat little console to log into.

      If you want to collect these, telegraf has a jolokia plugin. It's an incredible combination!

    • declan_roberts 27 minutes ago
      That sounds like a great idea. What kind of prompt do you use?
      • motoboi 22 minutes ago
        Nothing much smarter than run the agent in the project folder, make sure it has means to interact with production (like configured kubectl) and ask it to jcmd the hell out of it.
    • wmichelin 49 minutes ago
      [dead]
  • treyd 9 minutes ago
    On mobile the whole page text is aligned center which makes it really hard to read.
  • chuckadams 1 hour ago
    I get that blog posts often advertise a company's products, but this one had absolutely zero content other than advertising.
  • pjmlp 29 minutes ago
    Even C requires discipline to write low latency code, if you think otherwise, you never used a profiler.
  • dominicrose 1 hour ago
    page doesn't load "En attente de la réponse de chronicle.software."
    • PaulHoule 1 hour ago
      + low latency anything requires discipline. if you lose 5ms you can't get it back.
  • opentokix 43 minutes ago
    How about not using Java? Then you can have low latency.

    Average go, rust, c++ and c will outperform amazing java programs, and the former will also be way way more easy to run, troubleshoot, interpret logs from.

    Java is usch garbage in every stack.

    • SeanLuke 27 minutes ago
      I need a UI which runs well on Windows, MacOS, and Linux, without having to build three different ones. Swing is still easily the best, most consistent, and most native-feeling cross-platform environment. It's much better than QT and GTK in most respects. And Java also runs elegantly on a little platform you may know as Android. I have high hopes for go and rust. But until they have mature UIs, they're out (for me).

      C and C++ are dangerous languages filled with security failings and footguns, and no modern app should be written in them.

      It's been my experience that well-written low-level Java code runs at about 75% the speed of good C code. (Of course lazy coders write in cushy Java which is much slower). When written efficiently, Java's biggest slowdown lies in array access (C and C++ array access is fast because it is very, very unsafe). But Java makes up for this in having a GC which will coalesce related objects into the same page and so take advantage of cache coherency effects in ways malloc and free cannot possibly do. I have some allocation-heavy algorithms in Java which are, as a result, significantly faster than well-written equivalents in C.

    • motoboi 35 minutes ago
      Rust? OK.

      C++ or go? Then you'll have to take a very closer look, because the java JIT is wonderful. A masterpiece of several hands, actually.

      • bluGill 21 minutes ago
        If low latency is your goal than you don't want JIT. JIT has two issues in low latency, first the first time through your code isn't compiled yet and so you get high latency. Second, it optimizes for the common case, which means when you hit an exception that exception will be higher latency because everything hits a branch miss.

        Of course we are talking generals here. Sometimes the above is acceptable and Java/JIT is just fine. Sometimes it is unacceptable and you cannot use Java/JIT. Know your domain.

        Of course in all cases (C, Rust, C++), you have to understand the system and what it is doing. Every language has a standard library that will do things that are not low latency on you. You have to know which library functions will do what, memory allocation and copies are both things that code often does without thought that are incompatible with low latency. No matter what you need to know what your language does that is against you.

        • re-thc 5 minutes ago
          > If low latency is your goal than you don't want JIT. JIT has two issues in low latency...

          There's startup "AOT cache" via Leyden that speeds up startup. Isn't native speed up it's quite a big boost.

          Then there's GraalVM that does give you a native image. Real AOT.

    • pjmlp 28 minutes ago
      It is a matter of skill.
    • cavoirom 35 minutes ago
      yes, until you need debugging.
    • re-thc 23 minutes ago
      > Average go, rust, c++ and c will outperform amazing java programs

      Not true. Many benchmarks have shown otherwise. it is at least competitive in many areas.

      > and the former will also be way way more easy to run, troubleshoot, interpret logs from

      No language will save you from poor logging practices. If you log every debug log it's not Java's problem. No 1 says you have to log the full stack trace if that's your concern. You can configure / strip / do anything. Learn to use the stack.

    • pestatije 13 minutes ago
      yeah...no, try low latency when running out of memory, or with more CPU-bound threads than cores...discipline vs almost impossible