Testing nginx rewrite performance

Our website is 12 years old and over time we have accured quite a few URL changes. Mainly due to terminlogy changes and SEO restructures. 819 to be exact. They are rewrite rules in a nginx config file. This is a lot of regular expressions that nginx needs to execute every request. We were interested in the performance impact so we did a quick test.

We created a minimum nginx config:

Lets check it works

ok, we’re ready for our first test, which is the base-case, i.e. 0 redirects. We’ll use vegeta to time the latency over 10,000 requests.

For test 2, we’ll add 819 rewrite rules to nginx and test again. I won’t show all our rewrite rules but here is a small extract to show an example of the kind of thing we’re talking about:

Lets run the same test, 10,000 requests again but this time I mount the rewriterules.conf into the nginx docker container:

The median latency has worsened from 132.126µs to 172.16µs. This is peanuts, but it shows the extra rewrites are having a impact to performance, however small.

Lets finish up by trying a really large number of rewrites. I took my rewriterules.conf file, did select-all, then copy and paste, paste, paste*10 until I had 10,000 rules. I ran exactly the same command as the previous test:

The results

With no rewrites a page is served in 132.126µs. With 819 rewrites a page is served in 172.16µs. With 10,000 rewrites a page is served in 906.9µs.

The conclusion

Ngix rewrites are super fast, use as many as you want because the performance impact is negligible. We’re talking nano-seconds.

No Comment

Post A Comment