Problem/Motivation
When a view is saved, views_invalidate_cache()
is called, resulting in an entire re-build of the views cache being required. On a site with a lot of views, this process can take 30+ seconds and renders the entire site unusable until it has been rebuilt.
Proposed resolution
In the case of saving a view, I would have thought just clearing the single view from the cache and then clearing the page/block/menu cache would be sufficient. We shouldn't need to rebuild cache of the entire views data or any other view, as saving a specific view wont affect any of those.
Comment | File | Size | Author |
---|---|---|---|
#29 | 2071607-29.patch | 2.39 KB | joelpittet |
| |||
#17 | saving_a_view_causes-2071607-17.patch | 2.26 KB | joelpittet |
#1 | 2071607-only_clear_related_cache_on_view_save.patch | 2.12 KB | andrewbelcher |
Comments
Comment #1
andrewbelcher CreditAttribution: andrewbelcher commentedI don't really know views' internals very well so I don't know if this would have other problems, but I've attached a patch that I think may resolve the issue by allowing a 'partial' call to
views_invalidate_cache()
...Comment #2
AnybodyI can confirm that this problem still exists. Saving a view requires up to 16 GB (!!) of memory on my page. This is not really nice ;)
Comment #3
andyg5000In our instance, variable_set('menu_rebuild_needed', TRUE); that's called in views_invalidate_cache() is the killer and isn't addressed in the patch. Looking for a solution other than commenting that out as discussed in #2263557: Slow performance when saving views which I closed as a dupe of this.
Comment #4
david_garcia CreditAttribution: david_garcia commentedThe complete menu rebuild is also an issue. But it is the only way to get changes in views displays that have a path (such as pages) to take inmediate effect.
Maybe a quick solution would be to only invalidate the menu cache if:
- Any of the existing views is of type "page" (or any display that uses a path) and the path has changed.
- A display of the current view has been added/removed, and it uses paths.
This last solutions does not look that bad, as it will only invalidate the menu cache if anything in the view has changed that afects it.
Comment #5
Shane Birley CreditAttribution: Shane Birley commentedIs there anything I can do to help with this issue? I have a few sites where the saving of a view takes about 200 years. I didn't realize that each save forces such a clearing of any cache systems.
Comment #6
joelpittet@Shane Birley can you confirm this patch saves a few years?
This patch looks like it would be very useful. Is there anything missing where it would miss things that need to be cleared?
Comment #7
joelpittetComment #8
joelpittetA rough performance test with just devel, saving a view that didn't change changed (opened the title and hit ok to get the save button).
Xdebug was turned off:
And to the point about
variable_set('menu_rebuild_needed', TRUE);
Just disabling that with the patch and no xdebug:Summary
This patch saves me roughly ~700ms-1s. Avoiding the menu rebuild saved ~8.5 seconds from that.
So the bigger win would go to avoiding the menu rebuild. Are there any conditions we could check like (path changed on view, or other things that would require a menu rebuild)?
Menu path doesn't change often so this could be huge.
or work on core menu rebuilding not taking so long:)
Comment #9
torgosPizza@joelpittet: Regarding the rebuilding of menu items, give #1978176: Build menu_tree without loading so many objects a glance. There was a patch there that helped me a LOT but it still needs some work.
Comment #10
joelpittet@torgosPizza I'm on that issue, a bit worried about #1978176-68: Build menu_tree without loading so many objects #68 David R's comment about security.
Comment #11
joelpittetThanks for pointing at it again though. I should really take a stab to see my savings!
Comment #12
joelpittetUsing the patch @torgosPizza mentioned in #9 with xdebug off and doing the same quick devel page test of saving a view on no changes and with the patch applied.
The page execution time was roughly the same. So unfortunately no gain was made with that other issue's patch for me.
Comment #13
torgosPizzaYeah, the earlier one was the one that actually got me decent results (comment #32). I guess it's one of those YMMV situations!
Comment #14
sylus CreditAttribution: sylus commentedI understand that it is only the menu_rebuild that yields drastic results but as for the original patch and issue itself I think it does make sense to only invalidate the cache for a single view. Possible to RTBC this patch and leave the rest to #1978176: Build menu_tree without loading so many objects?
Comment #15
joelpittetI'm going to RTBC this because I've been using it for quite some time and it was helping me out:)
Comment #16
joelpittetActually, with the latest dev it needs a re-roll, then RTBC:)
Comment #17
joelpittetRe-roll of #1
Comment #19
AnybodyMhm any idea why the tests fail? I can confirm it was RTBC and working before...
Comment #20
sylus CreditAttribution: sylus commentedRe-triggering
Comment #23
joelpittetThe tests are expecting more is cleared than are, or we need to clear some other cid as well.
Comment #24
torgosPizzaThis patch helped us, as we've been dealing with downtime every time I save one particular View. For me it's RTBC but to @joelpittet's comment I'd like to see what we can do to get the tests to turn green.
Comment #25
Anybody+1 for #24. In case the view display has a menu entry perhaps the menu cache also has to be cleared? Might that cause the tests to fail?
Comment #27
AnybodyI've just been running into a new downtime again because this patch was not commited... bad trouble with the customer. For large sites this is a real problem causing downtimes so I'm now pushing the priority. I also retriggered to test and will have a look at the reasons why it still fails afterwards.
Comment #28
joseph.olstadwe're also using this patch #17 because it's such a huge improvement on save speeds, (despite the test failures) , not sure why the test failures.
Comment #29
joelpittetThis will solve the test failures but I'm not sure what caches need to be cleared and which ones are fine to leave on save and delete?
Comment #30
AnybodyThank you joelpittet, the patch looks good so far. But it should also consider to only set
if a menu related setting has been changes or the view display type is menu related (like "page"). Otherwise the menu rebuild is extremely painful and expensive. It also locks the database until the rebuild is done.
Comment #31
joelpittet@Anybody, that sounds like a nice addition but maybe a scope creep on this issue. There is no context provided to that function to help tell if the view has a menu or not.
The bigger question to get this in is "How do we know we've cleared enough from
cache_views
"? There could be a contrib that potentially relies on that clear to function which could be a blocker for this.Comment #32
Anybody@joelpittet: Thank you for your quick reply. You are right that one main question is "How do we know we've cleared enough from cache_views"? but I'm sadly not able to answer that question. Should we perhaps contact a views maintainer for that?
But furthermore I think that the menu rebuild point is not a nice addition but a very important point. On large websites that is a very huge problem and as far as we can tell even the largest problem of all at this point. Currently we even have to comment out that line on pages with > 1 mio nodes. And that page uses panels etc. to include views instead of views pages. I think that menu related views (=views page display type) are at least < 50% of all views display types used.
But of course we may not introduce wrong or missing functionality here but I think that function call has to be much more granular perhaps at a very different point int the views display definition, perhaps using a hook?
If you ask me, that call should have never been placed at that point.
So how can we go on and who can we ask best?
If you agree I'd like to place these two last points on the agenda to finally fix this old issue.
Comment #33
joelpittet@Anybody, the
menu_rebuild_needed
point could be it's own issue.Not sure who to ask.
Comment #34
gdaw CreditAttribution: gdaw as a volunteer commentedRTBC+1 patch 17
Comment #35
joseph.olstadBased on #14, but with patch #29
Keep scope small, see Sylus comment #14
Huge performance improvement
Comment #36
joseph.olstad3.19 was just released, somehow we missed including this :(
patch has a significant performance implication as mentioned previously
Check to make sure if the patch needs a reroll or not.
Comment #37
DamienMcKennaSorry for missing this.
Lets get it into the next stable release.
Comment #39
DamienMcKennaCommitted. Thanks.