How fast and resource-consuming is sub_filter?

Francis Daly francis at daoine.org
Wed Apr 17 12:07:37 UTC 2019


On Fri, Apr 05, 2019 at 12:08:51AM -0400, elkie wrote:

Hi there,

> How bad is the idea of having tens or even hundreds of sub_filter directives
> in nginx configuration?

I suspect that the answer is "it depends".

It sounds to me like it should be inefficient -- but the question is not
"is it bad", but "is it better than another way to achieve the desired
end result".

> Are the replacements by http_sub_module module time- and resource-consuming
> operations, or they are light enough not to care about it?

If you do not measure it being too slow on your system, then it is not
too slow for your use case.

There is a particular result you want to achieve. One way is to use
sub_filter. Maybe another way is to pass content through an external
system which will make the same changes. Maybe another way is to make
a copy of the source content with the changes already made, and serve
the copy directly.

Each possible way will have an initial cost (in writing and testing),
and an ongoing cost (in processing and serving the output).

Maybe a low initial cost (of "adding a bunch of directives to nginx.conf")
is good for you, and the extra processing load of nginx running those
directives each time, is not important to you. In that case, using
sub_filter is probably the right answer for you.

But: I think that only you can measure the load on your hardware with
your input/transform/output content.

If you measure and don't see a problem, there is not a problem that you
looked for.

If you don't measure, then there is not a problem that you care about.

Good luck with it!

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list