Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpCache] Do not call terminate() on cache hit#46763

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@Toflar
Copy link
Contributor

@ToflarToflar commentedJun 24, 2022
edited
Loading

QA
Branch?6.2
Bug fix?no
New feature?yes
Deprecations?yes
Tickets-
LicenseMIT
Doc PR-

Currently,HttpCache always calls thekernel.terminate events, even if the response is coming from cache.
Why is this a problem?

kernel.terminate events are used to do things after the response has been sent to the visitor. At least that happens if you have support forfastcgi_finish_request().
For Contao for example, we use this to dispatch a message to update the search index but you can imagine a lot of stuff being done there, like sending e-mails etc. Accordingto the docs, it says "perform some heavy action".

This means that currently, the system is basically always booted even when the response is coming fromHttpCache because dispatching theTerminateEvent causes the container to be booted etc. which makes the system slower than it needs to be.

We don't need to update the search index when the response is coming from the cache because it already is up to date. And there are no e-mails or other "heavy actions" to perform because by definition, nothing could've happened as the system was not booted (or should not have been).

Also, imagine if you used a "real" reverse proxy like Varnish. There's no call to the back end either when there's a cache hit so it's actually an inconsistency. You cannot "perform some heavy action" there either. If you wanted to, it would have to be implemented in the proxy itself. So Varnish would need to trigger that heavy action. HttpCache should behave just the same.
You could e.g. use theEventDispatchingHttpCache fromhttps://github.com/FriendsOfSymfony/FOSHttpCache, if you need something like that.

alexander-schranz and apfelbox reacted with thumbs up emoji
@carsonbotcarsonbot added this to the4.4 milestoneJun 24, 2022
@ToflarToflarforce-pushed thefix/no-terminate-call-on-cache-hit branch 2 times, most recently from90348c9 toc7b7593CompareJune 24, 2022 09:19
@Toflar
Copy link
ContributorAuthor

Failing tests unrelated, imho.

@Toflar
Copy link
ContributorAuthor

Mentioning some users ofHttpCache for their OSS projects:@dbu@alexander-schranz@chirimoya@andrerom

Copy link
Contributor

@alexander-schranzalexander-schranz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Make sense from my point of view!

@andrerom
Copy link

I think it makes (a lot of) sense for eZ=>Ibexa as well, but as I'm not there anymore I'll ping@bdunogier who might know who is involved in this now

@bdunogier
Copy link

Thank you@andrerom ! I'll ping@adamwojs about it :)

adamwojs reacted with thumbs up emoji

@GromNaN
Copy link
Member

That seems reasonable.
Regarding our policy, this is a performance improvement that may break someone's code if they need the terminate listeners to be called on cache hit. Your PR should target 6.2.

Copy link
Contributor

@dbudbu left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this seems reasonable to me. the other kernel events are also not triggered on a cache hit (as the cache kernel does not forward the request to the wrapped kernel). having only the terminate event seems odd. and indeed, when a separate caching proxy is used, no terminate is triggered.

the code was added over a decade ago:7efe4bc

i can see the fear of breaking some existing systems. i think most delayed tasks should not be needed after a cache hit, but if some sort of reporting is done in the framework it might care about cache hits too.

another option could be to use a flag whether to forward the termination event for cache hits that defaults to true for now, and maybe do a deprecation warning if it is not set to false, to make people aware that the behaviour will change.

without a flag, the behaviour can be changed by extending the HttpCache class and overwriting the terminate method to unconditionally forward the event.

@Toflar
Copy link
ContributorAuthor

To me, this is definitely a bug so I don't see why this would not need to be fixed in 4.4.
However, I understand that we cannot simply change the current behavior in a bugfix release so I've introduced a new configuration option. That allows everybody to fix it whenever they want.

Not sure if I should deprecate this as I did now. And if so, how the heck did we expect deprecations in 4.4? With the annotation still - so I would need to have two test methods and cannot useif - else in the same test as I do now?

Copy link
Contributor

@dbudbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

regarding bug vs change, i think we are here in really a gray area.

there is nothing technically wrong with calling terminate. no security risk, no exceptions happening. you can't be sure that nobody would want the event to happen, so i don't think its correct to consider it a bug.

it is a significant waste of server resources even if it should not affect response times directly. the option seems justified to me, and given how unlikely it is to need the event, i think it makes sense to change the default in the next major version. (e.g. logging of requests should happen at webserver level, not in PHP)

given how long it has been like this, i would vote for stability in this case and only change the default in the next major.

@Toflar
Copy link
ContributorAuthor

I agree, that's why the default remains untouched now. However, I think we should be given the ability to fix it easily in all actively supported versions without having to overrideterminate() in every single project.

dbu reacted with thumbs up emoji

Copy link
Member

@fabpotfabpot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As explained in the comments, this must be done in 6.2.
In addition, performance optimizations are only for 6.2 as well.
Also, as it might break BC anyway, it cannot be part of 4.4 where stability is paramount.

@fabpot
Copy link
Member

Forgot to mention that I think this is indeed a good idea to have that in 6.2.

@Toflar
Copy link
ContributorAuthor

With the option there is no BC break. It just offers the users the ability to adjust their setups in 4.4 already.
I'm unsure what I need to do now :)
If you want this in 6.2 only, would you want me to still keep the option when I rebase or not? :)

Copy link
Member

@GromNaNGromNaN left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

With the option there is no BC break. It just offers the users the ability to adjust their setups in 4.4 already. I'm unsure what I need to do now :) If you want this in 6.2 only, would you want me to still keep the option when I rebase or not? :)

We really appreciate the investigations. The proposed solution is good for the next minor version (6.2).@fabpot listed the reasons it cannot be merged in an old branch:

  • it is not a security issue, not a functional bug
  • it is a new feature (performance optimization are feature)
  • it adds a new option
  • it adds a depreciation message (which is good for changing the default behavior in 7.0)

@ToflarToflar changed the base branch from4.4 to6.2June 25, 2022 20:21
@ToflarToflarforce-pushed thefix/no-terminate-call-on-cache-hit branch fromfa6aeb5 toc730730CompareJune 25, 2022 20:21
@ToflarToflarforce-pushed thefix/no-terminate-call-on-cache-hit branch fromc730730 to662eb17CompareJune 25, 2022 20:28
@Toflar
Copy link
ContributorAuthor

My question was just if you want to still keep the option now that we've decided it should be 6.2 but I guess we should do that. PR is updated. Failing tests seem unrelated, the current 6.2 branch does not pass apparently :)

@nicolas-grekasnicolas-grekas removed this from the4.4 milestoneJun 26, 2022
@nicolas-grekasnicolas-grekas added this to the6.2 milestoneJun 26, 2022
@fabpot
Copy link
Member

Thank you@Toflar.

Toflar reacted with thumbs up emoji

@fabpotfabpot merged commit47c2da7 intosymfony:6.2Jun 27, 2022
@ToflarToflar deleted the fix/no-terminate-call-on-cache-hit branchJune 27, 2022 08:57
fabpot added a commit that referenced this pull requestSep 20, 2022
…e_on_cache_hit HttpCache option (wouterj)This PR was merged into the 6.2 branch.Discussion----------[FrameworkBundle] Add semantic config for new terminate_on_cache_hit HttpCache option| Q             | A| ------------- | ---| Branch?       | 6.2| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Tickets       | -| License       | MIT| Doc PR        |symfony/symfony-docs#16999Adds the semantic configuration for the option introduced in Symfony 6.2 by#46763Commits-------bb387e9 [FrameworkBundle] Add semantic config for new terminate_on_cache_hit HttpCache option
@fabpotfabpot mentioned this pull requestOct 24, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@GromNaNGromNaNGromNaN left review comments

@fabpotfabpotfabpot approved these changes

+2 more reviewers

@dbudbudbu approved these changes

@alexander-schranzalexander-schranzalexander-schranz approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

9 participants

@Toflar@andrerom@bdunogier@GromNaN@fabpot@dbu@alexander-schranz@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp