Problem/Motivation

See #1199866: Add an in-memory LRU cache - let's use that code here. Postponing on that one...

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3498154

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexpott created an issue. See original summary.

catch’s picture

Either in this issue or a follow-up, we should remove or modify MigrateExecutable::attemptMemoryReclaim()

alexpott changed the visibility of the branch 3498154-use-lru-cache to hidden.

heddn’s picture

re: slot count:

From #1199866-84: Add an in-memory LRU cache, the thought was that this should be a much higher number then 300. So it is nice to see a number of 1000. Do we know if smaller hosting, e.g. an entry level pantheon plan will hold 1000 entity slots for 5-6 fields on a node or paragraph?

alexpott’s picture

@heddn well atm the moment the number of slots in your cache is infinite so this is not really making anything worse. 5-6 fields on node is not that much - I tried to get the amount of memory used by a node on a production site with a complex data model. I think it might in the realms of 0.2mb per node... so a 1000 of them is about 200mb which is well within what I would expect you to be running a migrate job with. I expect that most sites nodes would take up considerably less space.

catch’s picture

Status: Postponed » Needs review

alexpott’s picture

Now that #1199866: Add an in-memory LRU cache is in we should use it!

catch’s picture

Very nice. Looks like StandardPerformanceTest needs a tweak.

berdir’s picture

No sure I see why this affects standard performance test.

Could that be a random fail? https://git.drupalcode.org/project/drupal/-/pipelines/440609/test_report... does say it failed quite a lot recently on 11.x.

catch’s picture

Hmm I think I saw a similar failure somewhere else, maybe it's a random failure. Not sure we need those assertions now we have the grouped cache tag assertions so might be better to just drop them entirely.

berdir’s picture

Yeah, I've been meaning to file an issue about that, started leaving them out in some cases, they no have no performance meaning now that we can assert the amount of actual lookup queries.

I can't trigger a retest on the MR or I would have done that, saw a similar comment recently, apparently an issue with merge requests created by core maintainers?

catch’s picture

The permissions on pipelines are different depending on whether they're triggered by a commit by a core committer or not, I do not really understand why but it's inherent to gitlab. Even the directory it runs in is different which was very annoying when trying to add phpstan et al result caching (it only worked for core committer MRs for a couple of weeks until we noticed).

catch’s picture

alexpott’s picture

Test went green on re-running.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems pretty straight forward, not entirely sure how else to review.

#16 has also already been committed

kristiaanvandeneynde’s picture

Should we document 'entity.memory_cache.slots: 1000' and/or its usefulness for migrations somewhere? Seems like something that could save a lot of time if we explain it beforehand rather than when found during debugging of your migration's memory issues.

MigrateExecutable used to release the entities from memory but no longer does as long as we don't reach the 1000 limit, yet we have (minor) concerns from @heddn that people (with free hosting plans) will run out of memory. To me, that seems like a behavioral change that could lead to some nasty hour-long debugging sessions figuring out why stuff isn't working anymore.

So I'm not sure about RTBC. Seems like we may have some collateral damage here if we release this without a CR or documentation.

alexpott’s picture

We could set the number of slots in a compiler pass and change it if you have less memory.

catch’s picture

Memory could be different for web vs. cli so I'm not sure about changing it dynamically like that.

kristiaanvandeneynde’s picture

I'd rather we leave it at 1k but at least mention this in the release notes, accompanied with a CR explaining you can change this behavior with a container param. Adding dynamic memory profiling is perhaps a bit overkill and may lead to obscure bugs.

kristiaanvandeneynde’s picture

I'll draft a CR, one sec.

kristiaanvandeneynde’s picture

https://www.drupal.org/node/3512407

Does this seem sufficient? It won't "kill" migrations per se, but it will trigger more batches and as a result may end up loading the same entities into memory over and over for every batch, leading to slower migrations.

Edit: Before, it would erase all entities from memory, so the change makes migrations faster as we can reuse the entities we do have in memory. It will just lead to more batches being created once we hit the memory limit because we no longer flush the entity cache. Not sure what the impact is of firing up a lot more batches vs the old behavior. If I were to guess, the old behavior was probably still slower.

catch’s picture

CR reads really well to me.

berdir’s picture

Agreed with leaving it at a fixed value, the scope here is that it shouldn't affect web requests and it can be lowered if necessary.

alexpott’s picture

The problem is if you are on minimal hosting changing container params is a right pfaff and knowing that you have to do that is going to be very hard to find out.

kristiaanvandeneynde’s picture

Couldn't people change this from their services.yml file which is automatically picked up because it's in the container_yamls setting?

Which reminds me we didn't add this new container param to default.services.yml. We might want to do that as it gives us the opportunity to write some brief documentation in its comment.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Adding to default.services.yml is a good idea, moving back to needs work for that.

alexpott’s picture

Status: Needs work » Needs review

Added the param to default.services.yml

kristiaanvandeneynde’s picture

Status: Needs review » Reviewed & tested by the community

LGTM.

Maybe wait until @alexpott confirms a services.yml file in sites/default is enough to take away his concerns in #27?

alexpott’s picture

We can start here - if it proves a problem then we can visit. Ideally if you're on cheap limited hosting you don't have to edit files to do a migration. I recently set up D11 on some cheap hosting it has 2GB memory limit in PHP so maybe Pantheon will up their game... 128Mb seems tiny.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Yeah I think this is fine for now. For drush migrations it will start a new batch if it runs into trouble, the more common situation I've seen on Pantheon is regular hook_update_N() and config import running out of memory, which this may or may not help but we'll find out.

Committed/pushed to 11.x, thanks!

  • catch committed d0743bcb on 11.x
    Issue #3498154 by alexpott, catch, kristiaanvandeneynde: Use LRU Cache...

catch’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.