Cache all OGNL expressions (when enabled) irrespective of their execution status [Fixes WW-5147]#504
Conversation
|
Thanks! LGTM 👍 just curious why you want to keep an expression which always fails! |
|
Very good question, indeed. ;-) The short answer is that it will always fail but will always be evaluated anyway. So better avoiding the cost of parsing in any case... Some more details on the case below. This is because this single expression can be evaluated through a chain, and the way the method Here are a few values of the And a stack trace for the Here, the Struts layer attempts to find the I did spend some time to check how method Would you say that this sequence of event is normal, or is it something that should not occur? Let me know, and I'll open another issue - I can reproduce it 100% so it's easy to investigate if you find it useful... |
|
Hi @davoustp. Thanks for producing this PR in response to the JIRA issue. 👍 The proposed change addresses the JIRA issue that was raised, by adding any expression/tree that can be "successfully parsed" to the expression cache. The original logic (prior to the change) would only add the expression/tree to the expression cache if the expression could be successfully executed (in addition to being "successfully parsed"). Looking at the history of There may be a trade-off in execution performance (by allowing more expressions to be considered "valid" and cached) and memory utilization (due to the larger number of potential expressions now being cached). It may be difficult to predict if the change in this PR might result in unexpected memory overhead, for some applications, due to potentially increased expression cache size. Having expressions considered "valid" if-and-only-if they can be executed successfully may have provided a limiting factor to keep the cache size more manageable in the past, but that is just my speculation. This change may be safer to attempt for the 2.6.x branch (as opposed to PR #503 for 2.5.x), since it introduces a new behaviour for the expression cache. Thoughts ? |
My pleasure, that's normal to contribute back when we find something useful for the community (OSS rocks).
Yep, that's my belief as well, the logic/behaviour is not documented, neither as a comment nor in commit history, so we're stuck in a guess game.
Very true, as with any caching strategy: you trade off CPU or latency against memory.
Definitely. However, I do think that this is a weird way to implement memory usage control. If we care about memory control, I would then rather go using a real cache with a proper eviction policy, such as https://github.com/ben-manes/caffeine (I use it a lot, it's rock stable, highly efficient and extremely flexible). This way, any application generating a very large set of expressions would still get the benefit of caching for the more frequently used expressions without growing the cache too large. And expressions get cached irrespective of any evaluation result. A small set of configuration knobs might be required as well (to allow user control on cache retention duration, bounded/unbounded and upper bound if needed...).
If we prefer keeping the changes low, yes, of course, we could have that change in 2.6.x only. |
|
I tried looking at Looking into using a full-fledged cache (like cache2k or caffeine, possibly using the JSR107/JCache API to be provider-agnostic) for the expression cache could be interesting. Alternatively, implementing a slightly more sophisticated customization of the existing cache (without introducing any new dependencies), could be interesting too. That could be a new feature request for 2.6.x. As for this PR and 2.6.x, given the explanation and arguments you have provided, I think it seems reasonable to apply to 2.6.x, and see how things behave. 👍 |
|
Thanks @JCgH4164838Gh792C124B5 ! I do have the same analysis as yours re: the ASTChain logic - this looks by design, but no clue as to whether this is normal or not. I opened up the new issue https://issues.apache.org/jira/browse/OGNL-261 to continue to discuss about these OGNL internals and get this PR limited to the OGNL expression caching scope. |
|
Thanks a lot @davoustp for the explanations. My only concern was cache as with caching all the valid expressions DDoS can be easily performed - yet I think this can be also improved by using a better caching mechanism. I opt to merge this PR, but only support those changes in Struts 2.6.x - I wouldn't introduce such behaviour in 2.5.x (also I just want to focus on 2.6.x branch, tbh) |
|
Hi @lukaszlenart, |
|
Thanks a lot @davoustp 💯 |
No description provided.