Skip to content

more than 500 multi-agents simulation at one time #4942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ZhangShaungnj opened this issue Mar 14, 2024 · 5 comments
Open

more than 500 multi-agents simulation at one time #4942

ZhangShaungnj opened this issue Mar 14, 2024 · 5 comments

Comments

@ZhangShaungnj
Copy link

ZhangShaungnj commented Mar 14, 2024

How can I simulate more than 500 multi-rotors at one time.
Here is my computer hardware list:
cpu:AMD EPYC 9654 96-Core Processor
ram:128g
gpu:4090
I find the simulation will not display smoothly in UE everytime the number over 70~80
I have tried join(),multi-process,threading.They don't work

### Tasks
@ZhangShaungnj
Copy link
Author

Snipaste_2024-03-14_22-50-23
Snipaste_2024-03-14_22-50-53
Snipaste_2024-03-14_22-51-22

@Midas75
Copy link

Midas75 commented May 31, 2024

AirSim adopts a spin wait similar to sleep (0) in some low-level sleep implementations, which causes threads to be repeatedly scheduled on the CPU core when multiple drones are simulated simultaneously, resulting in high kernel state consumption. When the number of simulated drones approaches the number of CPU cores/CPU threads, performance will plummet, so it can be seen that in your configuration, 80 drones correspond to your CPU96 core. The solution is to replace its internal spin implementation (approximately four times) with a plain sleep implementation and recompile AirLib for use in the Unreal project. Using this method, I can achieve 400+drone simulation based on i7-12700 in Unity scenarios.

@Coinstine
Copy link

AirSim adopts a spin wait similar to sleep (0) in some low-level sleep implementations, which causes threads to be repeatedly scheduled on the CPU core when multiple drones are simulated simultaneously, resulting in high kernel state consumption. When the number of simulated drones approaches the number of CPU cores/CPU threads, performance will plummet, so it can be seen that in your configuration, 80 drones correspond to your CPU96 core. The solution is to replace its internal spin implementation (approximately four times) with a plain sleep implementation and recompile AirLib for use in the Unreal project. Using this method, I can achieve 400+drone simulation based on i7-12700 in Unity scenarios.

hi dude, could u tell me the detail how u replace the internal spin implementation with a plain sleep one? thank u sooooo much!!

@Midas75
Copy link

Midas75 commented Apr 24, 2025

AirSim adopts a spin wait similar to sleep (0) in some low-level sleep implementations, which causes threads to be repeatedly scheduled on the CPU core when multiple drones are simulated simultaneously, resulting in high kernel state consumption. When the number of simulated drones approaches the number of CPU cores/CPU threads, performance will plummet, so it can be seen that in your configuration, 80 drones correspond to your CPU96 core. The solution is to replace its internal spin implementation (approximately four times) with a plain sleep implementation and recompile AirLib for use in the Unreal project. Using this method, I can achieve 400+drone simulation based on i7-12700 in Unity scenarios.

hi dude, could u tell me the detail how u replace the internal spin implementation with a plain sleep one? thank u sooooo much!!

Hi,
I forked AirSim and applied the implementation, which you can find here. For more details on the implementation, feel free to check the commit here.
In summary, you will need to make changes in the following three files:

  • AirLib/include/common/ClockBase.hpp: virtual void sleep_for(TTimeDelta dt)
  • AirLib/include/common/CancelToken.hpp: bool sleep(double secs)
  • AirLib/include/common/common_utils/ScheduledExecutor.hpp: static void sleep_for(TTimePoint deplay_nanos)

Please note that my fork introduces Boost as a dependency, and the build has only been tested on Windows.
Good luck!

@Coinstine
Copy link

AirSim adopts a spin wait similar to sleep (0) in some low-level sleep implementations, which causes threads to be repeatedly scheduled on the CPU core when multiple drones are simulated simultaneously, resulting in high kernel state consumption. When the number of simulated drones approaches the number of CPU cores/CPU threads, performance will plummet, so it can be seen that in your configuration, 80 drones correspond to your CPU96 core. The solution is to replace its internal spin implementation (approximately four times) with a plain sleep implementation and recompile AirLib for use in the Unreal project. Using this method, I can achieve 400+drone simulation based on i7-12700 in Unity scenarios.

hi dude, could u tell me the detail how u replace the internal spin implementation with a plain sleep one? thank u sooooo much!!

Hi, I forked AirSim and applied the implementation, which you can find here. For more details on the implementation, feel free to check the commit here. In summary, you will need to make changes in the following three files:

  • AirLib/include/common/ClockBase.hpp: virtual void sleep_for(TTimeDelta dt)
  • AirLib/include/common/CancelToken.hpp: bool sleep(double secs)
  • AirLib/include/common/common_utils/ScheduledExecutor.hpp: static void sleep_for(TTimePoint deplay_nanos)

Please note that my fork introduces Boost as a dependency, and the build has only been tested on Windows. Good luck!

膜拜大佬!!!真的牛!非常感谢,这就去研究下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants