add connection stats
parent
f5425ae8cc
commit
2a900c23aa
1
HISTORY
1
HISTORY
|
|
@ -8,6 +8,7 @@ Version 5.04 2014-09-13
|
|||
to the tracker server
|
||||
* fdfs_monitor support delete empty group
|
||||
* bug fixed: two tracker leaders occur in rare case
|
||||
* add connection stats
|
||||
|
||||
Version 5.03 2014-08-10
|
||||
* network send and recv retry when error EINTR happen
|
||||
|
|
|
|||
|
|
@ -417,8 +417,11 @@ static int list_storages(FDFSGroupStat *pGroupStat)
|
|||
"\t\tstorage_port = %d\n" \
|
||||
"\t\tstorage_http_port = %d\n" \
|
||||
"\t\tcurrent_write_path = %d\n" \
|
||||
"\t\tsource storage id= %s\n" \
|
||||
"\t\tif_trunk_server= %d\n" \
|
||||
"\t\tsource storage id = %s\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\tsuccess_upload_count = %"PRId64"\n" \
|
||||
"\t\ttotal_append_count = %"PRId64"\n" \
|
||||
|
|
@ -478,6 +481,9 @@ static int list_storages(FDFSGroupStat *pGroupStat)
|
|||
pStorage->current_write_path, \
|
||||
pStorage->src_id, \
|
||||
pStorage->if_trunk_server, \
|
||||
pStorageStat->connection.alloc_count, \
|
||||
pStorageStat->connection.current_count, \
|
||||
pStorageStat->connection.max_count, \
|
||||
pStorageStat->total_upload_count, \
|
||||
pStorageStat->success_upload_count, \
|
||||
pStorageStat->total_append_count, \
|
||||
|
|
|
|||
|
|
@ -124,6 +124,8 @@ 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,
|
||||
|
|
|
|||
|
|
@ -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_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
|
||||
|
|
|
|||
|
|
@ -68,6 +68,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);
|
||||
}
|
||||
|
||||
static int set_recv_event(struct fast_task_info *pTask)
|
||||
|
|
|
|||
|
|
@ -1565,8 +1565,11 @@ static void storage_set_metadata_done_callback( \
|
|||
|
||||
int storage_service_init()
|
||||
{
|
||||
#define ALLOC_CONNECTIONS_ONCE 256
|
||||
|
||||
int result;
|
||||
int bytes;
|
||||
int init_connections;
|
||||
struct storage_nio_thread_data *pThreadData;
|
||||
struct storage_nio_thread_data *pDataEnd;
|
||||
pthread_t tid;
|
||||
|
|
@ -1594,8 +1597,11 @@ int storage_service_init()
|
|||
return result;
|
||||
}
|
||||
|
||||
if ((result=free_queue_init(g_max_connections, g_buff_size, \
|
||||
g_buff_size, sizeof(StorageClientInfo))) != 0)
|
||||
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, g_buff_size,
|
||||
g_buff_size, sizeof(StorageClientInfo))) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1843,6 +1849,15 @@ static void *accept_thread_entrance(void* arg)
|
|||
"errno: %d, error info: %s", \
|
||||
__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;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
#include "shared_func.h"
|
||||
#include "pthread_func.h"
|
||||
#include "sched_thread.h"
|
||||
#include "fast_task_queue.h"
|
||||
#include "tracker_types.h"
|
||||
#include "tracker_proto.h"
|
||||
#include "tracker_client_thread.h"
|
||||
|
|
@ -2131,6 +2132,14 @@ static int tracker_heart_beat(ConnectionInfo *pTrackerServer, \
|
|||
{
|
||||
pStatBuff = (FDFSStorageStatBuff *)( \
|
||||
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, \
|
||||
pStatBuff->sz_total_upload_count);
|
||||
long2buff(g_storage_stat.success_upload_count, \
|
||||
|
|
|
|||
|
|
@ -73,3 +73,5 @@ bool g_http_servers_dirty = false;
|
|||
char g_exe_name[256] = {0};
|
||||
#endif
|
||||
|
||||
FDFSConnectionStat g_connection_stat = {0, 0};
|
||||
|
||||
|
|
|
|||
|
|
@ -97,6 +97,8 @@ extern bool g_http_servers_dirty;
|
|||
extern char g_exe_name[256];
|
||||
#endif
|
||||
|
||||
extern FDFSConnectionStat g_connection_stat;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ void task_finish_clean_up(struct fast_task_info *pTask)
|
|||
|
||||
memset(pTask->arg, 0, sizeof(TrackerClientInfo));
|
||||
free_queue_push(pTask);
|
||||
__sync_fetch_and_sub(&g_connection_stat.current_count, 1);
|
||||
}
|
||||
|
||||
void recv_notify_read(int sock, short event, void *arg)
|
||||
|
|
|
|||
|
|
@ -53,8 +53,10 @@ static void tracker_find_max_free_space_group();
|
|||
|
||||
int tracker_service_init()
|
||||
{
|
||||
#define ALLOC_CONNECTIONS_ONCE 1024
|
||||
int result;
|
||||
int bytes;
|
||||
int init_connections;
|
||||
struct nio_thread_data *pThreadData;
|
||||
struct nio_thread_data *pDataEnd;
|
||||
pthread_t tid;
|
||||
|
|
@ -77,8 +79,11 @@ int tracker_service_init()
|
|||
return result;
|
||||
}
|
||||
|
||||
if ((result=free_queue_init(g_max_connections, TRACKER_MAX_PACKAGE_SIZE,\
|
||||
TRACKER_MAX_PACKAGE_SIZE, sizeof(TrackerClientInfo))) != 0)
|
||||
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)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
|
@ -259,6 +264,15 @@ static void *accept_thread_entrance(void* arg)
|
|||
"errno: %d, error info: %s", \
|
||||
__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;
|
||||
|
|
@ -3506,6 +3520,13 @@ static int tracker_deal_storage_beat(struct fast_task_info *pTask)
|
|||
sizeof(TrackerHeader));
|
||||
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 = \
|
||||
buff2long(pStatBuff->sz_total_upload_count);
|
||||
pStat->success_upload_count = \
|
||||
|
|
|
|||
|
|
@ -207,11 +207,23 @@ typedef struct
|
|||
|
||||
/* last heart beat time */
|
||||
time_t last_heart_beat_time;
|
||||
|
||||
struct {
|
||||
int alloc_count;
|
||||
int current_count;
|
||||
int max_count;
|
||||
} connection;
|
||||
} FDFSStorageStat;
|
||||
|
||||
/* struct for network transfering */
|
||||
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_success_upload_count[8];
|
||||
char sz_total_append_count[8];
|
||||
|
|
@ -440,5 +452,10 @@ typedef struct {
|
|||
bool if_leader; //if leader
|
||||
} TrackerRunningStatus;
|
||||
|
||||
typedef struct fdfs_connection_stat {
|
||||
volatile int current_count;
|
||||
volatile int max_count;
|
||||
} FDFSConnectionStat;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue