TSG-8487: 使用参数设置rapidjson为每个日志句柄预申请的内存大小,默认为8K

This commit is contained in:
liuxueli
2021-11-13 13:27:59 +03:00
parent 86020118e5
commit 36c36102f3
4 changed files with 41 additions and 4 deletions

View File

@@ -85,7 +85,13 @@ id2field_t g_tsg_fs2_field[TSG_FS2_MAX]={{0, TSG_FS2_TCP_LINKS, "tcp_links"},
{0, TSG_FS2_DDOS_SUCCESS_LOG, "ddos_suc_log"}, {0, TSG_FS2_DDOS_SUCCESS_LOG, "ddos_suc_log"},
{0, TSG_FS2_DDOS_FAILED_LOG, "ddos_fai_log"}, {0, TSG_FS2_DDOS_FAILED_LOG, "ddos_fai_log"},
{0, TSG_FS2_SET_TIMOUT_SUCCESS, "set_timeout_suc"}, {0, TSG_FS2_SET_TIMOUT_SUCCESS, "set_timeout_suc"},
{0, TSG_FS2_SET_TIMOUT_FAILED, "set_timeout_fai"} {0, TSG_FS2_SET_TIMOUT_FAILED, "set_timeout_fai"},
{0, TSG_FS2_CREATE_LOG_HANDLE, "create_log_cnt"},
{0, TSG_FS2_DUP_LOG_HANDLE, "dup_log_cnt"},
{0, TSG_FS2_APPEND_LOG_HANDLE, "append_log_cnt"},
{0, TSG_FS2_FREE_LOG_HANDLE, "free_log_cnt"},
{0, TSG_FS2_FREE_RAPID_SIZE, "free_rapid_size"},
{0, TSG_FS2_FREE_RAPID_CAPACITY, "free_rapid_capacity"}
}; };
id2field_t g_tsg_proto_name2id[PROTO_MAX]={{PROTO_UNKONWN, 0, "unknown"}, id2field_t g_tsg_proto_name2id[PROTO_MAX]={{PROTO_UNKONWN, 0, "unknown"},

View File

@@ -113,6 +113,12 @@ enum TSG_FS2_TYPE{
TSG_FS2_DDOS_FAILED_LOG, TSG_FS2_DDOS_FAILED_LOG,
TSG_FS2_SET_TIMOUT_SUCCESS, TSG_FS2_SET_TIMOUT_SUCCESS,
TSG_FS2_SET_TIMOUT_FAILED, TSG_FS2_SET_TIMOUT_FAILED,
TSG_FS2_CREATE_LOG_HANDLE,
TSG_FS2_DUP_LOG_HANDLE,
TSG_FS2_APPEND_LOG_HANDLE,
TSG_FS2_FREE_LOG_HANDLE,
TSG_FS2_FREE_RAPID_SIZE,
TSG_FS2_FREE_RAPID_CAPACITY,
TSG_FS2_MAX TSG_FS2_MAX
}; };

View File

@@ -37,6 +37,7 @@ struct tsg_log_instance_t *g_tsg_log_instance;
struct TLD_handle_t struct TLD_handle_t
{ {
int thread_id; int thread_id;
MemoryPoolAllocator<> *valueAllocator;
Document *document; Document *document;
}; };
@@ -831,13 +832,26 @@ static int action2fs_id(int action)
int TLD_cancel(struct TLD_handle_t *handle) int TLD_cancel(struct TLD_handle_t *handle)
{ {
long long length=0;
if (handle != NULL) if (handle != NULL)
{ {
if (handle->document != NULL) if (handle->document != NULL)
{ {
length=handle->document->GetAllocator().Size();
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_FREE_RAPID_SIZE], 0, FS_OP_ADD, length);
length=handle->document->GetAllocator().Capacity();
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_FREE_RAPID_CAPACITY], 0, FS_OP_ADD, length);
delete handle->document; delete handle->document;
handle->document = NULL; handle->document = NULL;
delete handle->valueAllocator;
handle->valueAllocator=NULL;
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_FREE_LOG_HANDLE], 0, FS_OP_ADD, 1);
} }
free(handle); free(handle);
handle = NULL; handle = NULL;
} }
@@ -887,6 +901,8 @@ int TLD_append(struct TLD_handle_t *handle, char *key, void *value, TLD_TYPE typ
break; break;
} }
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_APPEND_LOG_HANDLE], 0, FS_OP_ADD, 1);
return 0; return 0;
} }
@@ -902,6 +918,9 @@ struct TLD_handle_t *TLD_duplicate(struct TLD_handle_t *handle)
//_handle->document->SetObject(); //_handle->document->SetObject();
_handle->document->CopyFrom(*handle->document, _handle->document->GetAllocator()); _handle->document->CopyFrom(*handle->document, _handle->document->GetAllocator());
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_DUP_LOG_HANDLE], 0, FS_OP_ADD, 1);
return _handle; return _handle;
} }
@@ -911,9 +930,13 @@ struct TLD_handle_t *TLD_create(int thread_id)
struct TLD_handle_t *_handle=(struct TLD_handle_t *)calloc(1, sizeof(struct TLD_handle_t)); struct TLD_handle_t *_handle=(struct TLD_handle_t *)calloc(1, sizeof(struct TLD_handle_t));
_handle->thread_id = thread_id; _handle->thread_id = thread_id;
_handle->document = new Document();
_handle->valueAllocator =new MemoryPoolAllocator<>(g_tsg_log_instance->rapidjson_chunk_capacity);
_handle->document = new Document(_handle->valueAllocator);
_handle->document->SetObject(); _handle->document->SetObject();
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_CREATE_LOG_HANDLE], 0, FS_OP_ADD, 1);
return _handle; return _handle;
} }
@@ -1392,6 +1415,7 @@ struct tsg_log_instance_t *tsg_sendlog_init(const char *conffile)
MESA_load_profile_string_def(conffile, "TSG_LOG", "LOG_PATH", _instance->log_path, sizeof(_instance->log_path), "./tsglog/tsglog"); MESA_load_profile_string_def(conffile, "TSG_LOG", "LOG_PATH", _instance->log_path, sizeof(_instance->log_path), "./tsglog/tsglog");
MESA_load_profile_int_def(conffile, "TSG_LOG", "SEND_USER_REGION", &(_instance->send_user_region), 0); MESA_load_profile_int_def(conffile, "TSG_LOG", "SEND_USER_REGION", &(_instance->send_user_region), 0);
MESA_load_profile_int_def(conffile, "TSG_LOG", "SEND_DATA_CENTER_SWITCH", &(_instance->send_data_center), 0); MESA_load_profile_int_def(conffile, "TSG_LOG", "SEND_DATA_CENTER_SWITCH", &(_instance->send_data_center), 0);
MESA_load_profile_int_def(conffile, "TSG_LOG", "RAPIDJSON_CHUNK_CAPACITY", &(_instance->rapidjson_chunk_capacity), 8096);
MESA_load_profile_int_def(conffile, "TSG_LOG", "APP_ID_TYPE", &(_instance->app_id_type), 1); //0: int, 1: string MESA_load_profile_int_def(conffile, "TSG_LOG", "APP_ID_TYPE", &(_instance->app_id_type), 1); //0: int, 1: string
MESA_load_profile_string_def(conffile, "TSG_LOG", "L7_UNKNOWN_NAME", _instance->l7_unknown_name, sizeof(_instance->l7_unknown_name), "UNCATEGORIZED"); MESA_load_profile_string_def(conffile, "TSG_LOG", "L7_UNKNOWN_NAME", _instance->l7_unknown_name, sizeof(_instance->l7_unknown_name), "UNCATEGORIZED");
@@ -1534,7 +1558,7 @@ int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handl
if(_instance==NULL || _handle==NULL || log_msg==NULL) if(_instance==NULL || _handle==NULL || log_msg==NULL)
{ {
TLD_cancel(handle); TLD_cancel(handle);
MESA_handle_runtime_log(_instance->logger, RLOG_LV_FATAL, "TSG_SEND_LOG", " instance==NULL || TLD_handle==NULL || log_msg==NULL "); MESA_handle_runtime_log(_instance->logger, RLOG_LV_DEBUG, "TSG_SEND_LOG", " instance==NULL || TLD_handle==NULL || log_msg==NULL ");
return -1; return -1;
} }

View File

@@ -133,6 +133,7 @@ struct tsg_log_instance_t
int send_user_region; int send_user_region;
int send_data_center; int send_data_center;
int recovery_interval; int recovery_interval;
int rapidjson_chunk_capacity;
int session_attribute_project_id; int session_attribute_project_id;
int tcp_flow_project_id; int tcp_flow_project_id;
int udp_flow_project_id; int udp_flow_project_id;