P2p: algorithmic optimisation in P2p_pool.

This commit is contained in:
Grégoire Henry 2019-02-19 16:29:54 +01:00
parent 15b61d6b84
commit 5f378c8ba0
No known key found for this signature in database
GPG Key ID: 50D984F20BD445D2

View File

@ -303,8 +303,11 @@ let gc_points ({ config = { max_known_points } ; known_points } as pool) =
match max_known_points with
| None -> ()
| Some (_, target) ->
let current_size = P2p_point.Table.length known_points in
if current_size > target then
let to_remove_target = current_size - target in
let now = Time.now () in (* TODO: maybe time of discovery? *)
let table = Gc_point_set.create target in
let table = Gc_point_set.create to_remove_target in
P2p_point.Table.iter (fun p point_info ->
if P2p_point_state.is_disconnected point_info then
let time =
@ -358,13 +361,16 @@ let gc_peer_ids ({ peer_meta_config = { score } ;
match max_known_peer_ids with
| None -> ()
| Some (_, target) ->
let table = Gc_peer_set.create target in
let current_size = P2p_peer.Table.length known_peer_ids in
if current_size > target then
let to_remove_target = current_size - target in
let table = Gc_peer_set.create to_remove_target in
P2p_peer.Table.iter (fun peer_id peer_info ->
let created = P2p_peer_state.Info.created peer_info in
let score = score @@ P2p_peer_state.Info.peer_metadata peer_info in
if P2p_peer_state.is_disconnected peer_info then
Gc_peer_set.insert (score, created, peer_id) table)
known_peer_ids ;
Gc_peer_set.insert (score, created, peer_id) table
) known_peer_ids ;
let to_remove = Gc_peer_set.get table in
ListLabels.iter to_remove ~f:begin fun (_, _, peer_id) ->
P2p_peer.Table.remove known_peer_ids peer_id