Project-OSRM / osrm-backend

Open Source Routing Machine - C++ backend
http://map.project-osrm.org
BSD 2-Clause "Simplified" License
6.29k stars 3.32k forks source link

memory keeps increasing by python with cython or C wrapper #6051

Closed ZhiWeiCui closed 4 weeks ago

ZhiWeiCui commented 3 years ago

Hi:

Thank you so much for providing an amazing package.

Use two package(pyosrm and osrmcpy )according to the method this get start. When the route method is executed multiple times, it is found that the memory keeps increasing.My test code is as follows. When I put router in the for loop, the memory is stable. I want to know if there is a function or method in osrm's c++ api that only clears the cache.

Looking forward to your reply!

from pyosrm import PyOSRM, Status
from dpsolver.Util import randomly_location
import subprocess, os, re

from osrmcpy import OSRM, Coordinate

def convert_size(size):
    if size <1024:
        return size
    elif (size >= 1024) and (size < (1024 * 1024)):
        return "%.2f KB"%(size/1024)
    elif (size >= (1024*1024)) and (size < (1024*1024*1024)):
        return "%.2f MB"%(size/(1024*1024))
    else:
        return "%.2f GB"%(size/(1024*1024*1024))

def process_info():
    pid = os.getpid()
    res = subprocess.getstatusoutput('ps aux|grep ' + str(pid))[1].split('\n')[0]

    p = re.compile(r'\s+')
    l = p.split(res)
    info = {'user': l[0],
            'pid': l[1],
            'cpu': l[2],
            'mem': l[3],
            'vsa': convert_size(int(l[4])*1024),
            'rss': convert_size(int(l[5])*1024),
            'start_time': l[6]}
    return info

# location
location_start = randomly_location(10000)
location_end = randomly_location(10000)

# osrmcpy
DATA_DIR = '/mnt/d/Data/osrm/bicycle/ch'
OSRM_DATASET = os.path.join(DATA_DIR, 'china-latest.osrm')
router = OSRM(OSRM_DATASET.encode('utf-8'), contraction=True)

# pyosrm
# router = PyOSRM(use_shared_memory=True, algorithm='CH')

for start, end in zip(location_start.values(), location_end.values()):
    result = router.route([start[::-1], end[::-1]])
    print(process_info())
danpat commented 3 years ago

@ZhiWeiCui I have not observed these kinds of leaks in the C++ layer - that tells me that it's likely a problem with PyOSRM or osrmcpy - you might try opening a ticket in one of those repos instead of here.

There is no cache release function in the C++ interface - there is no internal cache.

github-actions[bot] commented 1 month ago

This issue seems to be stale. It will be closed in 30 days if no further activity occurs.