OPTIM: pattern: only apply LRU cache for large enough lists
As shown in issue #1518, the LRU cache has a non-null cost that can sometimes be above the match cost it's trying to avoid. After a number of tests, it appears that: - "simple" match operations (sub, beg, end, int etc) reach a break-even after ~20 patterns in list - "heavy" match operations (reg) reach a break-even after ~5 patterns in list Let's only consult the LRU cache when the number of patterns in the expression is at least as large as this limit. Of course there will always be outliers but it already starts good. Another improvement consists in reducing the cache size to further speed up lookups, which makes sense if less expressions use the cache.
This commit is contained in:
parent
25b0592745
commit
555994c968
|
@ -496,7 +496,7 @@ struct pattern *pat_match_str(struct sample *smp, struct pattern_expr *expr, int
|
|||
}
|
||||
|
||||
/* look in the list */
|
||||
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) {
|
||||
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns) && expr->ref->entry_cnt >= 20) {
|
||||
unsigned long long seed = pat_lru_seed ^ (long)expr;
|
||||
|
||||
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
|
||||
|
@ -539,7 +539,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 && !LIST_ISEMPTY(&expr->patterns)) {
|
||||
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns) && expr->ref->entry_cnt >= 20) {
|
||||
unsigned long long seed = pat_lru_seed ^ (long)expr;
|
||||
|
||||
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
|
||||
|
@ -608,7 +608,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 && !LIST_ISEMPTY(&expr->patterns)) {
|
||||
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns) && expr->ref->entry_cnt >= 5) {
|
||||
unsigned long long seed = pat_lru_seed ^ (long)expr;
|
||||
|
||||
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
|
||||
|
@ -674,7 +674,7 @@ struct pattern *pat_match_beg(struct sample *smp, struct pattern_expr *expr, int
|
|||
}
|
||||
|
||||
/* look in the list */
|
||||
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns)) {
|
||||
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns) && expr->ref->entry_cnt >= 20) {
|
||||
unsigned long long seed = pat_lru_seed ^ (long)expr;
|
||||
|
||||
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
|
||||
|
@ -718,7 +718,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 && !LIST_ISEMPTY(&expr->patterns)) {
|
||||
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns) && expr->ref->entry_cnt >= 20) {
|
||||
unsigned long long seed = pat_lru_seed ^ (long)expr;
|
||||
|
||||
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
|
||||
|
@ -766,7 +766,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 && !LIST_ISEMPTY(&expr->patterns)) {
|
||||
if (pat_lru_tree && !LIST_ISEMPTY(&expr->patterns) && expr->ref->entry_cnt >= 20) {
|
||||
unsigned long long seed = pat_lru_seed ^ (long)expr;
|
||||
|
||||
lru = lru64_get(XXH3(smp->data.u.str.area, smp->data.u.str.data, seed),
|
||||
|
|
Loading…
Reference in New Issue