MEDIUM: resolvers: replace the answer_list with a (flat) tree

With SRV records, a huge amount of time is spent looking for records
by walking long lists. It is possible to reduce this by indexing values
in trees instead. However the whole code relies a lot on the list
ordering, and even implements some round-robin on it to distribute IP
addresses to servers.

This patch starts carefully by replacing the list with a an eb32 tree
that is still used like a list, with a constant key 0. Since ebtrees
preserve insertion order for duplicates, the tree walk visits the nodes
in the exact same order it did with the lists. This allows to implement
the required infrastructure without changing the behavior.
This commit is contained in:
Willy Tarreau
2021-10-21 07:39:57 +02:00
parent a89c19127d
commit 7893ae117f
2 changed files with 48 additions and 24 deletions

View File

@@ -119,13 +119,13 @@ struct resolv_answer_item {
unsigned int last_seen; /* When was the answer was last seen */
struct resolv_answer_item *ar_item; /* pointer to a RRset from the additional section, if exists */
struct list attached_servers; /* attached server head */
struct list list;
struct eb32_node link; /* linking node */
};
struct resolv_response {
struct dns_header header;
struct list query_list;
struct list answer_list;
struct eb_root answer_tree;
/* authority ignored for now */
};