性能优化 修复内存泄露
This commit is contained in:
parent
30cfeed736
commit
30e84a5bfa
@ -9,8 +9,11 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_BUILD_TYPE "Debug")
|
set(CMAKE_BUILD_TYPE "Debug")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DA8_TCP_SESSION2=1 -fsanitize=address -fno-omit-frame-pointer")
|
set(CMAKE_BUILD_TYPE "Release")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DA8_TCP_SESSION2=1")
|
||||||
|
#set(CMAKE_CXX_FLAGS_RELEASE "-O2 -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DA8_TCP_SESSION2=1 -fsanitize=address -fno-omit-frame-pointer")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DA8_TCP_SESSION2=1")
|
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DA8_TCP_SESSION2=1")
|
||||||
|
#set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DA8_TCP_SESSION2=1 -fsanitize=address -fno-omit-frame-pointer")
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
AFTER
|
AFTER
|
||||||
|
@ -24,10 +24,10 @@ Android::~Android()
|
|||||||
|
|
||||||
void Android::Initialize()
|
void Android::Initialize()
|
||||||
{
|
{
|
||||||
|
Human::Initialize();
|
||||||
health = meta->i->health();
|
health = meta->i->health();
|
||||||
skin.skin_id = 14001;
|
skin.skin_id = 14001;
|
||||||
skin.skin_lv = 1;
|
skin.skin_lv = 1;
|
||||||
RecalcSelfCollider();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Android::Update(int delta_time)
|
void Android::Update(int delta_time)
|
||||||
|
@ -59,11 +59,12 @@ static void SavePerfLog()
|
|||||||
RoomMgr::Instance()->RoomNum()
|
RoomMgr::Instance()->RoomNum()
|
||||||
});
|
});
|
||||||
if (App::Instance()->HasFlag(4)) {
|
if (App::Instance()->HasFlag(4)) {
|
||||||
a8::XPrintf("mainloop_time:%d netmsg_time:%d room:%d online:%d\n",
|
a8::XPrintf("mainloop_time:%d netmsg_time:%d room:%d over_room:%d online:%d\n",
|
||||||
{
|
{
|
||||||
App::Instance()->perf.max_run_delay_time,
|
App::Instance()->perf.max_run_delay_time,
|
||||||
App::Instance()->perf.max_dispatchmsg_time,
|
App::Instance()->perf.max_dispatchmsg_time,
|
||||||
RoomMgr::Instance()->RoomNum(),
|
RoomMgr::Instance()->RoomNum(),
|
||||||
|
RoomMgr::Instance()->OverRoomNum(),
|
||||||
PlayerMgr::Instance()->OnlineNum()
|
PlayerMgr::Instance()->OnlineNum()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -73,16 +74,15 @@ static void SavePerfLog()
|
|||||||
f8::HttpClientPool::Instance()->max_request_delay = 0;
|
f8::HttpClientPool::Instance()->max_request_delay = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::Init(int argc, char* argv[])
|
bool App::Init(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
this->argc = argc;
|
this->argc = argc;
|
||||||
this->argv = argv;
|
this->argv = argv;
|
||||||
|
|
||||||
if (!ParseOpt()) {
|
if (!ParseOpt()) {
|
||||||
terminated = true;
|
|
||||||
a8::XPrintf("gameserver启动失败,缺少-i参数\n", {});
|
a8::XPrintf("gameserver启动失败,缺少-i参数\n", {});
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
a8::XPrintf("gameserver starting instance_id:%d pid:%d game_id:%d\n", {instance_id, getpid(), GAME_ID});
|
a8::XPrintf("gameserver starting instance_id:%d pid:%d game_id:%d\n", {instance_id, getpid(), GAME_ID});
|
||||||
|
|
||||||
@ -101,8 +101,8 @@ void App::Init(int argc, char* argv[])
|
|||||||
JsonDataMgr::Instance()->Init();
|
JsonDataMgr::Instance()->Init();
|
||||||
MetaMgr::Instance()->Init();
|
MetaMgr::Instance()->Init();
|
||||||
uuid.SetMachineId(instance_id);
|
uuid.SetMachineId(instance_id);
|
||||||
PlayerMgr::Instance()->Init();
|
|
||||||
RoomMgr::Instance()->Init();
|
RoomMgr::Instance()->Init();
|
||||||
|
PlayerMgr::Instance()->Init();
|
||||||
GGListener::Instance()->Init();
|
GGListener::Instance()->Init();
|
||||||
|
|
||||||
a8::UdpLog::Instance()->Info("gameserver starting instance_id:%d pid:%d", {instance_id, getpid()});
|
a8::UdpLog::Instance()->Info("gameserver starting instance_id:%d pid:%d", {instance_id, getpid()});
|
||||||
@ -118,16 +118,24 @@ void App::Init(int argc, char* argv[])
|
|||||||
SavePerfLog();
|
SavePerfLog();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (HasFlag(7)) {
|
||||||
|
a8::Timer::Instance()->AddDeadLineTimer(
|
||||||
|
1000 * 60 * 2,
|
||||||
|
a8::XParams(),
|
||||||
|
[] (const a8::XParams& param)
|
||||||
|
{
|
||||||
|
App::Instance()->terminated = true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::UnInit()
|
void App::UnInit()
|
||||||
{
|
{
|
||||||
if (terminated) {
|
GGListener::Instance()->UnInit();
|
||||||
return;
|
|
||||||
}
|
|
||||||
GGListener::Instance()->Init();
|
|
||||||
RoomMgr::Instance()->UnInit();
|
|
||||||
PlayerMgr::Instance()->UnInit();
|
PlayerMgr::Instance()->UnInit();
|
||||||
|
RoomMgr::Instance()->UnInit();
|
||||||
MetaMgr::Instance()->UnInit();
|
MetaMgr::Instance()->UnInit();
|
||||||
JsonDataMgr::Instance()->UnInit();
|
JsonDataMgr::Instance()->UnInit();
|
||||||
f8::HttpClientPool::Instance()->UnInit();
|
f8::HttpClientPool::Instance()->UnInit();
|
||||||
@ -137,6 +145,8 @@ void App::UnInit()
|
|||||||
f8::TGLog::Instance()->UnInit();
|
f8::TGLog::Instance()->UnInit();
|
||||||
UnInitLog();
|
UnInitLog();
|
||||||
|
|
||||||
|
FreeSocketMsgQueue();
|
||||||
|
FreeIMMsgQueue();
|
||||||
delete im_msg_mutex_;
|
delete im_msg_mutex_;
|
||||||
im_msg_mutex_ = nullptr;
|
im_msg_mutex_ = nullptr;
|
||||||
delete msg_mutex_;
|
delete msg_mutex_;
|
||||||
@ -149,9 +159,6 @@ void App::UnInit()
|
|||||||
|
|
||||||
int App::Run()
|
int App::Run()
|
||||||
{
|
{
|
||||||
if (terminated) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
a8::UdpLog::Instance()->Info("gameserver running", {});
|
a8::UdpLog::Instance()->Info("gameserver running", {});
|
||||||
last_run_tick_ = a8::XGetTickCount();
|
last_run_tick_ = a8::XGetTickCount();
|
||||||
@ -499,3 +506,52 @@ bool App::HasFlag(int flag)
|
|||||||
{
|
{
|
||||||
return flags.find(flag) != flags.end();
|
return flags.find(flag) != flags.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void App::FreeSocketMsgQueue()
|
||||||
|
{
|
||||||
|
msg_mutex_->lock();
|
||||||
|
if (!work_node_) {
|
||||||
|
work_node_ = top_node_;
|
||||||
|
top_node_ = nullptr;
|
||||||
|
bot_node_ = nullptr;
|
||||||
|
}
|
||||||
|
while (work_node_) {
|
||||||
|
MsgNode* pdelnode = work_node_;
|
||||||
|
work_node_ = work_node_->next;
|
||||||
|
if (pdelnode->buf) {
|
||||||
|
free(pdelnode->buf);
|
||||||
|
}
|
||||||
|
free(pdelnode);
|
||||||
|
if (!work_node_) {
|
||||||
|
work_node_ = top_node_;
|
||||||
|
top_node_ = nullptr;
|
||||||
|
bot_node_ = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msg_mutex_->unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void App::FreeIMMsgQueue()
|
||||||
|
{
|
||||||
|
im_msg_mutex_->lock();
|
||||||
|
if (!im_work_node_) {
|
||||||
|
im_work_node_ = im_top_node_;
|
||||||
|
im_top_node_ = nullptr;
|
||||||
|
im_bot_node_ = nullptr;
|
||||||
|
}
|
||||||
|
while (im_work_node_) {
|
||||||
|
IMMsgNode* pdelnode = im_work_node_;
|
||||||
|
im_work_node_ = im_work_node_->next;
|
||||||
|
if (pdelnode->msgid == f8::IM_SysMsgQueue) {
|
||||||
|
a8::XParams* param = (a8::XParams*)pdelnode->params.param1.GetUserData();
|
||||||
|
delete param;
|
||||||
|
}
|
||||||
|
delete pdelnode;
|
||||||
|
if (!im_work_node_) {
|
||||||
|
im_work_node_ = im_top_node_;
|
||||||
|
im_top_node_ = nullptr;
|
||||||
|
im_bot_node_ = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
im_msg_mutex_->unlock();
|
||||||
|
}
|
||||||
|
@ -12,7 +12,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void Init(int argc, char* argv[]);
|
bool Init(int argc, char* argv[]);
|
||||||
void UnInit();
|
void UnInit();
|
||||||
|
|
||||||
int Run();
|
int Run();
|
||||||
@ -49,6 +49,8 @@ private:
|
|||||||
void UnInitLog();
|
void UnInitLog();
|
||||||
|
|
||||||
bool ParseOpt();
|
bool ParseOpt();
|
||||||
|
void FreeSocketMsgQueue();
|
||||||
|
void FreeIMMsgQueue();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
@ -68,6 +70,7 @@ public:
|
|||||||
4: 打印性能日志
|
4: 打印性能日志
|
||||||
5: 压力测试
|
5: 压力测试
|
||||||
6: 删除over room
|
6: 删除over room
|
||||||
|
7: 内存泄露测试
|
||||||
*/
|
*/
|
||||||
std::set<int> flags;
|
std::set<int> flags;
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#include "precompile.h"
|
#include "precompile.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int exitcode = 0;
|
int exitcode = 0;
|
||||||
App::Instance()->Init(argc, argv);
|
if (App::Instance()->Init(argc, argv)) {
|
||||||
exitcode = App::Instance()->Run();
|
exitcode = App::Instance()->Run();
|
||||||
App::Instance()->UnInit();
|
App::Instance()->UnInit();
|
||||||
|
}
|
||||||
return exitcode;
|
return exitcode;
|
||||||
}
|
}
|
||||||
|
@ -157,6 +157,10 @@ private:
|
|||||||
for (auto& meta : safearea_meta_list) {
|
for (auto& meta : safearea_meta_list) {
|
||||||
MetaData::SafeArea& item = a8::FastAppend(safearea_list);
|
MetaData::SafeArea& item = a8::FastAppend(safearea_list);
|
||||||
item.i = &meta;
|
item.i = &meta;
|
||||||
|
if (App::Instance()->HasBit(7)) {
|
||||||
|
meta.set_wait_time(3);
|
||||||
|
meta.set_shrink_speed(500);
|
||||||
|
}
|
||||||
safearea_hash[item.i->id()] = &item;
|
safearea_hash[item.i->id()] = &item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +96,7 @@ void Room::UnInit()
|
|||||||
delete pair.second;
|
delete pair.second;
|
||||||
}
|
}
|
||||||
removed_robot_hash_.clear();
|
removed_robot_hash_.clear();
|
||||||
|
grid_service.UnInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Room::Update(int delta_time)
|
void Room::Update(int delta_time)
|
||||||
|
@ -43,6 +43,14 @@ void RoomMgr::Init()
|
|||||||
|
|
||||||
void RoomMgr::UnInit()
|
void RoomMgr::UnInit()
|
||||||
{
|
{
|
||||||
|
for (auto& pair : room_hash_) {
|
||||||
|
pair.second->UnInit();
|
||||||
|
delete pair.second;
|
||||||
|
}
|
||||||
|
for (auto& pair : over_room_hash_) {
|
||||||
|
pair.second->UnInit();
|
||||||
|
delete pair.second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomMgr::Update(int delta_time)
|
void RoomMgr::Update(int delta_time)
|
||||||
@ -131,6 +139,11 @@ int RoomMgr::RoomNum()
|
|||||||
return room_hash_.size();
|
return room_hash_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int RoomMgr::OverRoomNum()
|
||||||
|
{
|
||||||
|
return over_room_hash_.size();
|
||||||
|
}
|
||||||
|
|
||||||
Room* RoomMgr::GetJoinableRoom(const std::string& account_id)
|
Room* RoomMgr::GetJoinableRoom(const std::string& account_id)
|
||||||
{
|
{
|
||||||
for (auto& pair : inactive_room_hash_) {
|
for (auto& pair : inactive_room_hash_) {
|
||||||
|
@ -23,6 +23,7 @@ class RoomMgr : public a8::Singleton<RoomMgr>
|
|||||||
void _CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg);
|
void _CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg);
|
||||||
void ActiveRoom(long long room_uuid);
|
void ActiveRoom(long long room_uuid);
|
||||||
int RoomNum();
|
int RoomNum();
|
||||||
|
int OverRoomNum();
|
||||||
Room* GetRoomByUuid(long long uuid);
|
Room* GetRoomByUuid(long long uuid);
|
||||||
void AddOverRoom(long long room_uuid);
|
void AddOverRoom(long long room_uuid);
|
||||||
|
|
||||||
|
2
third_party/a8engine
vendored
2
third_party/a8engine
vendored
@ -1 +1 @@
|
|||||||
Subproject commit fc4a7d7d241002c04aaa09dbf6d6dac91f659a04
|
Subproject commit 07650796618d3d5f86bc3749e817bdc4848458b9
|
2
third_party/framework
vendored
2
third_party/framework
vendored
@ -1 +1 @@
|
|||||||
Subproject commit fd72ea56059dc8545920e33d436dad5a1d3700fb
|
Subproject commit 0d1fd33446c6dda16e8ecb5a0ad9b0e42c44deee
|
Loading…
x
Reference in New Issue
Block a user