-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(plugins/proxy-cache): add wildcard and parameter match support for content_type #10055
Conversation
sister PR: #10030 |
47f3f08
to
4683619
Compare
4683619
to
0042da5
Compare
LGTM on the code wise, this needs to get merged after #10030 |
1ec0b59
to
39b66ad
Compare
build/openresty/patches/ngx_lua-0.10.21_02-dyn_upstream_keepalive.patch
Outdated
Show resolved
Hide resolved
5b1f384
to
0883866
Compare
@vm-001 Could you please rebase? |
0883866
to
0fe260e
Compare
it will not create conflicts @hanshuebner because this PR is creating a new dedicated EDIT: tracked in KAG-789 |
Unification would be good. We don't want to have to implementations of basically the same thing. Please create a KAG ticket for visibility. |
It has been confirmed that the lua-protobuf under version 0.4.2 causes the Segmentation fault(core dump) while used with lpeg. The issue was found in another PR(#10055).
Co-authored-by: Enrique García Cota <[email protected]>
0fe260e
to
298e5b0
Compare
put a block on this PR as the original perf (#10030 (comment)) doesn't seem to prove that lpeg is faster than ngx.re |
@fffonion The log of that test is reversed(due to the typo), I've just corrected that. Here is the output from my computer:
|
The reason why lpeg is faster in this example program is that the regular expression to parse the parameters is evaluated multiple times, once for each parameter provided. If the whole matching is done by one regular expression evaluation, it is faster than lpeg. Let's not try to be too cheap when making arguments about performance. The regular expression based version of the code also is easier to understand and reason about than the lpeg based version because it uses less named local state. Also, regular expressions are much more widely known than lpeg, which is a plus in terms of review- and maintainability. |
Writing a single static regular expression able to match a content type(with multiple parameters) is almost impossible. If an example content type with parameters here is to be considered cheap. Then Feel free to remove - local media_type = (types/format_types) * (parameters/merge_params) * P(-1)
+ local media_type = (types/format_types) * P(-1) The Regular expression is indeed easy to maintain compared to Lpeg, but the media type is something RFC and hasn't been changed for a decade. That's why I think using Lpeg for this scenario is acceptable. |
I'm not sure what you mean by that. How about
The performance benefit of the lpeg version is too small to warrant an implementation that is opaque and can't be reviewed unless one learns a non-standard parsing library. There is much more to be gained spending time learning how to use regular expressions. |
It's not working. Missing "charset = UTF-8" local inspect = require("inspect")
local r = ngx.re.match("application/json;charset=UTF-8;Foo=Bar", [[(?<type>.+)\/(?<subtype>[^ ;]+)(?:;\s*([^= ]+)=([^; ]+))*]])
print(inspect(r))
--[[
{ "application", "json", "Foo", "Bar",
[0] = "application/json;charset=UTF-8;Foo=Bar",
subtype = "json",
type = "application"
}
--]] |
That's true, and you're probably right in claiming that it is difficult to make it work in one regular expression. However, the overhead lies completely in the invocation of the regular expression parser, so reducing the number of regular expression evaluations is the key to improving performance. Regular expressions are easier to review and more universal than lpeg, and they're also faster to write, so the use of an obscure parsing library does not seem to be warranted, in particular given that the performance argument can be made both ways. |
Summary
Add wildcard and parameter match support for content_type
Checklist
Issue reference
FTI-1131