-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
monsters bug when running #1650
Comments
tested right now, everything is okay with that, must be your server. |
They have pretty much always done that(atleast on OTs), you can just put follow on ex a necro and it will walk one step at a time insted of running. Would be better IMO if they actually ran away insted of walking step by step, should not be easier just because you caught up with the monster. |
@WibbenZ in the rl they run away without stop or turn to the player, I think that the problem is with the flag "runonhealth" because the monster try to run, but attack aswell o.O |
Maybe monsters could have an internal state machine with ATTACK and FLEE states, the former searching a player and launching attacks and the latter just running away and checking if it's possible to attack again. |
confirmed, bug. |
bump, also monsters when running stay in crazy dancing |
Sorry for refreshing this issue, but that "bug" was reported some time ago by someone on forum and @marksamman stance on this is: |
@nekiro It does look like a weird behavior. I'm inclined to tag it as a bug and look for a more performant solution than the one you linked. |
yeah this is indeed a bug, make monsters so "dumb" that hunting anything isn't even hard |
Maybe these monsters following player look dumb, but try to spawn Rabbit. It runs away doing 1 step per second! Changing line described by Mark fixed Rabbits too. |
exactly, my proposal for the time being, is to add mark code with a configurable switch to turn it on/off and warn about performance just like we do with classic attack speed and other settings |
I did some test:
Results were same over minute, so I post just 5 seconds part of each test. CPU usage on
As we can see, there is only one change in stats:
It made 171 calls to IT MUST BE configurable on/off in EDIT:
with 10 demons it uses extra 3% CPU:
with 15 demons it uses extra 10% CPU! 👀
There must be some way, to make them move smooth and react fast, but not use 123% CPU. |
I suggest splitting the tickrate of monster actions to allow setting different values. Currently there's only one value for everything, the link to variable: forgottenserver/src/creature.h Line 72 in f7efa85
also, why is it hardcoded? |
I will benchmark idea with 100 ms 'find path' interval. I will also test algorithm, where monster can do 'extra step calculation' once every XXX ms. I will test values 100, 200 and 500 ms. |
On a second thought, won't it cause a data race? |
I did tests with 4 reaction algorithms:
Fighting vs 5 demons (on [email protected]): Fighting vs 15 demons (on [email protected]): Testing EDIT: |
Algorithm 4 by Mark. Monsters react like with 'instant reaction' algorithm, but CPU usage is lower, as we schedule updateCreatureWalk to moment when monster can make next step.
( Total CPU usage comparison: |
That cpu usage is still quite big even for 15 demons. If we assume 200 players online of which 70% are hunting and keeping 5 monsters active on average (data completely made up but you get the point), will the server be playable? On the other hand, there were also issues with pathfinding performance from what I remember. Also there's a huge bottleneck in area spells. Every tile of spell area calls isSightClear, edit: nvm, the thing with magic effects doesnt happen |
I made Demon with 0 spells/attacks and 0 summons, to make results stable. EDIT: |
Didn't your line of sight PRs fix improve the logic to not check every tile on area spells? |
No, I planned to work on that after two things get merged, but I've been busy with several other things. I'm not really good at optimizations so I'll stick with working on protocol. If anyone is interested in working on that, I can give you hints though. |
I did tests with multithread pathfinding with searches limited to one calculation per step. It's hard to say, if it reduces dispatcher thread CPU usage, because it generates constant load related to multithread synchronization. Cost of 40 synchronizations of 16 threads per second is higher than calculation of 15 demons steps (around 1% cpu). I made version for TFS, but someone need to test it on server with 50+ players online: Someone tried to install it on otservbr and said it crashes, but maybe he did not apply it in all required places. |
I've tested again TFS algorithm vs Mark fast reaction vs Gesior fast reaction vs Kondra multi-thread path finding. Benchmark:
Results (avg CPU usage by Dispatcher thread):
So you can reduce CPU usage on Dispatcher by 3% (50 ms reaction) or 9% (200 ms reaction) using 8 cores, but lower CPU usage accumulates more monster to process at once making it lag for 31 ms, not 15 ms (normal TFS lags for 30 ms). Full results after 4 hours of benchmarking: Tested on Hetzner CCX33 Cloud:
Path Finding code is temporarily on branch (with Kondra permission): Raw results from OTS Stats and PHP code to process them in CSV: EDIT:
|
What if entire monster behavior was on multiple threads instead of game one and only dealing damage/dropping loot was on game thread? |
You can run on multiple threads only things that do not modify anything. |
According to pretty much every extensive resource on the internet, all the top minds in programmers hangout discord, as well as others I have spoken with in real life... multi-threading A* pathfinding is pointless. Pretty much everyone everywhere agree's, if there is at all any issues of performance in an A* pathfinding algorithm, its the implementation or some other issue that needs addressed, and multi-threading is not the solution. Even when using a dedicated thread for pathfinding, pretty much all agree that this would not do much as the main thread is still waiting on the results before moving. |
That's right answer to wrong question. There are often 30+ monsters waiting for path calculation every 0.05 sec with 400 players online. You can calculate all their paths to target using multiple threads. |
And then every one of those monsters would still have to wait to receive their path on the main thread. |
Idea is that you process multiple monsters at once, not each monster as different Dispatcher Task. TFS already does it in It's most basic multi-thread concept possible. You have 10 task to do (in this case run A*). You can run them on main thread and they will take 10x 'task execution time' or you can run them on 10 threads and wait on main thread for results, which will reduce time to 1x 'task execution time', if you have 10 core CPU. By using 10 cores, you can reduce main thread processing time 10 times. Only communication between threads is that Dispatcher lists 'monsters that require new path' and go sleep (nothing can move/change in that time). Path-finding threads process that list and then wake up Dispatcher thread. Normal path-finding: 10 times per second 10% of Monsters recalculate their path (if required) and start walking (Game::checkCreatures / onThink) Result: faster reaction (0.05 sec, not 1.0 sec); lower CPU usage on Dispatcher, if you have enough CPU cores. EDIT: |
Listen to what you are saying. If nothing can change, then its not multi-threaded. If there are indeed multiple threads running, everything has changed by the time they are done... this is the entire point and complexity that IS multi-threading! If nothing can change, then that means things are waiting (locked/frozen), that is a lag. If things are changing, then its like I said previously, the paths are stale. A player could have moved in the way, a fire field created... these things can happen while the secondary thread is running, and if they can't, then everything is waiting, and that's a lag. Even if you are getting slightly better results than what is already in place, its only barely slightly better and for a high cost, and I don't mean CPU usage, so much as the resource that is a thread. I don't want to argue the matter. If you have good results with multi-threading, or what you think is good results, more power to you. I am only saying, even if the results are better than whatever is going on right now, its not because multi-threading is the solution to a bottleneck for this case, its that there is another issue that needs addressed which when done so, would allow greater response times AND waaaaay less CPU for the same. |
There is one thing that can change. It's Monster* list of 'steps to target position' - thing that is calculated and modified by path-finding algorithm (A*).
Nothing has changed, because only thread that can modify game (players/monsters/map) is Dispatcher. It's sleeping and waiting for path-finding results.
Multi-threading is solution to any problem that CAN be processed in parallel. Path-finding is only part of OTS engine that can be processed in parallel. |
Who exactly is getting 100 percent CPU usage with 200 players online? Now you make me question where these players and this host with these willing players come from... |
well, how tittle says, when monsters is running low life, then walk 1 sqm and stop, walk another and stop, for exemple, draptor when is running he walk 1 sqm and stop and turn to the player, and continue doing it until he did not view any player and stop
The text was updated successfully, but these errors were encountered: