Update WorldServer timings

This commit is contained in:
David Markowitz 2022-12-16 03:46:38 -08:00
parent 3f1b4339f5
commit 0d460c0eb3
4 changed files with 42 additions and 19 deletions

View File

@ -12,7 +12,10 @@
typedef int RESTICKET; typedef int RESTICKET;
// These are the same define, but they mean two different things in different contexts
// so a different define to distinguish what calculation is happening will help clarity.
#define FRAMES_TO_MS(x) 1000 / x #define FRAMES_TO_MS(x) 1000 / x
#define MS_TO_FRAMES(x) 1000 / x
//=========== FRAME TIMINGS =========== //=========== FRAME TIMINGS ===========
constexpr uint32_t highFramerate = 60; constexpr uint32_t highFramerate = 60;

View File

@ -79,10 +79,10 @@ void PerformanceManager::SelectProfile(LWOMAPID mapID) {
m_CurrentProfile = pair->second; m_CurrentProfile = pair->second;
} }
uint32_t PerformanceManager::GetServerFramerate() { uint32_t PerformanceManager::GetServerFrameDelta() {
if (UserManager::Instance()->GetUserCount() == 0) { if (UserManager::Instance()->GetUserCount() == 0) {
return m_InactiveProfile.serverFramerate; return m_InactiveProfile.serverFrameDelta;
} }
return m_CurrentProfile.serverFramerate; return m_CurrentProfile.serverFrameDelta;
} }

View File

@ -5,14 +5,14 @@
#include "dCommonVars.h" #include "dCommonVars.h"
struct PerformanceProfile { struct PerformanceProfile {
uint32_t serverFramerate; uint32_t serverFrameDelta;
}; };
class PerformanceManager { class PerformanceManager {
public: public:
static void SelectProfile(LWOMAPID mapID); static void SelectProfile(LWOMAPID mapID);
static uint32_t GetServerFramerate(); static uint32_t GetServerFrameDelta();
private: private:
static PerformanceProfile m_CurrentProfile; static PerformanceProfile m_CurrentProfile;

View File

@ -232,7 +232,7 @@ int main(int argc, char** argv) {
bool ready = false; bool ready = false;
uint32_t framesSinceMasterStatus = 0; uint32_t framesSinceMasterStatus = 0;
uint32_t framesSinceShutdownSequence = 0; uint32_t framesSinceShutdownSequence = 0;
uint32_t currentFramerate = highFrameDelta; uint32_t currentFramerate = highFramerate;
uint32_t ghostingStepCount = 0; uint32_t ghostingStepCount = 0;
auto ghostingLastTime = std::chrono::high_resolution_clock::now(); auto ghostingLastTime = std::chrono::high_resolution_clock::now();
@ -287,6 +287,14 @@ int main(int argc, char** argv) {
} }
} }
uint32_t currentFrameDelta = highFrameDelta;
// These values are adjust them selves to the current framerate should it update.
uint32_t logFlushTime = 15 * currentFramerate; // 15 seconds in frames
uint32_t shutdownTimeout = 10 * 60 * currentFramerate; // 10 minutes in frames
uint32_t noMasterConnectionTimeout = 5 * currentFramerate; // 5 seconds in frames
uint32_t chatReconnectionTime = 30 * currentFramerate; // 30 seconds in frames
uint32_t saveTime = 10 * 60 * currentFramerate; // 10 minutes in frames
uint32_t sqlPingTime = 10 * 60 * currentFramerate; // 10 minutes in frames
while (true) { while (true) {
Metrics::StartMeasurement(MetricVariable::Frame); Metrics::StartMeasurement(MetricVariable::Frame);
Metrics::StartMeasurement(MetricVariable::GameLoop); Metrics::StartMeasurement(MetricVariable::GameLoop);
@ -299,24 +307,37 @@ int main(int argc, char** argv) {
const auto occupied = UserManager::Instance()->GetUserCount() != 0; const auto occupied = UserManager::Instance()->GetUserCount() != 0;
uint32_t newFrameDelta = currentFrameDelta;
if (!ready) { if (!ready) {
currentFramerate = highFrameDelta; newFrameDelta = highFrameDelta;
} else { } else {
currentFramerate = PerformanceManager::GetServerFramerate(); newFrameDelta = PerformanceManager::GetServerFrameDelta();
}
// Update to the new framerate
if (newFrameDelta != currentFrameDelta) {
currentFrameDelta = newFrameDelta;
currentFramerate = MS_TO_FRAMES(newFrameDelta);
Game::logger->LogDebug("WorldServer", "Framerate for zone/instance/clone %i/%i/%i is now %i", zoneID, instanceID, cloneID, currentFramerate);
logFlushTime = 15 * currentFramerate; // 15 seconds in frames
shutdownTimeout = 10 * 60 * currentFramerate; // 10 minutes in frames
noMasterConnectionTimeout = 5 * currentFramerate; // 5 seconds in frames
chatReconnectionTime = 30 * currentFramerate; // 30 seconds in frames
saveTime = 10 * 60 * currentFramerate; // 10 minutes in frames
sqlPingTime = 10 * 60 * currentFramerate; // 10 minutes in frames
} }
//Warning if we ran slow //Warning if we ran slow
if (deltaTime > currentFramerate) { if (deltaTime > currentFrameDelta) {
Game::logger->Log("WorldServer", "We're running behind, dT: %f > %f (framerate)", deltaTime, currentFramerate); Game::logger->Log("WorldServer", "We're running behind, dT: %f > %f (framerate %i)", deltaTime, currentFrameDelta, currentFramerate);
} }
//Check if we're still connected to master: //Check if we're still connected to master:
if (!Game::server->GetIsConnectedToMaster()) { if (!Game::server->GetIsConnectedToMaster()) {
framesSinceMasterDisconnect++; framesSinceMasterDisconnect++;
uint32_t framesToWaitForMaster = ready ? 10 : 200; if (framesSinceMasterDisconnect >= noMasterConnectionTimeout && !Game::shouldShutdown) {
if (framesSinceMasterDisconnect >= framesToWaitForMaster && !Game::shouldShutdown) { Game::logger->Log("WorldServer", "Game loop running but no connection to master for %d frames, shutting down", noMasterConnectionTimeout);
Game::logger->Log("WorldServer", "Game loop running but no connection to master for %d frames, shutting down", framesToWaitForMaster);
Game::shouldShutdown = true; Game::shouldShutdown = true;
} }
} else framesSinceMasterDisconnect = 0; } else framesSinceMasterDisconnect = 0;
@ -325,8 +346,7 @@ int main(int argc, char** argv) {
if (!chatConnected) { if (!chatConnected) {
framesSinceChatDisconnect++; framesSinceChatDisconnect++;
// Attempt to reconnect every 30 seconds. if (framesSinceChatDisconnect >= chatReconnectionTime) {
if (framesSinceChatDisconnect >= 2000) {
framesSinceChatDisconnect = 0; framesSinceChatDisconnect = 0;
Game::chatServer->Connect(masterIP.c_str(), chatPort, "3.25 ND1", 8); Game::chatServer->Connect(masterIP.c_str(), chatPort, "3.25 ND1", 8);
@ -403,7 +423,7 @@ int main(int argc, char** argv) {
Metrics::EndMeasurement(MetricVariable::UpdateReplica); Metrics::EndMeasurement(MetricVariable::UpdateReplica);
//Push our log every 15s: //Push our log every 15s:
if (framesSinceLastFlush >= 1000) { if (framesSinceLastFlush >= logFlushTime) {
Game::logger->Flush(); Game::logger->Flush();
framesSinceLastFlush = 0; framesSinceLastFlush = 0;
} else framesSinceLastFlush++; } else framesSinceLastFlush++;
@ -420,7 +440,7 @@ int main(int argc, char** argv) {
} }
//Save all connected users every 10 minutes: //Save all connected users every 10 minutes:
if (framesSinceLastUsersSave >= 40000 && zoneID != 0) { if (framesSinceLastUsersSave >= saveTime && zoneID != 0) {
UserManager::Instance()->SaveAllActiveCharacters(); UserManager::Instance()->SaveAllActiveCharacters();
framesSinceLastUsersSave = 0; framesSinceLastUsersSave = 0;
@ -430,7 +450,7 @@ int main(int argc, char** argv) {
} else framesSinceLastUsersSave++; } else framesSinceLastUsersSave++;
//Every 10 min we ping our sql server to keep it alive hopefully: //Every 10 min we ping our sql server to keep it alive hopefully:
if (framesSinceLastSQLPing >= 40000) { if (framesSinceLastSQLPing >= sqlPingTime) {
//Find out the master's IP for absolutely no reason: //Find out the master's IP for absolutely no reason:
std::string masterIP; std::string masterIP;
uint32_t masterPort; uint32_t masterPort;
@ -451,7 +471,7 @@ int main(int argc, char** argv) {
Metrics::StartMeasurement(MetricVariable::Sleep); Metrics::StartMeasurement(MetricVariable::Sleep);
t += std::chrono::milliseconds(currentFramerate); t += std::chrono::milliseconds(currentFrameDelta);
std::this_thread::sleep_until(t); std::this_thread::sleep_until(t);
Metrics::EndMeasurement(MetricVariable::Sleep); Metrics::EndMeasurement(MetricVariable::Sleep);