FilUnderscore / ImprovedHordes

7 Days To Die Server/Client Mod - Improves existing hordes by reworking their core behaviours.
https://community.7daystodie.com/topic/26781-improved-hordes/
Other
8 stars 3 forks source link

Path finding #31

Closed Crudelis98 closed 4 months ago

Crudelis98 commented 6 months ago

Describe the bug 7 days to die uses one core to run the server and hordes are huge performance impact. It got me thinking if it is possible to move path finding algorithm to GPU from CPU on dedicated server?

To Reproduce

Expected behavior Low CPU usage.

Screenshots

Link to game output log (can be found in 7DaysToDie_Data folder)

Additional context Improvement, curiosity.

FilUnderscore commented 6 months ago

Sounds like an interesting idea and would probably involve compute shaders which can possibly be integrated through something like an assetbundle. There is a concern though how much performance increase we would see as a result, because the GPU would need to have info about the world to pathfind taking terrain into account and whether that could slow it down.

The path finding does currently use multithreading through a patch which could also be causing high CPU usage - have you looked into reducing the tick rate of the threads in the settings.xml file?

Crudelis98 commented 6 months ago

Honestly, I've never tried this mod, I didn't expect you to respond to this thread, but thank you. I have no idea about possible improvements. I've never written more than 100 lines of code in C#, but my thinking is simple, lots of zombies -> parallel execution -> GPU. Isn't it enough to copy the data to vram and execute the process on CUDA cores and copy it back to ram?

edit

Do native game AI use multithread? Or you introduced it?

edit 2

What is the best CPU to run game and/or server? (Intel with best single thread perfomorance or maybe a bit slower Ryzen but X3D cache?)

FilUnderscore commented 6 months ago

Isn't it enough to copy the data to vram and execute the process on CUDA cores and copy it back to ram?

In theory, yes. The problem could be when chunks load/unload during pathfinding or blocks are placed, we need to track updates otherwise the pathfinding could break and need re-computation, so it would be expensive to go back and forth between VRAM and RAM.

Do native game AI use multithread? Or you introduced it?

Vanilla uses a single coroutine but I set it to a dedicated thread - I do believe it could be more optimized in terms of using something like parallel execution where each entity can pathfind at the same time but that could simply see the CPU usage skyrocket, I would need to do some testing with this idea.

What is the best CPU to run game and/or server? (Intel with best single thread perfomorance or maybe a bit slower Ryzen but X3D cache?)

Given that the game runs on Unity (and Unity really likes to run with a single game thread), it would most likely be that CPUs with a higher single thread performance would be most ideal.

Crudelis98 commented 5 months ago

Thank you for answer, we play with your mod now. Its more fun NGL. I feel like our server (i3-9100f) is more than enough for handling huge hordes (as we have 6 player x 12 zombies per player and main thread is 18%, my guess is 25% is max, so there is a spare room). The problem is client PC my old 7700k overclocked to 5 GHz is nothing for this game. FPS drops to 20 and my GPU usage drops to 15%. So it must be CPU.

FilUnderscore commented 5 months ago

Thank you for answer, we play with your mod now. Its more fun NGL. I feel like our server (i3-9100f) is more than enough for handling huge hordes (as we have 6 player x 12 zombies per player and main thread is 18%, my guess is 25% is max, so there is a spare room). The problem is client PC my old 7700k overclocked to 5 GHz is nothing for this game. FPS drops to 20 and my GPU usage drops to 15%. So it must be CPU.

Ah I see, you are talking about the clients. In that case, the only solutions are to either reduce the max alive horde entity count or upgrade your CPU. Unfortunately, the performance issue regarding entities on a vanilla client is unrelated to the mod and is a known issue with 7DTD.