mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-13 09:17:18 +00:00
fix(Core/World): Remove artificially high minimal update intervals an… (#15422)
fix(Core/World): Remove artificially high minimal update intervals and Allow specifying minimum world updates diff in config * Allow specifying minimum world updates diff in config * Remove artificially high minimal update intervals * cherry-pick commit (29a4153f00) * cherry-pick commit (de4920de81) * cherry-pick commit (32cef906b0) Co-authored-by: Shauren <shauren.trinity@gmail.com> Co-authored-by: Giacomo Pozzoni <giacomopoz@gmail.com>
This commit is contained in:
@@ -72,13 +72,15 @@ char serviceDescription[] = "AzerothCore World of Warcraft emulator world servic
|
||||
* 2 - paused
|
||||
*/
|
||||
int m_ServiceStatus = -1;
|
||||
|
||||
#include <boost/dll/shared_library.hpp>
|
||||
#include <timeapi.h>
|
||||
#endif
|
||||
|
||||
#ifndef _ACORE_CORE_CONFIG
|
||||
#define _ACORE_CORE_CONFIG "worldserver.conf"
|
||||
#endif
|
||||
|
||||
#define WORLD_SLEEP_CONST 10
|
||||
using namespace boost::program_options;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -137,6 +139,44 @@ int main(int argc, char** argv)
|
||||
return WinServiceUninstall() == true ? 0 : 1;
|
||||
else if (configService.compare("run") == 0)
|
||||
WinServiceRun();
|
||||
|
||||
Optional<UINT> newTimerResolution;
|
||||
boost::system::error_code dllError;
|
||||
std::shared_ptr<boost::dll::shared_library> winmm(new boost::dll::shared_library("winmm.dll", dllError, boost::dll::load_mode::search_system_folders), [&](boost::dll::shared_library* lib)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (newTimerResolution)
|
||||
lib->get<decltype(timeEndPeriod)>("timeEndPeriod")(*newTimerResolution);
|
||||
}
|
||||
catch (std::exception const&)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
delete lib;
|
||||
});
|
||||
|
||||
if (winmm->is_loaded())
|
||||
{
|
||||
try
|
||||
{
|
||||
auto timeGetDevCapsPtr = winmm->get<decltype(timeGetDevCaps)>("timeGetDevCaps");
|
||||
// setup timer resolution
|
||||
TIMECAPS timeResolutionLimits;
|
||||
if (timeGetDevCapsPtr(&timeResolutionLimits, sizeof(TIMECAPS)) == TIMERR_NOERROR)
|
||||
{
|
||||
auto timeBeginPeriodPtr = winmm->get<decltype(timeBeginPeriod)>("timeBeginPeriod");
|
||||
newTimerResolution = std::min(std::max(timeResolutionLimits.wPeriodMin, 1u), timeResolutionLimits.wPeriodMax);
|
||||
timeBeginPeriodPtr(*newTimerResolution);
|
||||
}
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
printf("Failed to initialize timer resolution: %s\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Add file and args in config
|
||||
@@ -522,9 +562,15 @@ void ShutdownCLIThread(std::thread* cliThread)
|
||||
|
||||
void WorldUpdateLoop()
|
||||
{
|
||||
uint32 minUpdateDiff = uint32(sConfigMgr->GetOption<int32>("MinWorldUpdateTime", 1));
|
||||
uint32 realCurrTime = 0;
|
||||
uint32 realPrevTime = getMSTime();
|
||||
|
||||
uint32 maxCoreStuckTime = uint32(sConfigMgr->GetOption<int32>("MaxCoreStuckTime", 60)) * 1000;
|
||||
uint32 halfMaxCoreStuckTime = maxCoreStuckTime / 2;
|
||||
if (!halfMaxCoreStuckTime)
|
||||
halfMaxCoreStuckTime = std::numeric_limits<uint32>::max();
|
||||
|
||||
LoginDatabase.WarnAboutSyncQueries(true);
|
||||
CharacterDatabase.WarnAboutSyncQueries(true);
|
||||
WorldDatabase.WarnAboutSyncQueries(true);
|
||||
@@ -536,18 +582,19 @@ void WorldUpdateLoop()
|
||||
realCurrTime = getMSTime();
|
||||
|
||||
uint32 diff = getMSTimeDiff(realPrevTime, realCurrTime);
|
||||
if (diff < minUpdateDiff)
|
||||
{
|
||||
uint32 sleepTime = minUpdateDiff - diff;
|
||||
if (sleepTime >= halfMaxCoreStuckTime)
|
||||
LOG_ERROR("server.worldserver", "WorldUpdateLoop() waiting for {} ms with MaxCoreStuckTime set to {} ms", sleepTime, maxCoreStuckTime);
|
||||
// sleep until enough time passes that we can update all timers
|
||||
std::this_thread::sleep_for(Milliseconds(sleepTime));
|
||||
continue;
|
||||
}
|
||||
|
||||
sWorld->Update(diff);
|
||||
realPrevTime = realCurrTime;
|
||||
|
||||
uint32 executionTimeDiff = getMSTimeDiff(realCurrTime, getMSTime());
|
||||
|
||||
// we know exactly how long it took to update the world, if the update took less than WORLD_SLEEP_CONST, sleep for WORLD_SLEEP_CONST - world update time
|
||||
if (executionTimeDiff < WORLD_SLEEP_CONST)
|
||||
{
|
||||
std::this_thread::sleep_for(Milliseconds(WORLD_SLEEP_CONST - executionTimeDiff));
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
if (m_ServiceStatus == 0)
|
||||
World::StopNow(SHUTDOWN_EXIT_CODE);
|
||||
@@ -583,10 +630,14 @@ void FreezeDetector::Handler(std::weak_ptr<FreezeDetector> freezeDetectorRef, bo
|
||||
freezeDetector->_worldLoopCounter = worldLoopCounter;
|
||||
}
|
||||
// possible freeze
|
||||
else if (getMSTimeDiff(freezeDetector->_lastChangeMsTime, curtime) > freezeDetector->_maxCoreStuckTimeInMs)
|
||||
else
|
||||
{
|
||||
LOG_ERROR("server.worldserver", "World Thread hangs, kicking out server!");
|
||||
ABORT();
|
||||
uint32 msTimeDiff = getMSTimeDiff(freezeDetector->_lastChangeMsTime, curtime);
|
||||
if (msTimeDiff > freezeDetector->_maxCoreStuckTimeInMs)
|
||||
{
|
||||
LOG_ERROR("server.worldserver", "World Thread hangs for {} ms, forcing a crash!", msTimeDiff);
|
||||
ABORT("World Thread hangs for {} ms, forcing a crash!", msTimeDiff);
|
||||
}
|
||||
}
|
||||
|
||||
freezeDetector->_timer.expires_from_now(boost::posix_time::seconds(1));
|
||||
|
||||
Reference in New Issue
Block a user