diff --git a/HISTORY b/HISTORY index 7cdc801..1a9b514 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,7 @@ Version 5.09 2016-11-10 - * bug fixed: list_all_groups expand buffer auto + * bug fixed: list_all_groups expand buffer auto for so many groups + * tracker.conf add parameters: min_buff_size and max_buff_size Version 5.08 2016-04-08 * install library to $(TARGET_PREFIX)/lib anyway diff --git a/conf/tracker.conf b/conf/tracker.conf index 9925a16..428381c 100644 --- a/conf/tracker.conf +++ b/conf/tracker.conf @@ -34,6 +34,14 @@ accept_threads=1 # since V2.00 work_threads=4 +# min buff size +# default value 8KB +min_buff_size = 8KB + +# max buff size +# default value 128KB +max_buff_size = 128KB + # the method of selecting group to upload files # 0: round robin # 1: specify group diff --git a/tracker/tracker_func.c b/tracker/tracker_func.c index cefbf78..1f0b459 100644 --- a/tracker/tracker_func.c +++ b/tracker/tracker_func.c @@ -136,6 +136,8 @@ int tracker_load_from_conf_file(const char *filename, \ char *pSpaceThreshold; char *pTrunkFileSize; char *pRotateErrorLogSize; + char *pMinBuffSize; + char *pMaxBuffSize; #ifdef WITH_HTTPD char *pHttpCheckUri; char *pHttpCheckType; @@ -147,6 +149,8 @@ int tracker_load_from_conf_file(const char *filename, \ int64_t slot_min_size; int64_t slot_max_size; int64_t rotate_error_log_size; + int64_t min_buff_size; + int64_t max_buff_size; char reserved_space_str[32]; memset(&g_groups, 0, sizeof(FDFSGroups)); @@ -616,6 +620,38 @@ int tracker_load_from_conf_file(const char *filename, \ break; } + + pMinBuffSize = iniGetStrValue(NULL, + "min_buff_size", &iniContext); + if (pMinBuffSize == NULL) { + min_buff_size = TRACKER_MAX_PACKAGE_SIZE; + } + else if ((result=parse_bytes(pMinBuffSize, 1, + &min_buff_size)) != 0) + { + return result; + } + g_min_buff_size = (int)min_buff_size; + + pMaxBuffSize = iniGetStrValue(NULL, + "max_buff_size", &iniContext); + if (pMaxBuffSize == NULL) { + max_buff_size = 16 * TRACKER_MAX_PACKAGE_SIZE; + } + else if ((result=parse_bytes(pMaxBuffSize, 1, + &max_buff_size)) != 0) + { + return result; + } + g_max_buff_size = (int)max_buff_size; + + if (g_min_buff_size < TRACKER_MAX_PACKAGE_SIZE) { + g_min_buff_size = TRACKER_MAX_PACKAGE_SIZE; + } + if (g_max_buff_size < g_min_buff_size) { + g_max_buff_size = g_min_buff_size; + } + #ifdef WITH_HTTPD if ((result=fdfs_http_params_load(&iniContext, \ filename, &g_http_params)) != 0) @@ -667,6 +703,8 @@ int tracker_load_from_conf_file(const char *filename, \ "max_connections=%d, " \ "accept_threads=%d, " \ "work_threads=%d, " \ + "min_buff_size=%d, " \ + "max_buff_size=%d, " \ "store_lookup=%d, store_group=%s, " \ "store_server=%d, store_path=%d, " \ "reserved_storage_space=%s, " \ @@ -703,6 +741,7 @@ int tracker_load_from_conf_file(const char *filename, \ g_fdfs_connect_timeout, \ g_fdfs_network_timeout, g_server_port, bind_addr, \ g_max_connections, g_accept_threads, g_work_threads, \ + g_min_buff_size, g_max_buff_size, \ g_groups.store_lookup, g_groups.store_group, \ g_groups.store_server, g_groups.store_path, \ fdfs_storage_reserved_space_to_string( \ diff --git a/tracker/tracker_global.c b/tracker/tracker_global.c index cbff568..98967b3 100644 --- a/tracker/tracker_global.c +++ b/tracker/tracker_global.c @@ -15,6 +15,8 @@ int g_accept_threads = 1; int g_work_threads = DEFAULT_WORK_THREADS; int g_sync_log_buff_interval = SYNC_LOG_BUFF_DEF_INTERVAL; int g_check_active_interval = CHECK_ACTIVE_DEF_INTERVAL; +int g_min_buff_size = TRACKER_MAX_PACKAGE_SIZE; +int g_max_buff_size = 16 * TRACKER_MAX_PACKAGE_SIZE; FDFSGroups g_groups; int g_storage_stat_chg_count = 0; diff --git a/tracker/tracker_global.h b/tracker/tracker_global.h index 5d165a8..f1b4fe5 100644 --- a/tracker/tracker_global.h +++ b/tracker/tracker_global.h @@ -41,6 +41,8 @@ extern FDFSGroups g_groups; extern int g_storage_stat_chg_count; extern int g_storage_sync_time_chg_count; //sync timestamp extern int g_max_connections; +extern int g_min_buff_size; +extern int g_max_buff_size; extern int g_accept_threads; extern int g_work_threads; extern FDFSStorageReservedSpace g_storage_reserved_space; diff --git a/tracker/tracker_service.c b/tracker/tracker_service.c index 1f05467..72ad1e1 100644 --- a/tracker/tracker_service.c +++ b/tracker/tracker_service.c @@ -82,8 +82,8 @@ int tracker_service_init() init_connections = g_max_connections < ALLOC_CONNECTIONS_ONCE ? g_max_connections : ALLOC_CONNECTIONS_ONCE; if ((result=free_queue_init_ex(g_max_connections, init_connections, - ALLOC_CONNECTIONS_ONCE, TRACKER_MAX_PACKAGE_SIZE, - TRACKER_MAX_PACKAGE_SIZE, sizeof(TrackerClientInfo))) != 0) + ALLOC_CONNECTIONS_ONCE, g_min_buff_size, + g_max_buff_size, sizeof(TrackerClientInfo))) != 0) { return result; } @@ -2969,10 +2969,27 @@ static int tracker_deal_server_list_all_groups(struct fast_task_info *pTask) } expect_size = sizeof(TrackerHeader) + g_groups.count * sizeof(TrackerGroupStat); - if ((result=free_queue_set_buffer_size(pTask, expect_size)) != 0) + if (expect_size > g_min_buff_size) { - pTask->length = sizeof(TrackerHeader); - return result; + if (expect_size <= g_max_buff_size) + { + if ((result=free_queue_set_buffer_size(pTask, expect_size)) != 0) + { + pTask->length = sizeof(TrackerHeader); + return result; + } + } + else + { + logError("file: "__FILE__", line: %d, " + "cmd=%d, client ip: %s, " + "expect buffer size: %d > max_buff_size: %d, " + "you should increase max_buff_size in tracker.conf", + __LINE__, TRACKER_PROTO_CMD_SERVER_LIST_ALL_GROUPS, + pTask->client_ip, expect_size, g_max_buff_size); + pTask->length = sizeof(TrackerHeader); + return ENOSPC; + } } groupStats = (TrackerGroupStat *)(pTask->data + sizeof(TrackerHeader));