nidi3 / graphviz-java

Use graphviz with pure java
Apache License 2.0
937 stars 107 forks source link

Graphviz cannot render a large number of nodes #192

Open luongbaotin7777 opened 3 years ago

luongbaotin7777 commented 3 years ago

Hi Bro, today I use Graphviz library for my java project. But it cannot render a large number of nodes. I wrote a createNode function and passed it into Graph. But when I render it not working, the API is almost destroyed. Note: I have about 822 nodes. Please help me, I really need this help. Thank you very much. image

luongbaotin7777 commented 3 years ago

With 95 nodes, my API still works fine.

nidi3 commented 3 years ago

Hi As a quick idea, you can try setting the memory with Graphviz.fromGraph(g).totalMemory(100_000_000).render(...

luongbaotin7777 commented 3 years ago

Hi As a quick idea, you can try setting the memory with Graphviz.fromGraph(g).totalMemory(100_000_000).render(...

yup bro, I got an out of memory error in Graphviz exception. When I set totalMemory (1000000000), I still get the error out of memory :(, so sad.

MadaManu commented 3 years ago

I faced the same problem, running at around 100 nodes. Worked fine with about 20-30, then any higher number it failed with:

205 Exception in thread "main" guru.nidi.graphviz.engine.GraphvizException: Got Error: 'TypeError: Module.print is not a function'. This is probably an out of memory error. Try using the totalMemory method.

However, after attempts at increasing java heap size, and setting total memory to MAX_INT, I didn't want to give up. I saved the generated dot in a text file, and dumped it into Graphviz Online. Sure I selected the engine I was using and I received the following error:

abort("Assertion failed: np->cells[1], at: maze.c,313,chkSgraph"). Build with -s ASSERTIONS=1 for more info

Did a bit of googling, just to figure out from this issue (Graphviz Gitlab Issue 1408) that there is a bug within orthogonal layout code. I switched to using POLYLINE instead of ORTHO and everything works ok now.

You could be facing something like this as well. I guess, from this project's perspective we could improve on the error handling and maybe include the underlying error from the engine in the error we log, instead of assuming it's a memory problem.

nidi3 commented 3 years ago

Thanks @MadaManu for pointing this out. With version 0.18.1 messages from the engine are logged directly. @luongbaotin7777 I was not able to reproduce your problem, could you try again with version 0.18.1 to see if there's a better logging message now?

MadaManu commented 3 years ago

@nidi3 Great point indeed. With regards to the example I've outlined above, upgrading to 0.18.1 doesn't even fail anymore using ORTHO. (I was previously using 0.18.0)

luongbaotin7777 commented 3 years ago

Thanks @MadaManu for pointing this out. With version 0.18.1 messages from the engine are logged directly. @luongbaotin7777 I was not able to reproduce your problem, could you try again with version 0.18.1 to see if there's a better logging message now?

I used ORTHO and total memory, it worked. thank you.