What's the best way to simulate in scenes with a lot of traffic?

Hi all,

I am trying to create a lot of traffic in Carla, e.g. Town06_Opt, by adding 1000 vehicles and 100 pedestrians. Currently, I am experiencing 4 FPS simulation speed, and it would be great if I can get some advice on my current set up and possible improvements.

To elaborate on what I am doing, I am trying to simulate a very busy traffic scene and at the same time to record live LiDAR scans from the ego vehicle.

The following are my current simulation setup:

  1. Hardward: Ryzen 3800X + RTX 2060 Super + 32 GB RAM
  2. Simulation is done in Unreal Engine Editor and I have turned off the option to “Use less CPU in background”
  3. Simulation is done in synchronomous mode and with no-rendering option turned on.

Here are the commands I executed to mimic a very busy traffic:

  1. python3 spawn_npc.py -n 400 -w 100 --sync to spawn actors (fewer than I actually need) using example script. Note that FPS drops from 60 FPS to 5 FPS after this.
  2. python3 open3d_lidar.py --semantic to create an ego vehicle with LiDAR to record scans
  3. python3 no_rendering_mode.py --no-rendering to enable no rendering mode

Some questions I have:

  1. Having no rendering mode on does not seem to affect FPS . I thought it was supposed to help a lot under busy traffic according to: https://carla.readthedocs.io/en/latest/adv_rendering_options/#quality-levels
  2. Is there a way to identify which is the bottleneck in my simulation pipeline? And some advice on how to improve this?

Thanks! Any help is appreciated!


First, thanks for using CARLA and welcome to our forums! I have a few suggestions for you in order to build a very busy traffic scene and have higher FPS.

One thing is, Town06 can’t sustain 1000 vehicles I think, it’s a bit too small. But I don’t know which kind of traffic you want to create.

Then, you should consider executing CARLA not via Unreal Engine, but using a packaged version. For example, you could download our nightly build from here, extract it and use ./CarlaUE.sh inside that folder to run the CARLA simulation. You can also use any other binary release.

Also, to actually run no rendering mode, it’s best if you do python3 config.py --no-rendering after having launched your simulation.

Then, when you are executing the Traffic Manager, by running spawn_npc.py, you should enable hybrid mode. This mode only enables physics for vehicles nearby the ego vehicle, while others far away move by teleportation and physics are deactivated. Since you are gathering data around an ego vehicle, this should definitely help. This can be activated by using the --hybrid flag when you launch the spawn_npc.py script.

Another suggestion is to spawn an heavy traffic only near your vehicle. I know it sounds quite obvious, but maybe you didn’t know this was a possibility. Spawn points aren’t the only way to spawn vehicles.

Let me know if this helps you, and if your FPS improves!

Hi @jackbart,

Thanks for the advice! It’s the first time that I start using Carla. It’s really a great simulation tool for my research! Thanks to your team!

I have tried out some of your suggestions, and already seen improvements to my FPS. Following is what I did so far:

  1. I tried to enable hybrid mode by adding the line vehicle_bp.set_attribute('role_name','hero') to my open3d_lidar.py to enable my ego vehicle.
  2. Run the scripts in such an order:
    python3 spawn_npc.py -n 400 -w 100 --sync --hybrid
    python3 open3d_lidar.py --semantic
    python3 config.py --no-rendering

Holding hybrid mode on/off as a control variable, I can see my FPS improve from 6.5 FPS to 7.5 FPS. I can see a similar improvement by having no-rendering mode on/off. It’s not by a large margin but I am eager to try the rest of the options.

I have couple of follow-up questions regarding to your suggestions, and hope if you can provide me with some insights :slight_smile:

  1. The reason I am using UE4 to simulate rather than binary version is because I want to make some modifications to the source code. However, I wasn’t able to find some online resources to compile my own binary version. I am not sure if make deploy under carla root directory would do the work.
  2. To elaborate on my scenario, I am trying to have my ego vehicle follow a designated path (covering whole town). And at all time during the drive, I want to have a lot of traffic near my ego vehicle. This is the reason why I wanted to create a lot of traffic to fill up the town. If I were to spawn heavy traffic only near my ego vehicle, I am worried that those heavy traffic would slowly drive away from ego vehicle (due to random driving in traffic manager). I guess an alternative is to keep spawning vehicles as the ego vehicle drives?
  3. As a side question, which C++ IDE would you recommend to develop carla? I am using CLion, but so far i am unable to build the project properly in it.

Thanks a lot for your help!

It’s make package, takes about an hour or so.

That’s a good alternative, another one would be to use deterministic mode and see if any seed is satisfying for you. There are a few ways to do this.

I am using Visual Studio and, if I recall correctly, there’s a way to build the CARLA project using it in the documentation.

Hi @jackbart,

Thanks a lot for your response! Really helpful!