From 738a3208b94612e3837e77736a99c6df5a0513ec Mon Sep 17 00:00:00 2001 From: yuqing Date: Sat, 13 Sep 2014 23:09:34 +0800 Subject: [PATCH] add connection stats --- storage/storage_dump.c | 6 ++++++ storage/storage_global.c | 2 -- storage/storage_global.h | 2 -- storage/storage_nio.c | 2 +- storage/storage_service.c | 6 +++--- tracker/tracker_service.c | 1 + tracker/tracker_types.h | 4 ++-- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/storage/storage_dump.c b/storage/storage_dump.c index e33b613..2046728 100644 --- a/storage/storage_dump.c +++ b/storage/storage_dump.c @@ -331,6 +331,9 @@ static int fdfs_dump_storage_stat(char *buff, const int buffSize) total_len = snprintf(buff, buffSize, "\ng_stat_change_count=%d\n" "g_sync_change_count=%d\n" + "alloc_count=%d\n" + "current_count=%d\n" + "max_count=%d\n" "total_upload_count=%"PRId64"\n" "success_upload_count=%"PRId64"\n" "total_set_meta_count=%"PRId64"\n" @@ -350,6 +353,9 @@ static int fdfs_dump_storage_stat(char *buff, const int buffSize) "last_synced_timestamp=%s\n" "last_heart_beat_time=%s\n", g_stat_change_count, g_sync_change_count, + free_queue_alloc_connections(), + g_storage_stat.connection.current_count, + g_storage_stat.connection.max_count, g_storage_stat.total_upload_count, g_storage_stat.success_upload_count, g_storage_stat.total_set_meta_count, diff --git a/storage/storage_global.c b/storage/storage_global.c index d0e6867..6a5954f 100644 --- a/storage/storage_global.c +++ b/storage/storage_global.c @@ -124,8 +124,6 @@ char g_exe_name[256] = {0}; struct storage_nio_thread_data *g_nio_thread_data = NULL; struct storage_dio_thread_data *g_dio_thread_data = NULL; -FDFSConnectionStat g_connection_stat = {0, 0}; - int storage_cmp_by_server_id(const void *p1, const void *p2) { return strcmp((*((FDFSStorageServer **)p1))->server.id, diff --git a/storage/storage_global.h b/storage/storage_global.h index 76be11b..2c180eb 100644 --- a/storage/storage_global.h +++ b/storage/storage_global.h @@ -171,8 +171,6 @@ extern char g_exe_name[256]; extern struct storage_nio_thread_data *g_nio_thread_data; //network io thread data extern struct storage_dio_thread_data *g_dio_thread_data; //disk io thread data -extern FDFSConnectionStat g_connection_stat; - int storage_cmp_by_server_id(const void *p1, const void *p2); #ifdef __cplusplus diff --git a/storage/storage_nio.c b/storage/storage_nio.c index 6c98761..14c1cf2 100644 --- a/storage/storage_nio.c +++ b/storage/storage_nio.c @@ -69,7 +69,7 @@ void task_finish_clean_up(struct fast_task_info *pTask) memset(pTask->arg, 0, sizeof(StorageClientInfo)); free_queue_push(pTask); - __sync_fetch_and_sub(&g_connection_stat.current_count, 1); + __sync_fetch_and_sub(&g_storage_stat.connection.current_count, 1); ++g_stat_change_count; } diff --git a/storage/storage_service.c b/storage/storage_service.c index b1c6382..77bffb6 100644 --- a/storage/storage_service.c +++ b/storage/storage_service.c @@ -1852,10 +1852,10 @@ static void *accept_thread_entrance(void* arg) else { int current_connections; - current_connections = __sync_add_and_fetch(&g_connection_stat. + current_connections = __sync_add_and_fetch(&g_storage_stat.connection. current_count, 1); - if (current_connections > g_connection_stat.max_count) { - g_connection_stat.max_count = current_connections; + if (current_connections > g_storage_stat.connection.max_count) { + g_storage_stat.connection.max_count = current_connections; } ++g_stat_change_count; } diff --git a/tracker/tracker_service.c b/tracker/tracker_service.c index 2699409..d3c9bd1 100644 --- a/tracker/tracker_service.c +++ b/tracker/tracker_service.c @@ -2223,6 +2223,7 @@ static int tracker_deal_server_list_group_storages(struct fast_task_info *pTask) long2buff((*ppServer)->current_write_path, \ pDest->sz_current_write_path); + int2buff(pStorageStat->connection.alloc_count, \ pStatBuff->connection.sz_alloc_count); int2buff(pStorageStat->connection.current_count, \ diff --git a/tracker/tracker_types.h b/tracker/tracker_types.h index 281991f..2989bde 100644 --- a/tracker/tracker_types.h +++ b/tracker/tracker_types.h @@ -210,7 +210,7 @@ typedef struct struct { int alloc_count; - int current_count; + volatile int current_count; int max_count; } connection; } FDFSStorageStat; @@ -454,7 +454,7 @@ typedef struct { typedef struct fdfs_connection_stat { volatile int current_count; - volatile int max_count; + int max_count; } FDFSConnectionStat; #endif