This commit is contained in:
aozhiwei 2019-12-12 16:14:51 +08:00
parent e2b9fd1517
commit fb958c1a83
6 changed files with 72 additions and 3 deletions

View File

@ -54,7 +54,8 @@ const char* const PROJ_LOG_FILENAME_FMT = "log_$pid_%Y%m%d.log";
static void SavePerfLog() static void SavePerfLog()
{ {
a8::UdpLog::Instance()->Info(" max_run_delay_time:%d max_timer_idle:%d " 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_run_delay_time,
App::Instance()->perf.max_timer_idle, App::Instance()->perf.max_timer_idle,
@ -63,6 +64,7 @@ static void SavePerfLog()
App::Instance()->msgnode_size_, App::Instance()->msgnode_size_,
App::Instance()->perf.read_count, App::Instance()->perf.read_count,
App::Instance()->perf.max_login_time, App::Instance()->perf.max_login_time,
App::Instance()->perf.max_join_time,
}); });
if (App::Instance()->HasFlag(2)) { if (App::Instance()->HasFlag(2)) {
a8::XPrintf("mainloop_time:%d netmsg_time:%d send_node_num:%d sent_bytes_num:%d\n", 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_run_delay_time = 0;
App::Instance()->perf.max_timer_idle = 0; App::Instance()->perf.max_timer_idle = 0;
App::Instance()->perf.max_login_time = 0; App::Instance()->perf.max_login_time = 0;
App::Instance()->perf.max_join_time = 0;
#else #else
App::Instance()->perf = PerfMonitor(); App::Instance()->perf = PerfMonitor();
#endif #endif

View File

@ -39,3 +39,5 @@ const int POSTFIX_LEN = 7;
const int MAX_NODE_ID = 8; const int MAX_NODE_ID = 8;
const int MAX_INSTANCE_ID = 500; const int MAX_INSTANCE_ID = 500;
const char* const azw_account_id = "6001_2001_oJqfX5c4pvW-wlarmcrvEO6BQjd8";

View File

@ -7,6 +7,7 @@
#include "target_conn.h" #include "target_conn.h"
#include "target_conn_mgr.h" #include "target_conn_mgr.h"
#include "GCListener.h" #include "GCListener.h"
#include "app.h"
void GameClientMgr::Init() void GameClientMgr::Init()
{ {
@ -18,6 +19,7 @@ void GameClientMgr::UnInit()
delete pair.second; delete pair.second;
} }
socket_hash_.clear(); socket_hash_.clear();
pending_account_hash_.clear();
} }
void GameClientMgr::OnClientDisconnect(a8::XParams& param) void GameClientMgr::OnClientDisconnect(a8::XParams& param)
@ -31,6 +33,7 @@ void GameClientMgr::OnClientDisconnect(a8::XParams& param)
socket_hash_.erase(param.sender); socket_hash_.erase(param.sender);
delete client; delete client;
} }
RemovePendingAccount(param.sender);
} }
void GameClientMgr::OnTargetServerDisconnect(a8::XParams& param) void GameClientMgr::OnTargetServerDisconnect(a8::XParams& param)
@ -42,6 +45,7 @@ void GameClientMgr::OnTargetServerDisconnect(a8::XParams& param)
} }
} }
for (auto& client : delete_client) { for (auto& client : delete_client) {
RemovePendingAccount(client->socket_handle);
GCListener::Instance()->ForceCloseClient(client->socket_handle); GCListener::Instance()->ForceCloseClient(client->socket_handle);
socket_hash_.erase(client->socket_handle); socket_hash_.erase(client->socket_handle);
delete client; delete client;
@ -71,6 +75,56 @@ void GameClientMgr::BindTargetConn(int socket_handle, int conn_instance_id)
client->socket_handle = socket_handle; client->socket_handle = socket_handle;
client->conn = conn; client->conn = conn;
socket_hash_[client->socket_handle] = client; 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);
}
}

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <a8/timer.h>
class GameClient; class GameClient;
class GameClientMgr : public a8::Singleton<GameClientMgr> class GameClientMgr : public a8::Singleton<GameClientMgr>
{ {
@ -17,7 +19,14 @@ class GameClientMgr : public a8::Singleton<GameClientMgr>
void OnTargetServerConnect(a8::XParams& param); void OnTargetServerConnect(a8::XParams& param);
GameClient* GetGameClientBySocket(int sockhande); GameClient* GetGameClientBySocket(int sockhande);
void BindTargetConn(int socket_handle, int conn_instance_id); 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: private:
a8::TimerAttacher timer_attacher_;
std::map<int, GameClient*> socket_hash_; std::map<int, GameClient*> socket_hash_;
std::map<int, std::tuple<std::string, long long, timer_list*>> pending_account_hash_;
}; };

View File

@ -12,11 +12,10 @@
#include "target_conn.h" #include "target_conn.h"
#include "target_conn_mgr.h" #include "target_conn_mgr.h"
#include "app.h" #include "app.h"
#include "gameclientmgr.h"
#include "framework/cpp/netmsghandler.h" #include "framework/cpp/netmsghandler.h"
const char* azw_account_id = "6001_2001_oJqfX5c4pvW-wlarmcrvEO6BQjd8";
void MasterSvrMgr::Init() void MasterSvrMgr::Init()
{ {
curr_context_id_ = a8::MakeInt64(0, time(nullptr) + 1000 * 60 * 10); 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) { if (req_handle_time > App::Instance()->perf.max_login_time) {
App::Instance()->perf.max_login_time = req_handle_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::Timer::Instance()->AddDeadLineTimerAndAttach(1000 * 10,
a8::XParams() a8::XParams()

View File

@ -6,6 +6,7 @@ struct PerfMonitor
int max_dispatchmsg_time = 0; int max_dispatchmsg_time = 0;
int max_timer_idle = 0; int max_timer_idle = 0;
int max_login_time = 0; int max_login_time = 0;
int max_join_time = 0;
long long out_data_size = 0; long long out_data_size = 0;
long long in_data_size = 0; long long in_data_size = 0;
long long read_count = 0; long long read_count = 0;