summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuxueli <[email protected]>2021-11-13 13:27:59 +0300
committerliuxueli <[email protected]>2021-11-13 13:27:59 +0300
commit36c36102f3eb06982c4879d29b180415e494a06d (patch)
treeed58900260b33fae32d9ed9124f7292963cf0968
parent86020118e56931a3b71de0c734f464be94e548b6 (diff)
TSG-8487: 使用参数设置rapidjson为每个日志句柄预申请的内存大小,默认为8Kv5.4.16
-rw-r--r--src/tsg_entry.cpp8
-rw-r--r--src/tsg_entry.h6
-rw-r--r--src/tsg_send_log.cpp30
-rw-r--r--src/tsg_send_log_internal.h1
4 files changed, 41 insertions, 4 deletions
diff --git a/src/tsg_entry.cpp b/src/tsg_entry.cpp
index e8cd0b4..60cf024 100644
--- a/src/tsg_entry.cpp
+++ b/src/tsg_entry.cpp
@@ -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_FAILED_LOG, "ddos_fai_log"},
{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"},
diff --git a/src/tsg_entry.h b/src/tsg_entry.h
index 5de9da3..99e1e2f 100644
--- a/src/tsg_entry.h
+++ b/src/tsg_entry.h
@@ -113,6 +113,12 @@ enum TSG_FS2_TYPE{
TSG_FS2_DDOS_FAILED_LOG,
TSG_FS2_SET_TIMOUT_SUCCESS,
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
};
diff --git a/src/tsg_send_log.cpp b/src/tsg_send_log.cpp
index 1a5d3b6..5ce8a38 100644
--- a/src/tsg_send_log.cpp
+++ b/src/tsg_send_log.cpp
@@ -37,6 +37,7 @@ struct tsg_log_instance_t *g_tsg_log_instance;
struct TLD_handle_t
{
int thread_id;
+ MemoryPoolAllocator<> *valueAllocator;
Document *document;
};
@@ -831,15 +832,28 @@ static int action2fs_id(int action)
int TLD_cancel(struct TLD_handle_t *handle)
{
+ long long length=0;
if (handle != 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;
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);
- handle = NULL;
+ handle = NULL;
}
return 0;
@@ -886,6 +900,8 @@ int TLD_append(struct TLD_handle_t *handle, char *key, void *value, TLD_TYPE typ
return -1;
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;
}
@@ -902,6 +918,9 @@ struct TLD_handle_t *TLD_duplicate(struct TLD_handle_t *handle)
//_handle->document->SetObject();
_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;
}
@@ -911,8 +930,12 @@ 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));
_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();
+
+ 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;
}
@@ -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_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", "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_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)
{
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;
}
diff --git a/src/tsg_send_log_internal.h b/src/tsg_send_log_internal.h
index 5c2cd41..83e4bd2 100644
--- a/src/tsg_send_log_internal.h
+++ b/src/tsg_send_log_internal.h
@@ -133,6 +133,7 @@ struct tsg_log_instance_t
int send_user_region;
int send_data_center;
int recovery_interval;
+ int rapidjson_chunk_capacity;
int session_attribute_project_id;
int tcp_flow_project_id;
int udp_flow_project_id;