内存优化
This commit is contained in:
@@ -10,46 +10,9 @@
|
||||
#include "Local_Server/Data_Source/Data_Source.h"
|
||||
#include "Local_Server/State_Report/State_Report.h"
|
||||
#include "Local_Server/server/Global.h"
|
||||
#include "Local_Server/server/Memory_Monitor.h"
|
||||
#include "Local_Server/server/Memory_Resource.h"
|
||||
#include "Local_Server/server/io_coro.h"
|
||||
// ./server ./config
|
||||
#ifdef __linux__
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
struct Catch_Memory {
|
||||
Catch_Memory() {
|
||||
sm = (std::int64_t)get_system_memory();
|
||||
cur = (std::int64_t)get_process_memory();
|
||||
}
|
||||
std::int64_t MB = 1024 * 1024;
|
||||
bool catch_ok() {
|
||||
auto old_memory = cur;
|
||||
cur = (std::int64_t)get_process_memory();
|
||||
auto change_mb = (cur - old_memory) / MB;
|
||||
auto cur_mb = cur / MB;
|
||||
// std::cout << get_current_date_string() << " 时内存" << cur_mb << "MB "
|
||||
// << " 变更" << change_mb << "MB" << std::endl;
|
||||
if (cur > memory_max) {
|
||||
auto rate = (double)cur / (double)sm;
|
||||
std::cout << get_current_date_string() + " 抓住内存暴涨:" << cur_mb << "MB" << " 变更" << change_mb
|
||||
<< "MB" << std::endl;
|
||||
std::cout << "\t内存占用" << rate << "%" << std::endl;
|
||||
stop_program = SIGINT;
|
||||
#if WIN32
|
||||
#else
|
||||
system("top");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#if WIN32
|
||||
std::int64_t memory_max = 1 * 1024 * 1024 * 1024;
|
||||
#else
|
||||
std::int64_t memory_max = 1 * 1024 * 1024 * 1024;
|
||||
#endif
|
||||
std::int64_t cur;
|
||||
std::int64_t sm;
|
||||
};
|
||||
int psc_main(int argc, char* argv[]) {
|
||||
std::cout << "wyc_main" << std::endl;
|
||||
if (argc >= 2) {
|
||||
@@ -133,22 +96,14 @@ int psc_main(int argc, char* argv[]) {
|
||||
g->dsp_config.init_env();
|
||||
auto coro = Coro::instance();
|
||||
coro->start();
|
||||
// Catch_Memory cm;
|
||||
while (stop_program == 0) {
|
||||
for (auto& ds : g->mode_acs.data_source_config.map.list()) {
|
||||
ds->delete_timeout_aircraft();
|
||||
}
|
||||
#ifdef __linux__
|
||||
if (g->mode_acs.settings.member<&Mode_ACS_Config_Data::monitor_msg_live>().snapshot())
|
||||
malloc_trim(0);
|
||||
#endif
|
||||
collect_server_memory(false);
|
||||
Memory_Monitor::instance().sample();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
if (Global::instance()->init_ok) {
|
||||
// if (cm.catch_ok()) {
|
||||
// stop_program = SIGINT;
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
}
|
||||
coro->stop();
|
||||
if (stop_program == SIGINT || stop_program == SIGTERM) {
|
||||
@@ -157,5 +112,7 @@ int psc_main(int argc, char* argv[]) {
|
||||
return 0;
|
||||
}
|
||||
int main(int argc, char* argv[]) {
|
||||
initialize_server_memory_resource();
|
||||
Memory_Monitor::instance().sample();
|
||||
return redict_main_with_gtest(argc, argv, psc_main);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user