diff --git a/server/wsproxy/app.cc b/server/wsproxy/app.cc index 67f2f46..55d49c0 100644 --- a/server/wsproxy/app.cc +++ b/server/wsproxy/app.cc @@ -54,7 +54,8 @@ const char* const PROJ_LOG_FILENAME_FMT = "log_$pid_%Y%m%d.log"; static void SavePerfLog() { a8::UdpLog::Instance()->Info(" max_run_delay_time:%d max_timer_idle:%d " - "in_data_size:%d out_data_size:%d msgnode_size:%d read_count:%d max_login_time:%d", + "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, @@ -63,6 +64,7 @@ static void SavePerfLog() App::Instance()->msgnode_size_, App::Instance()->perf.read_count, App::Instance()->perf.max_login_time, + App::Instance()->perf.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", @@ -77,6 +79,7 @@ static void SavePerfLog() 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; #else App::Instance()->perf = PerfMonitor(); #endif diff --git a/server/wsproxy/constant.h b/server/wsproxy/constant.h index a1ab429..3165ef0 100644 --- a/server/wsproxy/constant.h +++ b/server/wsproxy/constant.h @@ -39,3 +39,5 @@ const int POSTFIX_LEN = 7; const int MAX_NODE_ID = 8; const int MAX_INSTANCE_ID = 500; + +const char* const azw_account_id = "6001_2001_oJqfX5c4pvW-wlarmcrvEO6BQjd8"; diff --git a/server/wsproxy/gameclientmgr.cc b/server/wsproxy/gameclientmgr.cc index 34eb8be..f6bf793 100644 --- a/server/wsproxy/gameclientmgr.cc +++ b/server/wsproxy/gameclientmgr.cc @@ -7,6 +7,7 @@ #include "target_conn.h" #include "target_conn_mgr.h" #include "GCListener.h" +#include "app.h" void GameClientMgr::Init() { @@ -18,6 +19,7 @@ void GameClientMgr::UnInit() delete pair.second; } socket_hash_.clear(); + pending_account_hash_.clear(); } void GameClientMgr::OnClientDisconnect(a8::XParams& param) @@ -31,6 +33,7 @@ void GameClientMgr::OnClientDisconnect(a8::XParams& param) socket_hash_.erase(param.sender); delete client; } + RemovePendingAccount(param.sender); } void GameClientMgr::OnTargetServerDisconnect(a8::XParams& param) @@ -42,6 +45,7 @@ void GameClientMgr::OnTargetServerDisconnect(a8::XParams& param) } } for (auto& client : delete_client) { + RemovePendingAccount(client->socket_handle); GCListener::Instance()->ForceCloseClient(client->socket_handle); socket_hash_.erase(client->socket_handle); delete client; @@ -71,6 +75,56 @@ void GameClientMgr::BindTargetConn(int socket_handle, int conn_instance_id) client->socket_handle = socket_handle; client->conn = conn; socket_hash_[client->socket_handle] = client; + { + auto itr = pending_account_hash_.find(socket_handle); + if (itr != pending_account_hash_.end()) { + std::string account_id = std::get<0>(itr->second); + long long req_tick = std::get<1>(itr->second); + long long cur_tick = a8::XGetTickCount(); + if (cur_tick - req_tick > App::Instance()->perf.max_join_time) { + App::Instance()->perf.max_join_time = cur_tick - req_tick; + } + if (account_id == azw_account_id) { + a8::UdpLog::Instance()->Info("%s join time:%d", + { + account_id, + cur_tick - req_tick + }); + } + RemovePendingAccount(socket_handle); + } + } } } } + +void GameClientMgr::AddPendingAccount(const std::string& account_id, int socket_handle, long long req_tick) +{ + auto itr = pending_account_hash_.find(socket_handle); + if (itr == pending_account_hash_.end()){ + timer_list* timer = a8::Timer::Instance()->AddDeadLineTimerAndAttach(1000 * 10, + a8::XParams() + .SetSender(socket_handle), + [] (const a8::XParams& param) + { + GameClientMgr::Instance()->pending_account_hash_.erase(param.sender); + App::Instance()->perf.max_join_time = std::max(1000 * 10, App::Instance()->perf.max_join_time); + }, + &timer_attacher_.timer_list_ + ); + pending_account_hash_[socket_handle] = std::make_tuple( + account_id, + socket_handle, + timer + ); + } +} + +void GameClientMgr::RemovePendingAccount(int socket_handle) +{ + auto itr = pending_account_hash_.find(socket_handle); + if (itr != pending_account_hash_.end()) { + a8::Timer::Instance()->DeleteTimer(std::get<2>(itr->second)); + pending_account_hash_.erase(itr); + } +} diff --git a/server/wsproxy/gameclientmgr.h b/server/wsproxy/gameclientmgr.h index 28bbb71..6144316 100644 --- a/server/wsproxy/gameclientmgr.h +++ b/server/wsproxy/gameclientmgr.h @@ -1,5 +1,7 @@ #pragma once +#include + class GameClient; class GameClientMgr : public a8::Singleton { @@ -17,7 +19,14 @@ class GameClientMgr : public a8::Singleton void OnTargetServerConnect(a8::XParams& param); GameClient* GetGameClientBySocket(int sockhande); void BindTargetConn(int socket_handle, int conn_instance_id); + void AddPendingAccount(const std::string& account_id, int socket_handle, long long req_tick); + +private: + + void RemovePendingAccount(int socket_handle); private: + a8::TimerAttacher timer_attacher_; std::map socket_hash_; + std::map> pending_account_hash_; }; diff --git a/server/wsproxy/mastersvrmgr.cc b/server/wsproxy/mastersvrmgr.cc index d4f56fd..5b5d5d4 100644 --- a/server/wsproxy/mastersvrmgr.cc +++ b/server/wsproxy/mastersvrmgr.cc @@ -12,11 +12,10 @@ #include "target_conn.h" #include "target_conn_mgr.h" #include "app.h" +#include "gameclientmgr.h" #include "framework/cpp/netmsghandler.h" -const char* azw_account_id = "6001_2001_oJqfX5c4pvW-wlarmcrvEO6BQjd8"; - void MasterSvrMgr::Init() { curr_context_id_ = a8::MakeInt64(0, time(nullptr) + 1000 * 60 * 10); @@ -137,6 +136,7 @@ void MasterSvrMgr::RequestTargetServer(f8::MsgHdr& hdr, const std::string& team_ if (req_handle_time > App::Instance()->perf.max_login_time) { App::Instance()->perf.max_login_time = req_handle_time; } + GameClientMgr::Instance()->AddPendingAccount(param.param2, param.param1, param.param3); }; a8::Timer::Instance()->AddDeadLineTimerAndAttach(1000 * 10, a8::XParams() diff --git a/server/wsproxy/types.h b/server/wsproxy/types.h index ce0d147..f4e1303 100644 --- a/server/wsproxy/types.h +++ b/server/wsproxy/types.h @@ -6,6 +6,7 @@ struct PerfMonitor int max_dispatchmsg_time = 0; int max_timer_idle = 0; int max_login_time = 0; + int max_join_time = 0; long long out_data_size = 0; long long in_data_size = 0; long long read_count = 0;