Memory consumption VRPTW solver

42 views
Skip to first unread message

Denzel

unread,
Oct 6, 2025, 3:57:36 PM (10 days ago) Oct 6
to or-tools-discuss

Hi all,

I've been analyzing resource usage in my Python implementation and observed that it consumes high amounts of RAM - over 5 GB - when repeatedly sending requests to an endpoint that triggers the Vehicle Routing Problem with Time Windows (VRPTW) solver. It plateaus here so it doesn't point to a memory leak, but the memory footprint is still concerning.

After profiling, I’ve isolated the issue to the underlying C++ library of OR-Tools:

  • All Python objects are properly released after each request, except for the distance cache maintained by OR-Tools.

  • The number of objects tracked by Python’s garbage collector increases in direct proportion to the size of the distance cache.

  • I have eliminated other C libraries as potential culprits for untracked memory growth.

My initial hypothesis was that the OR-Tools C++ solver might be causing heap fragmentation, so I have been experimenting with alternative memory allocators that favor mmap-based storage over sbrk to reduce fragmentation. However, though especially jemalloc seemed promising at first, it eventually reached comparable memory usage after several hours of runtime.

I’m particularly interested in hearing from others:

  • Have you encountered similar memory growth patterns with OR-Tools in Python?

  • How have you addressed persistent memory retention, especially in scenarios with repeated solver instantiations?

  • Are there recommended strategies to forcefully release or limit the internal caches of the VRPTW solver in C++ or via the Python wrapper (pywrapcp)?

Any insights, patterns, or best practices would be greatly appreciated.

Thanks in advance!

christoph...@gmail.com

unread,
Oct 6, 2025, 4:51:35 PM (10 days ago) Oct 6
to or-tools-discuss
Yes, we had also experienced memory retention issues. We were using a relatively old version of the c# API, however (Google.OrTools.ConstraintSolver; version 6.7.xxxx.yyyy) and it occurred when we did intensive performance testing with tens of thousands of test cases, each repeated multiple times to get statistical significance. We had also localized it to memory allocated by the c++ component. As a workaround for the tests, we portioned them into groups of several hundred and then killed the session after each group and started a new one. Since the productive version didn't have that kind of load and wasn't running into problems we didn't pursue the matter further. 

Denzel

unread,
Oct 7, 2025, 8:33:23 AM (9 days ago) Oct 7
to or-tools-discuss
Hi Christoph, thank you for your message. I am wondering if this is a standard pattern in this community then to combat this, to use a RPC for ortool calls or graceful reloading of your API every X requests?
Op maandag 6 oktober 2025 om 22:51:35 UTC+2 schreef christoph...@gmail.com:
Reply all
Reply to author
Forward
0 new messages