Repository navigation
fix(layout): a deep stack for the ELK server, no waiting on a layout that overflowed it - #271
Merged
Merged
Conversation
…out that overflowed it ELK's network simplex walks a graph by recursion. On the megabyte a JVM gives a thread, a warm server overflowed its stack on a deep graph of 10,000 nodes. The server catches the error, logs it and never answers the request, so the layout waited out its whole timeout before it was refused or handed to elkjs. - The server's threads get a 64 MB stack (`ELK_SERVER_STACK`), unless the JVM options name one. With it that graph lays out in five seconds. - A server that still says a layout overflowed its stack is ended, like one out of heap. That fails the layout at once (3.5 s against the real server on a stack made too small), and the next layout starts the server again. Claude-Session: https://claude.ai/code/session_01EToj6NxqLABK3H5cucHNsY
- The server is shared by every diagram, and an overflow leaves it healthy but for one request. It is no longer killed on the spot: it is retired (the next layout starts another), answers what else it was asked, and is ended when the layouts that overflowed are all it has left (`ElkServerProcess.during`, which `SwitchingElk` asks the server through). - A layout that overflowed fails with the reason, on the status line and in the log, and with JVM options that keep the heap (`-Xmx2g -Xss256m`). - The error stream is read by the line: a line the pipe hands over in pieces is still heard, and the word inside another line (an id the server quotes) is no overflow. - A stack named in `JAVA_TOOL_OPTIONS` or `JDK_JAVA_OPTIONS` is left alone. Not done: a graph that overflows 64 MB costs a server start at each try. The cure is in the server (answer the error, as it answers a layout error), with the next build of its jar. Claude-Session: https://claude.ai/code/session_01EToj6NxqLABK3H5cucHNsY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while measuring the layout rates for #270.
The fault
ELK's network simplex walks a graph by recursion (
NetworkSimplex.tightTreeDFS). On the megabyte a JVM gives a thread, a warm server overflowed its stack on a deep graph of 10,000 nodes.GzipFramedSocketElkServercatches theStackOverflowError, logsSEVERE: [n] Error: nulland leaves the request open. The client then waits out the whole timeout (120 s) before the layout is refused or handed to elkjs.The fix, on the TypeScript side (the shipped jar is unchanged)
ELK_SERVER_STACK,-Xss64m), added to the JVM's arguments unless a stack is named already:-Xss…or-XX:ThreadStackSize=…in<ns>.layout.javaOpts,JAVA_TOOL_OPTIONSorJDK_JAVA_OPTIONS. The memory is reserved, and used only as deep as a layout goes.ElkServerProcess.during, whichSwitchingElknow asks the server through).-Xmx2g -Xss256m.Checked against the real server
Through
SwitchingElkand a realElkServerProcess, a deep graph of 10,000 nodes and a graph of 300 nodes asked for at once, two rounds each:-Xss512k(made too small)Earlier, with
-Xss64mgiven by hand, a warm server laid out 10,000 nodes in 5.4 s and 4.4 s and 20,000 nodes in 9.7 s, where the same warm server on the default stack overflowed. A cold server on a 1 MB stack did lay the 10,000-node graph out (three rounds): the overflow needs a server that has run many layouts.Not done
A graph that overflows 64 MB costs a server start at each try. The cure is in the server itself (answer the error as it answers a layout error, and keep running), which needs a new build of the jar and its copy in every product.
Checks
packages/diagram-server: 148 files, 1,153 tests pass. Type check clean.scripts/check-neutrality.shpasses.https://claude.ai/code/session_01EToj6NxqLABK3H5cucHNsY