MINOR: pattern: do not needlessly lookup the LRU cache for empty lists

If a pattern list is empty, there's no way we can find its elements in
the pattern cache, so let's avoid this expensive lookup. This can happen
for ACLs or maps loaded from files that may optionally be empty for
example. Doing so improves the request rate by roughly 10% for a single
such match for only 8 threads. That's normal because the LRU cache
pre-creates an entry that is about to be committed for the case the list
lookup succeeds after a miss, so we bypass all this.
This commit is contained in:
Willy Tarreau 2023-08-22 07:22:05 +02:00
parent 3fde27d980
commit 821fc95146
1 changed files with 6 additions and 6 deletions

View File

@ -491,7 +491,7 @@ struct pattern *pat_match_str(struct sample *smp, struct pattern_expr *expr, int
}
/* look in the list */
if (pat_lru_tree) {
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) {
unsigned long long seed = pat_lru_seed ^ (long)expr;
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
@ -534,7 +534,7 @@ struct pattern *pat_match_bin(struct sample *smp, struct pattern_expr *expr, int
struct pattern *ret = NULL;
struct lru64 *lru = NULL;
if (pat_lru_tree) {
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) {
unsigned long long seed = pat_lru_seed ^ (long)expr;
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
@ -603,7 +603,7 @@ struct pattern *pat_match_reg(struct sample *smp, struct pattern_expr *expr, int
struct pattern *ret = NULL;
struct lru64 *lru = NULL;
if (pat_lru_tree) {
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) {
unsigned long long seed = pat_lru_seed ^ (long)expr;
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
@ -686,7 +686,7 @@ struct pattern *pat_match_beg(struct sample *smp, struct pattern_expr *expr, int
}
/* look in the list */
if (pat_lru_tree) {
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) {
unsigned long long seed = pat_lru_seed ^ (long)expr;
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
@ -730,7 +730,7 @@ struct pattern *pat_match_end(struct sample *smp, struct pattern_expr *expr, int
struct pattern *ret = NULL;
struct lru64 *lru = NULL;
if (pat_lru_tree) {
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) {
unsigned long long seed = pat_lru_seed ^ (long)expr;
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
@ -778,7 +778,7 @@ struct pattern *pat_match_sub(struct sample *smp, struct pattern_expr *expr, int
struct pattern *ret = NULL;
struct lru64 *lru = NULL;
if (pat_lru_tree) {
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) {
unsigned long long seed = pat_lru_seed ^ (long)expr;
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),