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!