From 0ed4c1f3e2a6791e2e2112a50493216675348e3e Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 24 Apr 2023 15:27:41 +0800 Subject: [PATCH] 1 --- server/wsproxy/app.cc | 38 ++++++++++++++++----------------- server/wsproxy/app.h | 9 ++++---- server/wsproxy/downstreammgr.cc | 8 +++---- server/wsproxy/mastermgr.cc | 8 +++---- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/server/wsproxy/app.cc b/server/wsproxy/app.cc index c561686..61f0dc8 100644 --- a/server/wsproxy/app.cc +++ b/server/wsproxy/app.cc @@ -59,28 +59,28 @@ static void SavePerfLog() "in_data_size:%d out_data_size:%d msgnode_size:%d read_count:%d max_login_time:%d " "max_join_time:%d", { - App::Instance()->perf.max_run_delay_time, - App::Instance()->perf.max_timer_idle, - App::Instance()->perf.in_data_size, - App::Instance()->perf.out_data_size, + App::Instance()->GetPerf().max_run_delay_time, + App::Instance()->GetPerf().max_timer_idle, + App::Instance()->GetPerf().in_data_size, + App::Instance()->GetPerf().out_data_size, //App::Instance()->msgnode_size_, - App::Instance()->perf.read_count, - App::Instance()->perf.max_login_time, - App::Instance()->perf.max_join_time, + App::Instance()->GetPerf().read_count, + App::Instance()->GetPerf().max_login_time, + App::Instance()->GetPerf().max_join_time, }); if (App::Instance()->HasFlag(2)) { a8::XPrintf("mainloop_time:%d netmsg_time:%d send_node_num:%d sent_bytes_num:%d\n", { - App::Instance()->perf.max_run_delay_time, - App::Instance()->perf.max_dispatchmsg_time, + App::Instance()->GetPerf().max_run_delay_time, + App::Instance()->GetPerf().max_dispatchmsg_time, GCListener::Instance()->GetSendNodeNum(), GCListener::Instance()->GetSentBytesNum() }); } - App::Instance()->perf.max_run_delay_time = 0; - App::Instance()->perf.max_timer_idle = 0; - App::Instance()->perf.max_login_time = 0; - App::Instance()->perf.max_join_time = 0; + App::Instance()->GetPerf().max_run_delay_time = 0; + App::Instance()->GetPerf().max_timer_idle = 0; + App::Instance()->GetPerf().max_login_time = 0; + App::Instance()->GetPerf().max_join_time = 0; } bool App::Init(int argc, char* argv[]) @@ -90,7 +90,7 @@ bool App::Init(int argc, char* argv[]) this->argv_ = argv; if (!ParseOpt()) { - terminated = true; + terminated_ = true; if (node_id_ <= 0) { a8::XPrintf("gameserver启动失败,缺少-n参数\n", {}); } else if (node_id_ > MAX_NODE_ID) { @@ -154,7 +154,7 @@ bool App::Init(int argc, char* argv[]) [] (int event, const a8::Args* args) { if (a8::TIMER_EXEC_EVENT == event) { - App::Instance()->terminated = true; + App::Instance()->terminated_ = true; App::Instance()->NotifyLoopCond(); } } @@ -167,7 +167,7 @@ bool App::Init(int argc, char* argv[]) [] (int event, const a8::Args* args) { if (a8::TIMER_EXEC_EVENT == event) { - App::Instance()->shutdowned = true; + App::Instance()->shutdowned_ = true; a8::XPrintf("shutdowned\n", {}); } } @@ -207,13 +207,13 @@ int App::Run() { int ret = 0; f8::UdpLog::Instance()->Info("wsproxy running", {}); - while (!terminated) { + while (!terminated_) { a8::tick_t begin_tick = a8::XGetTickCount(); QuickExecute(); SlowerExecute(); a8::tick_t end_tick = a8::XGetTickCount(); - if (end_tick - begin_tick > perf.max_run_delay_time) { - perf.max_run_delay_time = end_tick - begin_tick; + if (end_tick - begin_tick > GetPerf().max_run_delay_time) { + GetPerf().max_run_delay_time = end_tick - begin_tick; } Schedule(); } diff --git a/server/wsproxy/app.h b/server/wsproxy/app.h index fc5c2db..7a1fdb8 100644 --- a/server/wsproxy/app.h +++ b/server/wsproxy/app.h @@ -41,6 +41,7 @@ public: long long NewUuid(); int GetNodeId() { return node_id_; } int GetInstanceId() { return instance_id_; } + PerfMonitor& GetPerf() { return perf_; } private: void QuickExecute(); @@ -62,14 +63,12 @@ private: void FreeSocketMsgQueue(); void FreeUdpMsgQueue(); -public: - volatile bool terminated = false; - volatile bool shutdowned = false; - PerfMonitor perf; - private: int argc_ = 0; char** argv_ = nullptr; + PerfMonitor perf_; + volatile bool terminated_ = false; + volatile bool shutdowned_ = false; int node_id_ = 0; int instance_id_ = 0; diff --git a/server/wsproxy/downstreammgr.cc b/server/wsproxy/downstreammgr.cc index 1818e52..8500356 100644 --- a/server/wsproxy/downstreammgr.cc +++ b/server/wsproxy/downstreammgr.cc @@ -95,8 +95,8 @@ void DownStreamMgr::BindUpStream(int socket_handle, int conn_instance_id) { if (auto pending_account = GetPendingAccount(socket_handle)) { long long cur_tick = a8::XGetTickCount(); - if (cur_tick - pending_account->add_tick > App::Instance()->perf.max_join_time) { - App::Instance()->perf.max_join_time = cur_tick - pending_account->add_tick; + if (cur_tick - pending_account->add_tick > App::Instance()->GetPerf().max_join_time) { + App::Instance()->GetPerf().max_join_time = cur_tick - pending_account->add_tick; } f8::UdpLog::Instance()->Info("BindUpStream account_id:%s", { @@ -120,8 +120,8 @@ void DownStreamMgr::AddPendingAccount(const std::string& account_id, int socket_ { if (a8::TIMER_EXEC_EVENT == event) { pending_account_hash_.erase(socket_handle); - App::Instance()->perf.max_join_time = - std::max((long long)1000 * 10, App::Instance()->perf.max_join_time); + App::Instance()->GetPerf().max_join_time = + std::max((long long)1000 * 10, App::Instance()->GetPerf().max_join_time); } }, &timer_attacher_ diff --git a/server/wsproxy/mastermgr.cc b/server/wsproxy/mastermgr.cc index 2224dc3..8720f4d 100644 --- a/server/wsproxy/mastermgr.cc +++ b/server/wsproxy/mastermgr.cc @@ -159,14 +159,14 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr, req->socket_handle ); long long req_handle_time = a8::XGetTickCount() - req->req_tick; - if (req_handle_time > App::Instance()->perf.max_login_time) { - App::Instance()->perf.max_login_time = req_handle_time; + if (req_handle_time > App::Instance()->GetPerf().max_login_time) { + App::Instance()->GetPerf().max_login_time = req_handle_time; } DownStreamMgr::Instance()->AddPendingAccount(req->account_id, req->socket_handle, req->req_tick); } else if (ALLOC_TARGET_SERVER_SUCCESS_TIMER_EVENT == event) { long long req_handle_time = a8::XGetTickCount() - req->req_tick; - if (req_handle_time > App::Instance()->perf.max_login_time) { - App::Instance()->perf.max_login_time = req_handle_time; + if (req_handle_time > App::Instance()->GetPerf().max_login_time) { + App::Instance()->GetPerf().max_login_time = req_handle_time; } DownStreamMgr::Instance()->AddPendingAccount(req->account_id, req->socket_handle, req->req_tick); }