MOD aaa-12 增加rpc的超时判断
SOL 增加rpc的超时判断 修改人:zhangliang 检视人:zhangliang
This commit is contained in:
parent
cfc95c66c9
commit
0ad879c584
|
@ -16,6 +16,7 @@
|
|||
#define BUFFER_SIZE 2048
|
||||
#define RPC_VERSION "RPC/1.0"
|
||||
#define TIMEOUT 120
|
||||
#define TIMEWARN 200
|
||||
|
||||
typedef enum {
|
||||
/* RPC ret code */
|
||||
|
|
|
@ -118,4 +118,6 @@ void rpc_sleep(int ms);
|
|||
|
||||
void rpc_set_non_block(int fd);
|
||||
|
||||
long rpc_time_msec(void);
|
||||
|
||||
#endif /* RPC_UTIL_H_ */
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "rpc_thread.h"
|
||||
#include "rpc_module.h"
|
||||
#include "rpc_conn.h"
|
||||
#include "rpc_util.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <sys/socket.h>
|
||||
|
@ -22,6 +23,7 @@
|
|||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
//server: one thread multiply connection. a connection would block a thread
|
||||
//client: one thread one connection
|
||||
|
@ -137,9 +139,11 @@ ret_code rpc_client_call(rpc_client* client, char* service_name,
|
|||
int* output_len) {
|
||||
int n_fd = eventfd(0, 0);
|
||||
rpc_response rsp;
|
||||
long time_diff;
|
||||
|
||||
assert(client!=NULL);
|
||||
rsp.data = (INT_TO_POINTER(n_fd));
|
||||
time_diff = rpc_time_msec();
|
||||
rpc_client_call_async(client, service_name, method_name, input, input_len,
|
||||
cb_call_ex, &rsp);
|
||||
|
||||
|
@ -154,6 +158,13 @@ ret_code rpc_client_call(rpc_client* client, char* service_name,
|
|||
int rt = select(n_fd + 1, &r_set, NULL, NULL, &tm);
|
||||
|
||||
close(n_fd);
|
||||
|
||||
time_diff = rpc_time_msec()-time_diff;
|
||||
if(time_diff > TIMEWARN)
|
||||
{
|
||||
rpc_log_warn("call %s@%s cost %ld\n",service_name, method_name, time_diff);
|
||||
}
|
||||
|
||||
if (rt == -1) {
|
||||
return RET_UNKNOWN;
|
||||
} else if (rt == 0) {
|
||||
|
|
|
@ -62,4 +62,13 @@ uint rpc_str_hash(constpointer v) {
|
|||
return h;
|
||||
}
|
||||
|
||||
long rpc_time_msec(void)
|
||||
{
|
||||
struct timespec tp = {0};
|
||||
|
||||
clock_gettime (CLOCK_MONOTONIC, &tp);
|
||||
|
||||
return(tp.tv_sec * 1000 + tp.tv_nsec / (1000 *1000));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue