Trinity-Bots icon indicating copy to clipboard operation
Trinity-Bots copied to clipboard

[TC] [AC] [Question/Feature] Suggest optimizing the spawn of NPCBOTS

Open moncat2005 opened this issue 1 year ago • 1 comments

DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

  • [X] I understand that my issue may get closed without notice if I intentionally remove or skip any mandatory* field
  • [X] This is NOT a bug/crash report
  • [X] I've searched the bugtracker for similar questions/requests including closed ones

Description

At present, the employment summoning method of NPCBOTS adopts pre spawning NPC objects with NPCBOTS functions, and then obtaining the player employment relationship binding through the selection menu of NPC intermediaries.

In order for online players to use the already hired NPCBOTS, or for new players to freely hire and choose NPCBOTS from various professions, the current approach requires almost all NPCBOTS to be pre spawned.

In the scenario of pre spawning hundreds of NPCBOTS, various script operations of NPCs are executing various actions, and this spawn area will become very sluggish. I tried pre spawning approximately 300 NPCBOTS on GMLAND, and the result was just like that. I guess this scenario may be one of the reasons for discovering an increase in CPU usage in the worldserver program.

Would you consider optimizing this approach?

The following suggestions are for reference:

  1. The free NPCBOTS for each profession is implemented through dynamic respawn. For example, through the NPCBOTS configuration file, each profession is controlled to maintain 3 candidates, and the missing ones are automatically respawn to ensure that the hired NPC can list a certain number of NPCBOTS for players to hire and choose from.

  2. After hiring NPCBOTS, players are allowed to change the name of the NPC, which is beneficial for the data respawn reuse of the create_template, just like a pet name, rather than having one NPC ID with only one employment relationship.

  3. Calculate the employment validity period of players periodically, dynamically clean up expired employment relationship data, and avoid excessive NPCBOTS respawn.

Thank you!

TrinityCore or AzerothCore

AzerothCore

Core rev. hash/commit

AzerothCore rev. 4699f0429a86 2023-08-13 19:17:15 +0700 (npcbots_3.3.5 branch) (Unix, RelWithDebInfo, Static)

Operating system

Ubuntu 18.04

moncat2005 avatar Aug 15 '23 03:08 moncat2005

1) and 2) are impossible to achieve with current concept which won't change, it requires each npcbot creature_template entry to be a unique creature, appearing in world or not 3) was implemented in #742 Also #579 I hope it helps your situation.

trickerer avatar Mar 20 '24 08:03 trickerer

https://github.com/trickerer/AzerothCore-wotlk-with-NPCBots/commit/0b5b5b36f4aac1ee3c2819e8a4f1fcaeead9e9ed That's about as far as I can go. Enabling this feature will make all inactive bots stay out of world, not triggering Update cycles, although AC currently doesn't have grids unload. Anyway feel free to test it, with this server performance should be mostly identical to no-bots-exist situation in case when there are no active bots. But of course this improvement will be engligible if you enable wandering bots (in world maps). It's still in test mode. I'll give this issue a leeway of about a week before closing, until then any related issues can be posted here.

trickerer avatar May 22 '24 03:05 trickerer

Considering ensuring that all CPU resources are only used in the idle state of the worldserver process (which includes the overhead of respawn NPCBOTS itself). I tested it based on the state of no player online after startup, and from the WorldServer console, it should be clearly effective.

This is yesterday's console message: 2024-05-21 19:27:57 INFO [time.update] Last 500 diffs summary with 0 players online: 2024-05-21 19:27:57 INFO [time.update] - Mean: 12; 2024-05-21 19:27:57 INFO [time.update] - Median: 11; 2024-05-21 19:27:57 INFO [time.update] - Percentiles (95, 99, max): 24, 28, 180.

This is the console information for today's compiled version: 2024-05-22 15:22:53 INFO [time.update] Last 500 diffs summary with 0 players online: 2024-05-22 15:22:53 INFO [time.update] - Mean: 11; 2024-05-22 15:22:53 INFO [time.update] - Median: 11; 2024-05-22 15:22:53 INFO [time.update] - Percentiles (95, 99, max): 17, 18, 170.

From the point of view of the CPU utilization of the worldserver process after linux executed the "top" command: Yesterday's version was 30%~ 42%. Today, after optimization, it is 27% ~ 39%.

From this perspective, it seems that the decrease in CPU usage is not significant.

moncat2005 avatar May 22 '24 08:05 moncat2005

After updating the optimized code, I run to the respawn npcbots location to check the status of NPCBOTS. It was found that NPCBOTS only appears when the GM account approaches the preset respawn point. But at the beginning of their brush, NPCBOTS still had casting and other actions, and after a while they were in a sitting and resting state. And in some skill CD times, they will also get up and cast new spells one after another, without maintaining a resting and silent state. I remember that thecommand can perform no other actions except recall and follow commands.

moncat2005 avatar May 22 '24 12:05 moncat2005

The point is not to make bots do nothing while in world and inactive (not currently following player). The point is to make bots stay out of grid so they don't trigger root Update() calls which includes pretty much everything, auras don't update, environment isn't checked, no regen even, they just stay in memory waiting to be put on that Update conveyor again by player.

If you want to compare performance for real compare it to a server with no bots at all

trickerer avatar May 22 '24 14:05 trickerer

I compiled and run the AZCORE native worldserver, and the CPU usage of this process is as follows: Console display: May 23, 2024 10:50:36 INFO [time. update] Last 500 diffs summary with 0 players online: May 23, 2024 10:50:36 INFO [time. update] - Mean: 11; May 23, 2024 10:50:36 INFO [time. update] - Median: 11; May 23, 2024 10:50:36 INFO [time. update] - Percentiles (95, 99, max): 14, 18, 151.

The CPU usage of the process displayed by the TOP command is 20%~30%

moncat2005 avatar May 23 '24 05:05 moncat2005

I just compiled the latest 0289fd97d version of May 22.

Upgrade the server that currently has players online, but there will soon be a problem with the worldserver program crash. I'm sorry I can't get the log.

moncat2005 avatar May 23 '24 07:05 moncat2005

2024-05-28 22:19:13 ERROR [entities.unit] CastSpell: unknown spell 7530 by caster GUID Full: 0xf1300111fc000065 Type: Creature Entry: 70140 Low: 101 2024-05-28 22:19:22 FATAL [entities.object] WorldObject::SetMap: obj 3 new map 0 0, old map 1 0

moncat2005 avatar May 28 '24 16:05 moncat2005

The code for the worldserver crash issue was compiled synchronously on May 22nd, and the log error message is as follows: 2024-05-28 22:19:13 ERROR [entities.unit] CastSpell: unknown spell 7530 by caster GUID Full: 0xf1300111fc000065 Type: Creature Entry: 70140 Low: 101 2024-05-28 22:19:22 FATAL [entities.object] WorldObject::SetMap: obj 3 new map 0 0, old map 1 0

The actual situation is that after the character goes online, the NPCbots are not called back to their side, and worldserver crashes directly. After automatic restart, the role login crashes again.

If the WorldServer main program is rolled back to the May 21st version (without hidden NPCbots code), everything will be normal when logging into the game.

moncat2005 avatar May 28 '24 16:05 moncat2005

The code for the worldserver crash issue was compiled synchronously on May 22nd, and the log error message is as follows: 2024-05-28 22:19:13 ERROR [entities.unit] CastSpell: unknown spell 7530 by caster GUID Full: 0xf1300111fc000065 Type: Creature Entry: 70140 Low: 101 2024-05-28 22:19:22 FATAL [entities.object] WorldObject::SetMap: obj 3 new map 0 0, old map 1 0

The actual situation is that after the character goes online, the NPCbots are not called back to their side, and worldserver crashes directly. After automatic restart, the role login crashes again.

If the WorldServer main program is rolled back to the May 21st version (without hidden NPCbots code), everything will be normal when logging into the game.

https://github.com/trickerer/AzerothCore-wotlk-with-NPCBots/commit/d03fa111123fccb47c6faa6335c511663fe36130 This is probably it

trickerer avatar May 29 '24 04:05 trickerer

I just compiled the latest code on 5/29 and upgraded the WorldServer program and database. At present, players have started to enter WorldServer and have not yet found any crashes. This version seems to have the lowest resource usage for npcbots MOD functionality so far.

moncat2005 avatar May 30 '24 08:05 moncat2005