Hi,

there seems to be memory leaks in the context of reading of xml-files.

I have run the scenario twice with a simulation time of 5 resp. 10 seconds:

The output of valgrind (a memory checker under linux) shows an increasing number of lost bytes:

valgrind28244.log (5 sceonds)
==28244== LEAK SUMMARY:
==28244==    definitely lost: 19,592 bytes in 202 blocks
==28244==    indirectly lost: 161,667 bytes in 1,437 blocks
==28244==      possibly lost: 0 bytes in 0 blocks
==28244==    still reachable: 48 bytes in 1 blocks
==28244==         suppressed: 0 bytes in 0 blocks
==28244== Reachable blocks (those to which a pointer was found) are not shown.
==28244== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==28244==
==28244== ERROR SUMMARY: 8 errors from 8 contexts (suppressed: 0 from 0)

valgrind28615.log (10 seconds)
==28615== LEAK SUMMARY:
==28615==    definitely lost: 38,792 bytes in 402 blocks
==28615==    indirectly lost: 257,667 bytes in 2,437 blocks
==28615==      possibly lost: 0 bytes in 0 blocks
==28615==    still reachable: 48 bytes in 1 blocks
==28615==         suppressed: 0 bytes in 0 blocks
==28615== Reachable blocks (those to which a pointer was found) are not shown.
==28615== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==28615==
==28615== ERROR SUMMARY: 8 errors from 8 contexts (suppressed: 0 from 0)

Attached is the modified py script and the output of valgrind for the last run

Greetings, Harald


Am 30.03.21 um 19:55 schrieb . Abdullah:
Hi,

I have attached both the .py and .txt files below.

On Tue, Mar 30, 2021 at 4:50 AM <[email protected] <mailto:[email protected]>> wrote:

    Hi Abdullah,

    I cannot see your .py file. Would you please send it as a .txt file?

    Regards,

    Giuliana

    *Von:* sumo-user <[email protected]
    <mailto:[email protected]>> *Im Auftrag von *. Abdullah
    *Gesendet:* Montag, 29. März 2021 16:50
    *An:* Sumo project User discussions <[email protected]
    <mailto:[email protected]>>
    *Betreff:* [sumo-user] Using traci.simulation.loadState increases
    memory usage

    Hi,

    I have noticed that if I use traci.simulation.loadState multiple
    times then my memory usage increases significantly. I
    have attached a simple code below, where cars are being added to
    the network and after every 5 seconds, a state is being saved and
    loaded back up. If I do this multiple times, it increases my
    memory usage. You can try the same code again by commenting out
    line 47 and it will drastically reduce the memory usage. Is there
    something I am doing wrong and is there a way around this?

--
    Thank you.

    Abdullah

    _______________________________________________
    sumo-user mailing list
    [email protected] <mailto:[email protected]>
    To unsubscribe from this list, visit
    https://www.eclipse.org/mailman/listinfo/sumo-user
    <https://www.eclipse.org/mailman/listinfo/sumo-user>



--
Thank you.
Abdullah

_______________________________________________
sumo-user mailing list
[email protected]
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/sumo-user

Attachment: valgrind28615.log.gz
Description: application/gzip

#!/usr/bin/python3

import os
import sys, gc
import argparse
import time
import json
import numpy as np
import random

parser = argparse.ArgumentParser(description='Example Python Programm')
parser.add_argument('-v','--valgrind', action='store_true', help='Only test')
args = parser.parse_args()

# we need to import some python modules from the $SUMO_HOME/tools directory
if 'SUMO_HOME' in os.environ:
    tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
    sys.path.append(tools)
else:
    sys.exit("please declare environment variable 'SUMO_HOME'")


from sumolib import checkBinary  # Checks for the binary in environ vars
import traci

def add_vehicle():
    additional_route_ID = traci.route.getIDList()
    no_of_cars = 60 - traci.simulation.getMinExpectedNumber()
    for i in range(no_of_cars):
        routeID = random.choice(additional_route_ID)
        while True:
            additional_veh_ID = random.randint(0,10000000)
            vehID = "addtionVehical."+str(additional_veh_ID)
            try:
                traci.vehicle.add(vehID, routeID, "car")
                break
            except:
                pass
def run():
    print('saving')
    step = 0
    valgrind = ['valgrind', '-s', '--leak-check=full',  '--track-origins=yes', '--tool=memcheck', '--log-file=valgrind%p.log']
    command = []
    command.extend(valgrind)
    command.extend(['/usr/local/bin/sumo', "-c", "config.sumocfg", "--step-length", "0.5", '--save-state.rng', "--step-method.ballistic", "--no-step-log", "--no-warnings", "--tripinfo-output", "tripinfo.xml"])
    traci.start(command)
    simulation_time = 10 # 10*60  # increasing this increases Memory usage
    while step <= simulation_time:
        print(step)
        add_vehicle() # adding vehicles to the network
        traci.simulationStep()
        step += traci.simulation.getDeltaT()
        if step % 5 == 0:
            for _ in range(200):
                traci.simulation.saveState('saved_state')
                # Save state and work on it and then load back the state
                traci.simulation.loadState('saved_state') # this uses a lot of memory, comment it to see the difference
    traci.close()


# main entry point
if __name__ == "__main__":
    run()

_______________________________________________
sumo-user mailing list
[email protected]
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/sumo-user

Reply via email to