From b1a47bb8ea413a0457bf0abf6c24cba44fd81682 Mon Sep 17 00:00:00 2001 From: wangyu- Date: Wed, 27 Sep 2017 11:11:06 -0500 Subject: [PATCH] performance optimization for dup_max=0 --- main.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index b118673..d162fab 100644 --- a/main.cpp +++ b/main.cpp @@ -198,9 +198,15 @@ struct conn_manager_t //TODO change map to unordered map } int insert_fd(u32_t fd,u64_t u64) { + int before=fd_last_active_time.bucket_count(); u64_to_fd[u64]=fd; fd_to_u64[fd]=u64; fd_last_active_time[fd]=get_current_time(); + int after=fd_last_active_time.bucket_count(); + if(after!=before)//rehash happens! + { + clear_it=fd_last_active_time.begin(); + } return 0; } int erase_fd(u32_t fd) @@ -422,7 +428,7 @@ int remove_seq(char * data,int &data_len) seq=ntoh64(seq); if(anti_replay.is_vaild(seq)==0) { - if(disable_replay_filter==1) + if(disable_replay_filter==1) // inefficient, to make packet_recv_count++ work for only non-dup packet return 0; mylog(log_trace,"seq %llx dropped bc of replay-filter\n ",seq); return -1; @@ -773,7 +779,18 @@ int event_loop() if (ret < 0) { mylog(log_warn, "send returned %d ,errno:%s\n", ret,strerror(errno)); } - add_and_new(new_udp_fd, dup_num - 1,random_between(dup_delay_min,dup_delay_max), data, data_len,u64); + if(dup_delay_max!=0) + { + add_and_new(new_udp_fd, dup_num - 1,random_between(dup_delay_min,dup_delay_max), data, data_len,u64); + } + else + { + for(int i=0;i