Redirects performance: permalinks vs nginx

(Jay Pfaffman) #1

I’ve just submitted a PR for the mybb importer that includes permalinks for users, categories, and topics (in Discourse terminology. The person I did it for is concerned that having Discourse handle these will be less efficient than having NGINX do it.

My naive understanding is that until rails goes looking for permalinks there’s no performance hit (other than a bit of database overhead) and when it does go looking, it does a single indexed database search. I’d think that if an external NGINX were doing it, it would be looking at all of those redirects on every query, but that can’t be right (can it?).

I’ve seen some discussions, though, about having an external nginx handle these redirects, and at least one importer generates a CSV file to use to do external redirects. What are the tradeoffs?

There are about 25K users, 150 categories, and 12K topics plus one permalink normalization to remove cruft after the .html in the URL.

(Jeff Atwood) #2

A question for @sam I think.

(Sam Saffron) #3

Perf wise nginx is likely faster, but the savings here are hardly worth the extra complexity

Each redirect costing you 10ms vs 1ms is hardly an issue, the redirects are permanent

(Stefano Maffulli) #4

Are the redirects evaluated at each URL request? If so, your estimate of 10x slower is for each page load or only for the redirected ones?

(Sam Saffron) #5

The redirects are all evaluated at the end of the chain, the lookup itself takes about 0.1ms.

It adds nothing to normal page lookups, it adds 0.1ms or so to 404s

The 10ms is the standard middleware walk every request to rails does. (actual timing for a middleware walk can range between 3-15ms depending on the phase of the moon)

(Jay Pfaffman) #6

And if NGINX did that before reverse proxying to Rails, wouldn’t it make all of those lookups longer?

(Sam Saffron) #7

Only one way to find out … measure …

(Jay Pfaffman) #8

I was afraid you’d say that. :wink: