Add Rule Zone:KillProcessOnDynamicShutdown and functionality for killing a dynamic after it has been allocated a zone and has shutdown - this is done for memory reasons because we do not clean up after ourselves at all and zone processes bloat heavily in memory. This is a workaround until we manage this better

This commit is contained in:
Akkadius 2019-09-06 12:26:30 -05:00
parent 45278f80ca
commit 534bed1483
4 changed files with 25 additions and 16 deletions

View File

@ -274,6 +274,7 @@ RULE_INT(Zone, MinOfflineTimeToReplenishments, 21600) // 21600 seconds is 6 Hour
RULE_BOOL(Zone, UseZoneController, true) // Enables the ability to use persistent quest based zone controllers (zone_controller.pl/lua) RULE_BOOL(Zone, UseZoneController, true) // Enables the ability to use persistent quest based zone controllers (zone_controller.pl/lua)
RULE_BOOL(Zone, EnableZoneControllerGlobals, false) // Enables the ability to use quest globals with the zone controller NPC RULE_BOOL(Zone, EnableZoneControllerGlobals, false) // Enables the ability to use quest globals with the zone controller NPC
RULE_INT(Zone, GlobalLootMultiplier, 1) // Sets Global Loot drop multiplier for database based drops, useful for double, triple loot etc. RULE_INT(Zone, GlobalLootMultiplier, 1) // Sets Global Loot drop multiplier for database based drops, useful for double, triple loot etc.
RULE_BOOL(Zone, KillProcessOnDynamicShutdown, true) // When process has booted a zone and has hit its zone shut down timer, it will hard kill the process to free memory back to the OS
RULE_CATEGORY_END() RULE_CATEGORY_END()
RULE_CATEGORY(Map) RULE_CATEGORY(Map)

View File

@ -435,8 +435,8 @@ int main(int argc, char** argv) {
LogDebug("Main thread running with thread id [{}]", pthread_self()); LogDebug("Main thread running with thread id [{}]", pthread_self());
#endif #endif
bool worldwasconnected = worldserver.Connected(); bool worldwasconnected = worldserver.Connected();
bool eqsf_open = false; bool eqsf_open = false;
bool websocker_server_opened = false; bool websocker_server_opened = false;
Timer quest_timers(100); Timer quest_timers(100);
@ -543,8 +543,9 @@ int main(int argc, char** argv) {
} }
} }
if (quest_timers.Check()) if (quest_timers.Check()) {
quest_manager.Process(); quest_manager.Process();
}
} }
} }

View File

@ -683,31 +683,31 @@ bool Zone::IsLoaded() {
return is_zone_loaded; return is_zone_loaded;
} }
void Zone::Shutdown(bool quite) void Zone::Shutdown(bool quiet)
{ {
if (!is_zone_loaded) if (!is_zone_loaded) {
return; return;
}
entity_list.StopMobAI(); entity_list.StopMobAI();
std::map<uint32,NPCType *>::iterator itr; std::map<uint32, NPCType *>::iterator itr;
while(!zone->npctable.empty()) { while (!zone->npctable.empty()) {
itr=zone->npctable.begin(); itr = zone->npctable.begin();
delete itr->second; delete itr->second;
zone->npctable.erase(itr); zone->npctable.erase(itr);
} }
while(!zone->merctable.empty()) { while (!zone->merctable.empty()) {
itr=zone->merctable.begin(); itr = zone->merctable.begin();
delete itr->second; delete itr->second;
zone->merctable.erase(itr); zone->merctable.erase(itr);
} }
zone->adventure_entry_list_flavor.clear(); zone->adventure_entry_list_flavor.clear();
std::map<uint32,LDoNTrapTemplate*>::iterator itr4; std::map<uint32, LDoNTrapTemplate *>::iterator itr4;
while(!zone->ldon_trap_list.empty()) while (!zone->ldon_trap_list.empty()) {
{
itr4 = zone->ldon_trap_list.begin(); itr4 = zone->ldon_trap_list.begin();
delete itr4->second; delete itr4->second;
zone->ldon_trap_list.erase(itr4); zone->ldon_trap_list.erase(itr4);
@ -717,8 +717,10 @@ void Zone::Shutdown(bool quite)
LogInfo("Zone Shutdown: [{}] ([{}])", zone->GetShortName(), zone->GetZoneID()); LogInfo("Zone Shutdown: [{}] ([{}])", zone->GetShortName(), zone->GetZoneID());
petition_list.ClearPetitions(); petition_list.ClearPetitions();
zone->SetZoneHasCurrentTime(false); zone->SetZoneHasCurrentTime(false);
if (!quite) if (!quiet) {
LogInfo("Zone shutdown: going to sleep"); LogInfo("Zone Shutdown: Going to sleep");
}
is_zone_loaded = false; is_zone_loaded = false;
zone->ResetAuth(); zone->ResetAuth();
@ -728,6 +730,11 @@ void Zone::Shutdown(bool quite)
UpdateWindowTitle(); UpdateWindowTitle();
LogSys.CloseFileLogs(); LogSys.CloseFileLogs();
if (RuleB(Zone, KillProcessOnDynamicShutdown)) {
LogInfo("[KillProcessOnDynamicShutdown] Shutting down");
std::exit(EXIT_SUCCESS);
}
} }
void Zone::LoadZoneDoors(const char* zone, int16 version) void Zone::LoadZoneDoors(const char* zone, int16 version)

View File

@ -84,7 +84,7 @@ class MobMovementManager;
class Zone { class Zone {
public: public:
static bool Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone = false); static bool Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone = false);
static void Shutdown(bool quite = false); static void Shutdown(bool quiet = false);
Zone(uint32 in_zoneid, uint32 in_instanceid, const char *in_short_name); Zone(uint32 in_zoneid, uint32 in_instanceid, const char *in_short_name);
~Zone(); ~Zone();