Comment by sunshowers

Comment by sunshowers 10 months ago

3 replies

This is why memory-bound services generally use languages without mandatory GC. Tail latency is a killer.

Rust's memory management does have some issues in practice (large synchronous drops) but they're relatively minor and easily addressed compared to mandatory GC.

foobarchu 10 months ago

In cases where java is unavoidable and you're working with large blocks, it is possible to sort of skirt around the gc with certain kinds of large buffers that live outside the heap.

I've used these to great success when I had multiple long-lived gigabyte+ arrays. Without off-heap memory, these tended to really slow the gc down (to be fair, I didn't have top of the line gc algorithms because the openj9 jvm had been mandated)

  • pkolaczk 10 months ago

    Managing off heap memory in Java is pain even worse than manual memory management in C. Unlike C++ and Rust, Java offers no tools for manual memory management, and its idioms like frequent use of exceptions make writing such code extremely error prone.

    • foobarchu 9 months ago

      ByteBuffers and direct memory make it possible.

      https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffe...

      But it is a pain and only really useful if you have a big, long lived object. In my case it was loading massive arrays into memory for access by the API server frontend. They needed to be complete overwritten once an hour, and it turns out that allocating 40% of system memory then immediately releasing another 40% back to the GC at once is a good recipe for long pauses or high CPU use