MAJOR: pattern: add LRU-based cache on pattern matching
authorWilly Tarreau <w@1wt.eu>
Wed, 29 Apr 2015 14:24:50 +0000 (16:24 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 29 Apr 2015 17:15:24 +0000 (19:15 +0200)
commitf3045d2a06b68b9878ba4a1accd1a6714e0e7a9d
tree42271836c9130a8557b3230fcc4cbddc505e569e
parent72f073b6c7478e6846dfe67eedb1642af45c4562
MAJOR: pattern: add LRU-based cache on pattern matching

The principle of this cache is to have a global cache for all pattern
matching operations which rely on lists (reg, sub, dir, dom, ...). The
input data, the expression and a random seed are used as a hashing key.
The cached entries contains a pointer to the expression and a revision
number for that expression so that we don't accidently used obsolete
data after a pattern update or a very unlikely hash collision.

Regarding the risk of collisions, 10k entries at 10k req/s mean 1% risk
of a collision after 60 years, that's already much less than the memory's
reliability in most machines and more durable than most admin's life
expectancy. A collision will result in a valid result to be returned
for a different entry from the same list. If this is not acceptable,
the cache can be disabled using tune.pattern.cache-size.

A test on a file containing 10k small regex showed that the regex
matching was limited to 6k/s instead of 70k with regular strings.
When enabling the LRU cache, the performance was back to 70k/s.
doc/configuration.txt
include/common/defaults.h
include/types/global.h
src/cfgparse.c
src/haproxy.c
src/pattern.c