revert lru of conn_manager

This commit is contained in:
wangyu- 2018-07-20 12:44:41 -05:00
parent 3a372b9eee
commit a7849b3634
3 changed files with 29 additions and 25 deletions

View File

@ -215,6 +215,11 @@ conn_manager_t conn_manager;
if(it==mp.end()) if(it==mp.end())
{ {
mp[addr]=new conn_info_t; mp[addr]=new conn_info_t;
//lru.new_key(addr);
}
else
{
//lru.update(addr);
} }
return mp[addr]; return mp[addr];
} }
@ -228,6 +233,11 @@ conn_manager_t conn_manager;
if(it==mp.end()) if(it==mp.end())
{ {
mp[addr]=new conn_info_t; mp[addr]=new conn_info_t;
//lru.new_key(addr);
}
else
{
//lru.update(addr);
} }
return *mp[addr]; return *mp[addr];
} }
@ -282,14 +292,14 @@ int conn_manager_t::clear_inactive()
} }
int conn_manager_t::clear_inactive0() int conn_manager_t::clear_inactive0()
{ {
//unordered_map<u64_t,conn_info_t*>::iterator it; unordered_map<address_t,conn_info_t*>::iterator it;
// unordered_map<u64_t,conn_info_t*>::iterator old_it; unordered_map<address_t,conn_info_t*>::iterator old_it;
if(disable_conn_clear) return 0; if(disable_conn_clear) return 0;
//map<uint32_t,uint64_t>::iterator it; //map<uint32_t,uint64_t>::iterator it;
int cnt=0; int cnt=0;
//it=clear_it; it=clear_it;
int size=mp.size(); int size=mp.size();
int num_to_clean=size/conn_clear_ratio+conn_clear_min; //clear 1/10 each time,to avoid latency glitch int num_to_clean=size/conn_clear_ratio+conn_clear_min; //clear 1/10 each time,to avoid latency glitch
@ -301,43 +311,37 @@ int conn_manager_t::clear_inactive0()
for(;;) for(;;)
{ {
if(cnt>=num_to_clean) break; if(cnt>=num_to_clean) break;
if(mp.begin()==mp.end()) break;
if(lru.empty()) break; if(it==mp.end())
address_t key; {
my_time_t ts=lru.peek_back(key); it=mp.begin();
}
//if(mp.begin()==mp.end()) break;
//if(it==mp.end())
//{
// it=mp.begin();
//}
auto it=mp.find(key);
if(it->second->state.server_current_state==server_ready &&current_time - it->second->last_hb_recv_time <=server_conn_timeout) if(it->second->state.server_current_state==server_ready &&current_time - it->second->last_hb_recv_time <=server_conn_timeout)
{ {
//it++; it++;
} }
else if(it->second->state.server_current_state!=server_ready&& current_time - it->second->last_state_time <=server_handshake_timeout ) else if(it->second->state.server_current_state!=server_ready&& current_time - it->second->last_state_time <=server_handshake_timeout )
{ {
//it++; it++;
} }
else if(it->second->blob!=0&&it->second->blob->conv_manager.s.get_size() >0) else if(it->second->blob!=0&&it->second->blob->conv_manager.s.get_size() >0)
{ {
assert(it->second->state.server_current_state==server_ready); assert(it->second->state.server_current_state==server_ready);
//it++; it++;
} }
else else
{ {
mylog(log_info,"[%s:%d]inactive conn cleared \n",my_ntoa(it->second->raw_info.recv_info.src_ip),it->second->raw_info.recv_info.src_port); mylog(log_info,"[%s:%d]inactive conn cleared \n",my_ntoa(it->second->raw_info.recv_info.src_ip),it->second->raw_info.recv_info.src_port);
//old_it=it; old_it=it;
//it++; it++;
erase(it); erase(old_it);
} }
cnt++; cnt++;
} }
//clear_it=it; clear_it=it;
return 0; return 0;
} }

View File

@ -283,9 +283,9 @@ struct conn_manager_t //manager for connections. for client,we dont need conn_m
unordered_map<address_t,conn_info_t*> mp; //put it at end so that it de-consturcts first unordered_map<address_t,conn_info_t*> mp; //put it at end so that it de-consturcts first
lru_collector_t<address_t> lru; //lru_collector_t<address_t> lru;
//unordered_map<u64_t,conn_info_t*>::iterator clear_it; unordered_map<address_t,conn_info_t*>::iterator clear_it;
long long last_clear_time; long long last_clear_time;

View File

@ -591,7 +591,7 @@ int server_on_raw_recv_handshake1(conn_info_t &conn_info,id_t tmp_oppsite_id )
return 0; return 0;
}*/ }*/
int server_on_timer(conn_info_t &conn_info) //for server. called when a timer is ready in epoll.for server,there will be one timer for every connection int server_on_timer(conn_info_t &conn_info) //for server. called when a timer is ready in epoll.for server,there will be one timer for every connection
// there is also a global timer for server,but its not handled here
{ {
char ip_port[40]; char ip_port[40];
u32_t ip=conn_info.raw_info.send_info.dst_ip; u32_t ip=conn_info.raw_info.send_info.dst_ip;