Performance of map directive

Igor Sysoev igor at sysoev.ru
Sat Sep 3 15:50:20 UTC 2011


On Sat, Sep 03, 2011 at 05:11:07PM +0300, Calin Don wrote:
> Hi,
> 
> I understood that if you have only strings in a map directive the access
> time is O(1).

Yes.

> What if you have the hostnames directive enabled and some of the items are
> in the format *.example.com?

nginx tests address by its parts, first "com", then "example".
So access of the operation varies from O(1) to O(N) where N is number of
parts of longest name. For example, if you test example.net only against

*.example.com
*.sub.domain.com

then this will be O(1). If you test www.sub.domain.com, it will be O(3).

> What about if you mix with regular expressions?

The regular expressions tested sequentially.

nginx tests map in the following order:

1) exact names,
2) *.names,
3) names.*,
4) regexes.

The first match stops the tesing.


-- 
Igor Sysoev



More information about the nginx mailing list