Skip to content
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

[HttpKernel] FileProfilerStorage remove expired profiles mechanism #47352

Merged
merged 0 commits into from Dec 18, 2022

Conversation

alamirault
Copy link
Contributor

@alamirault alamirault commented Aug 21, 2022

Q A
Branch? 6.2
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #45831
License MIT
Doc PR symfony/symfony-docs#...

This is a first attempt for limit number of profiles saved (discussed in #45831).
When we save new profile, all expired profiles are removed. Expiration is one day for the moment.

Questions:

  • Not sure how to deal, profiles with time 0, like an unexpired profile ?
  • I assume profiles are sorted and oldest profile is on firstline. -> avoid readind all index file if first profile is not expired
  • Is there a best way ? (cpu/memory, io efficient) (I'm not sure I have the necessary skills, changes are welcome :))

TODOS:

  • Changelog
  • Complete tests
  • Symfony docs PR

@carsonbot
Copy link

Hey!

To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done?

Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review.

Cheers!

Carsonbot

@alamirault alamirault force-pushed the feature/45831-remove-expired-profiles branch from c670f8a to 6cd2a51 Compare August 21, 2022 13:27
@alamirault alamirault changed the title [HttpKernel] FileProfilerStorage has remove expired profiles mechanism [HttpKernel] FileProfilerStorage remove expired profiles mechanism Aug 21, 2022
@alamirault alamirault marked this pull request as ready for review August 21, 2022 13:34
@carsonbot carsonbot added this to the 6.2 milestone Aug 21, 2022
@alamirault alamirault force-pushed the feature/45831-remove-expired-profiles branch from cb75093 to cf10b53 Compare October 29, 2022 12:26
@nicolas-grekas nicolas-grekas modified the milestones: 6.2, 6.3 Nov 5, 2022
@nicolas-grekas nicolas-grekas force-pushed the feature/45831-remove-expired-profiles branch 2 times, most recently from da36747 to 600596f Compare December 16, 2022 10:25
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

I updated the PR with the following changes:

  • set expiration at 2 days
  • run randomly 1 / 10
  • never write to index.csv but store a seek offset in index.csv.offset

The seek offset allows looking up for files to prune very quickly, that's why 1/10 is enough IMHO.
index.csv is going to grow but this file is small and doing so saves us from race conditions.

@alamirault
Copy link
Contributor Author

Thanks Nicolas, I like your rework !

@fabpot
Copy link
Member

fabpot commented Dec 18, 2022

Thank you @alamirault.

@alamirault alamirault deleted the feature/45831-remove-expired-profiles branch December 18, 2022 11:42
@alamirault alamirault restored the feature/45831-remove-expired-profiles branch December 18, 2022 11:53
@fabpot fabpot mentioned this pull request May 1, 2023
nicolas-grekas added a commit that referenced this pull request Jul 13, 2023
…age (radar3301)

This PR was merged into the 6.3 branch.

Discussion
----------

[HttpKernel] Skip corrupted CSV data in FileProfilerStorage

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Partially fixes #50942, improves/fixes on PR #50913, partially fixes #50816
| License       | MIT

Technically, part of this fix could go all the way back to 2.1, but since we're not sure why/how exactly the index.csv file is being corrupted in the first place, this PR should just serve as a stop-gap measure until the root cause can be identified.

A corrupted index.csv file is especially noticeable since 6.3, when the "Remove Expired Profiles" feature was added by #47352 .

RE: improves/fixes on PR #50913:
Warnings are (usually?) only escalated to errors in debug mode, so having a try/catch is a bit more overhead than I think is actually needed, and I believe just checking that the line read from the csv is not corrupted is the better/faster option. Granted, the profiler should really only be active in debug/non-production modes anyway, but "should" and reality usually don't align...

`@alamirault` `@MatTheCat` `@benjaminfunk` `@Pelagoss` `@derrabus`

Commits
-------

b4e942d Update FileProfilerStorage.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[WebProfiler] Add a limit how many profiles should be saved
5 participants