From 8fd4e5f47efd13a6bad7811239438539ae383966 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Mon, 7 Dec 2015 17:06:38 +0100 Subject: Make peer handling more efficient Each service process maintains a dictionary of peers, mapping an application alias to a {pid(), #diameter_caps{}} list of connected peers. These lists are potentially large, peers were appended to the end of the list for no particular reason, and these long lists were constructed/deconstructed when filtering them for pick_peer callbacks. Many simultaneous outgoing request could then slow the VM to a crawl, with many scheduled processes mired in list manipulation. The pseudo-dicts are now replaced by plain ets tables. The reason for them was (once upon a time) to have an interface interchangeable with a plain dict for debugging purposes, but strict swapablity hasn't been the case for some time now, and in practice a swap has never taken place. Additional tables mapping Origin-Host/Realm have also been introduced, to minimize the size of the peers lists when peers are filtered on host/realm. For example, a filter like {any, [{all, [realm, host]}, realm]} is probably a very common case: preferring a Destination-Realm/Host match before falling back on Destination-Realm alone. This is now more efficiently (but not equivalently) expressed as {first, [{all, [realm, host]}, realm]} to stop the search when the best match is made, and extracts peers from host/realm tables instead of searching through the list of all peers supporting the application in question. The code to try and start with a lookup isn't exhaustive, and the 'any' filter is still as inefficient as previously. --- lib/diameter/doc/src/diameter.xml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'lib/diameter/doc/src') diff --git a/lib/diameter/doc/src/diameter.xml b/lib/diameter/doc/src/diameter.xml index b0cff32c9a..dbbbb01138 100644 --- a/lib/diameter/doc/src/diameter.xml +++ b/lib/diameter/doc/src/diameter.xml @@ -466,7 +466,7 @@ Matches only those peers whose Origin-Host has the specified value, or all peers if the atom any.

-{realm, any|&dict_DiameterIdentity; +{realm, any|&dict_DiameterIdentity;}

Matches only those peers whose Origin-Realm has the @@ -499,18 +499,22 @@ Matches only those peers matched by each filter in the specified list.

Matches only those peers matched by at least one filter in the -specified list.

+specified list. +The resulting list will be in match order, peers matching the +first filter of the list sorting before those matched by the second, +and so on.

+
+{first, [&peer_filter;]} +

-The resulting peer list will be in match order, peers matching the -first filter of the list sorting before those matched by the second, -and so on. -For example, the following filter causes peers matching both the host -and realm filters to be presented before those matching only the realm -filter.

+Like any, but stops at the first filter for which there are +matches, which can be much more efficient when there are many peers. +For example, the following filter causes only peers best matching +both the host and realm filters to be presented.

-{any, [{all, [host, realm]}, realm]}
+{first, [{all, [host, realm]}, realm]}
 
-- cgit v1.2.3