-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java: linear solver memory leak #3684
Comments
this is swig generated code. Not sure what we can do. |
Can you try with com.google.ortools.modelbuilder ? The API is a bit different. It has 2 classes (model and solver). Model manipulation is very limited. But it should be lightweight, and all the modeling layer if pure java (outside of the model class). |
Unfortunately, our solver connector is too generic and cannot be easily simplified to use modelbuilder. Thank you, it allowed us to learn about this api! |
Hi Laurent -- |
I'm seeing similar behaviour:
Like @Opsiana I'm also on Anyone found a workaround/solution? I don't think this problem can be represented with FWIW, if any OR-tools maintainers wanted to hop on a video call at some point, pair debug/profile together, I'd be happy to do so! |
For anyone else reading this - we ended up solving this by switching off of or-tools, to clp-java (https://github.com/quantego/clp-java). We were using CLP under the hood anyways with or-tools, so they're both just Java wrappers of the same underlying native lib. Behaviour and performance seems to be identical between the two (for our use case, at least), but with clp-java memory usage stays constant and low, even under really heavy load, while with or-tools under identical load memory climbed straight up until OOM. |
I have ended up solving my issue 2 ways: I did move to ModelBuilder (is there Java docs on it btw? Had to figure out lots of things myself), and it did help a lot. Instead of my server crashing about twice a day, it started crashing once every 2 days. So moving to ModelBuilder alone did not fix the issue. What really did fix it (and it's been running fine for over a week with a lot more reasonable memory consumption) was setting these jvm flags: As I understand, the native code under or-tools uses the So if you are running the solver lots of times, memory gets allocated and de-allocated within those arenas but don't necessarily get released back to the OS due fragmentation and some technical reasons I don't fully understand. The trim forces the arenas to be locked and release memory back to the OS, so the locking has some downside which has been unoticeable in my use-case. This flag is only available since Java 17 so if you're on <17, setting Some resources if anybody wants to know more: https://www.algolia.com/blog/engineering/when-allocators-are-hoarding-your-precious-memory/ I hope this helps and maybe even helps or-tools developers find a way to get around this issue. |
The CpSolver we use has always had memory leak problems. Has anyone encountered similar problems? |
CP-SAT?
Le mar. 23 avr. 2024, 04:13, tukangzheng ***@***.***> a
écrit :
… The CpSolver we use has always had memory leak problems. Has anyone
encountered similar problems?
—
Reply to this email directly, view it on GitHub
<#3684 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACUPL3JEVAI4URWDA5PDKS3Y6W7WFAVCNFSM6AAAAAAVDXDZNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZRGI4DENJYG4>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
yes |
CP-SAT does not leak memory.
It uses a lot of memory, but does not leak.
Le mer. 24 avr. 2024, 10:40, tukangzheng ***@***.***> a
écrit :
… yes
—
Reply to this email directly, view it on GitHub
<#3684 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACUPL3I7ES62TJGG26PQWM3Y65VXBAVCNFSM6AAAAAAVDXDZNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZUGQYDOOJRG4>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
@Mizux, from what we have observed, it was not a memory leak. Just an avoidable consumption of memory used by the java.lang.ref.Finalizer thread and triggered by the presence of the finalize() method on MPConstraint/MPVariable classes. May be the issue title should then be: 'java: linear solver memory bloat' |
java: heap memory consumption
version: 9.4
There is an issue regarding the implementation of ortools-java classes
com.google.ortools.linearsolver.MPConstraint
andcom.google.ortools.linearsolver.MPVariable
.Both classes override the deprecated method finalize() resulting in a significant and unnecessary consumption of heap memory and process time. A 50% reduction of heap memory and 20% reduction of process time have been observed in our tests when removing those methods, since related instances were not map nor treated by the jvm finalizer.
Since in java, there is no control on when finalize() is called by garbage collection, a better practice to clean resources would probably be to explicitly call MPVariable.delete()/MPConstraint.delete() if needed.
Thank you for ortools!
The text was updated successfully, but these errors were encountered: