add connection stats

pull/48/head
yuqing 2014-09-13 22:10:04 +08:00
parent f5425ae8cc
commit 2a900c23aa
12 changed files with 85 additions and 6 deletions

View File

@ -8,6 +8,7 @@ Version 5.04 2014-09-13
to the tracker server to the tracker server
* fdfs_monitor support delete empty group * fdfs_monitor support delete empty group
* bug fixed: two tracker leaders occur in rare case * bug fixed: two tracker leaders occur in rare case
* add connection stats
Version 5.03 2014-08-10 Version 5.03 2014-08-10
* network send and recv retry when error EINTR happen * network send and recv retry when error EINTR happen

View File

@ -417,8 +417,11 @@ static int list_storages(FDFSGroupStat *pGroupStat)
"\t\tstorage_port = %d\n" \ "\t\tstorage_port = %d\n" \
"\t\tstorage_http_port = %d\n" \ "\t\tstorage_http_port = %d\n" \
"\t\tcurrent_write_path = %d\n" \ "\t\tcurrent_write_path = %d\n" \
"\t\tsource storage id= %s\n" \ "\t\tsource storage id = %s\n" \
"\t\tif_trunk_server= %d\n" \ "\t\tif_trunk_server = %d\n" \
"\t\tconnection.alloc_count = %d\n" \
"\t\tconnection.current_count = %d\n" \
"\t\tconnection.max_count = %d\n" \
"\t\ttotal_upload_count = %"PRId64"\n" \ "\t\ttotal_upload_count = %"PRId64"\n" \
"\t\tsuccess_upload_count = %"PRId64"\n" \ "\t\tsuccess_upload_count = %"PRId64"\n" \
"\t\ttotal_append_count = %"PRId64"\n" \ "\t\ttotal_append_count = %"PRId64"\n" \
@ -478,6 +481,9 @@ static int list_storages(FDFSGroupStat *pGroupStat)
pStorage->current_write_path, \ pStorage->current_write_path, \
pStorage->src_id, \ pStorage->src_id, \
pStorage->if_trunk_server, \ pStorage->if_trunk_server, \
pStorageStat->connection.alloc_count, \
pStorageStat->connection.current_count, \
pStorageStat->connection.max_count, \
pStorageStat->total_upload_count, \ pStorageStat->total_upload_count, \
pStorageStat->success_upload_count, \ pStorageStat->success_upload_count, \
pStorageStat->total_append_count, \ pStorageStat->total_append_count, \

View File

@ -124,6 +124,8 @@ char g_exe_name[256] = {0};
struct storage_nio_thread_data *g_nio_thread_data = NULL; struct storage_nio_thread_data *g_nio_thread_data = NULL;
struct storage_dio_thread_data *g_dio_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) int storage_cmp_by_server_id(const void *p1, const void *p2)
{ {
return strcmp((*((FDFSStorageServer **)p1))->server.id, return strcmp((*((FDFSStorageServer **)p1))->server.id,

View File

@ -171,6 +171,8 @@ extern char g_exe_name[256];
extern struct storage_nio_thread_data *g_nio_thread_data; //network io thread data 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 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); int storage_cmp_by_server_id(const void *p1, const void *p2);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -68,6 +68,7 @@ void task_finish_clean_up(struct fast_task_info *pTask)
memset(pTask->arg, 0, sizeof(StorageClientInfo)); memset(pTask->arg, 0, sizeof(StorageClientInfo));
free_queue_push(pTask); free_queue_push(pTask);
__sync_fetch_and_sub(&g_connection_stat.current_count, 1);
} }
static int set_recv_event(struct fast_task_info *pTask) static int set_recv_event(struct fast_task_info *pTask)

View File

@ -1565,8 +1565,11 @@ static void storage_set_metadata_done_callback( \
int storage_service_init() int storage_service_init()
{ {
#define ALLOC_CONNECTIONS_ONCE 256
int result; int result;
int bytes; int bytes;
int init_connections;
struct storage_nio_thread_data *pThreadData; struct storage_nio_thread_data *pThreadData;
struct storage_nio_thread_data *pDataEnd; struct storage_nio_thread_data *pDataEnd;
pthread_t tid; pthread_t tid;
@ -1594,8 +1597,11 @@ int storage_service_init()
return result; return result;
} }
if ((result=free_queue_init(g_max_connections, g_buff_size, \ init_connections = g_max_connections < ALLOC_CONNECTIONS_ONCE ?
g_buff_size, sizeof(StorageClientInfo))) != 0) g_max_connections : ALLOC_CONNECTIONS_ONCE;
if ((result=free_queue_init_ex(g_max_connections, init_connections,
ALLOC_CONNECTIONS_ONCE, g_buff_size,
g_buff_size, sizeof(StorageClientInfo))) != 0)
{ {
return result; return result;
} }
@ -1843,6 +1849,15 @@ static void *accept_thread_entrance(void* arg)
"errno: %d, error info: %s", \ "errno: %d, error info: %s", \
__LINE__, errno, STRERROR(errno)); __LINE__, errno, STRERROR(errno));
} }
else
{
int current_connections;
current_connections = __sync_add_and_fetch(&g_connection_stat.
current_count, 1);
if (current_connections > g_connection_stat.max_count) {
g_connection_stat.max_count = current_connections;
}
}
} }
return NULL; return NULL;

View File

@ -25,6 +25,7 @@
#include "shared_func.h" #include "shared_func.h"
#include "pthread_func.h" #include "pthread_func.h"
#include "sched_thread.h" #include "sched_thread.h"
#include "fast_task_queue.h"
#include "tracker_types.h" #include "tracker_types.h"
#include "tracker_proto.h" #include "tracker_proto.h"
#include "tracker_client_thread.h" #include "tracker_client_thread.h"
@ -2131,6 +2132,14 @@ static int tracker_heart_beat(ConnectionInfo *pTrackerServer, \
{ {
pStatBuff = (FDFSStorageStatBuff *)( \ pStatBuff = (FDFSStorageStatBuff *)( \
out_buff + sizeof(TrackerHeader)); out_buff + sizeof(TrackerHeader));
long2buff(free_queue_alloc_connections(), \
pStatBuff->connection.sz_alloc_count);
long2buff(g_storage_stat.connection.current_count, \
pStatBuff->connection.sz_current_count);
long2buff(g_storage_stat.connection.max_count, \
pStatBuff->connection.sz_max_count);
long2buff(g_storage_stat.total_upload_count, \ long2buff(g_storage_stat.total_upload_count, \
pStatBuff->sz_total_upload_count); pStatBuff->sz_total_upload_count);
long2buff(g_storage_stat.success_upload_count, \ long2buff(g_storage_stat.success_upload_count, \

View File

@ -73,3 +73,5 @@ bool g_http_servers_dirty = false;
char g_exe_name[256] = {0}; char g_exe_name[256] = {0};
#endif #endif
FDFSConnectionStat g_connection_stat = {0, 0};

View File

@ -97,6 +97,8 @@ extern bool g_http_servers_dirty;
extern char g_exe_name[256]; extern char g_exe_name[256];
#endif #endif
extern FDFSConnectionStat g_connection_stat;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -72,6 +72,7 @@ void task_finish_clean_up(struct fast_task_info *pTask)
memset(pTask->arg, 0, sizeof(TrackerClientInfo)); memset(pTask->arg, 0, sizeof(TrackerClientInfo));
free_queue_push(pTask); free_queue_push(pTask);
__sync_fetch_and_sub(&g_connection_stat.current_count, 1);
} }
void recv_notify_read(int sock, short event, void *arg) void recv_notify_read(int sock, short event, void *arg)

View File

@ -53,8 +53,10 @@ static void tracker_find_max_free_space_group();
int tracker_service_init() int tracker_service_init()
{ {
#define ALLOC_CONNECTIONS_ONCE 1024
int result; int result;
int bytes; int bytes;
int init_connections;
struct nio_thread_data *pThreadData; struct nio_thread_data *pThreadData;
struct nio_thread_data *pDataEnd; struct nio_thread_data *pDataEnd;
pthread_t tid; pthread_t tid;
@ -77,8 +79,11 @@ int tracker_service_init()
return result; return result;
} }
if ((result=free_queue_init(g_max_connections, TRACKER_MAX_PACKAGE_SIZE,\ init_connections = g_max_connections < ALLOC_CONNECTIONS_ONCE ?
TRACKER_MAX_PACKAGE_SIZE, sizeof(TrackerClientInfo))) != 0) 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)
{ {
return result; return result;
} }
@ -259,6 +264,15 @@ static void *accept_thread_entrance(void* arg)
"errno: %d, error info: %s", \ "errno: %d, error info: %s", \
__LINE__, errno, STRERROR(errno)); __LINE__, errno, STRERROR(errno));
} }
else
{
int current_connections;
current_connections = __sync_add_and_fetch(&g_connection_stat.
current_count, 1);
if (current_connections > g_connection_stat.max_count) {
g_connection_stat.max_count = current_connections;
}
}
} }
return NULL; return NULL;
@ -3506,6 +3520,13 @@ static int tracker_deal_storage_beat(struct fast_task_info *pTask)
sizeof(TrackerHeader)); sizeof(TrackerHeader));
pStat = &(pClientInfo->pStorage->stat); pStat = &(pClientInfo->pStorage->stat);
pStat->connection.alloc_count = \
buff2long(pStatBuff->connection.sz_alloc_count);
pStat->connection.current_count = \
buff2long(pStatBuff->connection.sz_current_count);
pStat->connection.max_count = \
buff2long(pStatBuff->connection.sz_max_count);
pStat->total_upload_count = \ pStat->total_upload_count = \
buff2long(pStatBuff->sz_total_upload_count); buff2long(pStatBuff->sz_total_upload_count);
pStat->success_upload_count = \ pStat->success_upload_count = \

View File

@ -207,11 +207,23 @@ typedef struct
/* last heart beat time */ /* last heart beat time */
time_t last_heart_beat_time; time_t last_heart_beat_time;
struct {
int alloc_count;
int current_count;
int max_count;
} connection;
} FDFSStorageStat; } FDFSStorageStat;
/* struct for network transfering */ /* struct for network transfering */
typedef struct typedef struct
{ {
struct {
char sz_alloc_count[4];
char sz_current_count[4];
char sz_max_count[4];
} connection;
char sz_total_upload_count[8]; char sz_total_upload_count[8];
char sz_success_upload_count[8]; char sz_success_upload_count[8];
char sz_total_append_count[8]; char sz_total_append_count[8];
@ -440,5 +452,10 @@ typedef struct {
bool if_leader; //if leader bool if_leader; //if leader
} TrackerRunningStatus; } TrackerRunningStatus;
typedef struct fdfs_connection_stat {
volatile int current_count;
volatile int max_count;
} FDFSConnectionStat;
#endif #endif