A trading engine needs tens of thousands of lightweight threads. Explain how tuning `-Xss` impacts total JVM footprint while keeping enough headroom for heap-based order books.

Java interview question for Advanced practice.

Answer

Each Java thread reserves stack memory up front. If the engine spawns 10k worker threads with the default 1 MB stack, you've committed roughly 10 GB of address space before allocating any heap. Profiling shows your call stacks rarely exceed a few hundred frames, so you can lower -Xss to 256 KB, freeing gigabytes for the heap and direct buffers. After changing the setting, stress-test the deepest code paths to ensure no StackOverflowError appears, and document the math so SREs understand the trade-off.

Explanation

Reducing -Xss from 1 MB to 256 KB saves ~750 MB across 3000 threads—but you must verify that call stacks still fit.

Related Questions