wp-cli icon indicating copy to clipboard operation
wp-cli copied to clipboard

Potential memory leaks with WXR export

Open stevegrunwell opened this issue 11 years ago • 18 comments

I'm currently working on exporting a rather large data set (~225,000 posts/attachments), split into 5MB chunks via the wp export command with the --max_file_size=5 argument. Even when I limit the post dates to a very narrow range, the memory used by the process will continue to grow until it hits PHP's limit (6GB on this particular server), at which point the export process will be killed.

As the process runs (and continues to write files–usually 12-15 before it crashes), the memory consumed by the process continues to grow; I'd expect some holdover as files are split, but not 6GB-worth.

stevegrunwell avatar Mar 09 '15 21:03 stevegrunwell

Intriguing. I'm dealing with a similar problem right now, except wp import :wink:

I imagine there is a memory leak somewhere.

danielbachhuber avatar Mar 09 '15 21:03 danielbachhuber

I've been having this same problem with wp import on vipquickstart when importing VIP sites. Same symptoms - as it runs, memory usage grows uncontrollably until it hits PHP's memory limit, and then the process crashes.

TheLastCicada avatar Mar 09 '15 22:03 TheLastCicada

@TheLastCicada see https://github.com/Automattic/vip-quickstart/issues/398

danielbachhuber avatar Mar 09 '15 22:03 danielbachhuber

@danielbachhuber that's how we've been making it work, but is it expected behavior that a wp-cli import needs over 1GB of RAM? My experience with this has been that on some imports, we need to set the WP_MAX_MEMORY_LIMIT to 2GB to get it to import, and even then it seems like we just got lucky and it imported before it hit the memory limit. Is this how I should expect the importer to work? Seems like an awful lot of RAM to need for this, especially when WordPress itself will run on almost nothing.

TheLastCicada avatar Mar 09 '15 22:03 TheLastCicada

FWIW, WP_MAX_MEMORY_LIMIT is set to 6G on the server where the importer's getting killed.

stevegrunwell avatar Mar 09 '15 22:03 stevegrunwell

but is it expected behavior that a wp-cli import needs over 1GB of RAM?

The WordPress importer is a pile of rubbish. I wouldn't be surprised if there was some structural memory inefficiencies. As I'm watching my import run right now, I'm seeing the memory usage slowly grow and grow by MB. I haven't worked on this problem in a while though, so I'll give it some thought.

Seems like an awful lot of RAM to need for this, especially when WordPress itself will run on almost nothing.

The importer wasn't designed for the pain we're putting it through :wink:

danielbachhuber avatar Mar 09 '15 22:03 danielbachhuber

Ah I was afraid of that. If there's a more efficient way wp-cli can interact with the importer to limit the memory footprint, that would be a tremendous improvement to my quality of life right now :)

TheLastCicada avatar Mar 09 '15 23:03 TheLastCicada

cc: @sboisvert in case you have anything to add here. We should chat about profiling wp import and wp export in Quickstart.

joshbetz avatar Mar 10 '15 00:03 joshbetz

The WordPress importer is a pile of rubbish.

It is long overdue for an overhaul or even replacement and as someone who does an awful lot of large site importing I would love to be part of a conversation regarding coming up with something better.

ryanmarkel avatar Mar 10 '15 01:03 ryanmarkel

We are working on a couple rebuilds from another system to WordPress. We choose to use the WP-API to do the import.

As for an export. We also have good experiences with using the same WP-API to export everything into another system by letting a script crawl the paged API endpoints and handle the JSON on the other side (in this case ruby)

sebastiaandegeus avatar Mar 10 '15 08:03 sebastiaandegeus

@TheLastCicada @joshbetz @sboisvert I'm not sure why it was missing before, but I've added a stop_the_insanity() equivalent in #1794 if you have a large import you can test it out on.

I suspect the exporter has the same object cache problem. However, it's a bit black box so I'll need to think on where I'd add it.

danielbachhuber avatar Apr 23 '15 13:04 danielbachhuber

@danielbachhuber has this resolved it for you? I am running into this issue as well. 3 import files totaling several hundred megs. Spins its wheels for a while, starts importing and after a few dies :S

blobaugh avatar Apr 28 '15 20:04 blobaugh

I am running into this issue as well. 3 import files totaling several hundred megs.

Which version of WP-CLI are you using?

danielbachhuber avatar Apr 28 '15 20:04 danielbachhuber

WP-CLI 0.15.0

Just upgraded to 0.19.0 and rerunning the importer

blobaugh avatar Apr 28 '15 20:04 blobaugh

@stevegrunwell @TheLastCicada I'd like to close the loop on the potential memory leak with the exporter. Have you run into the issue recently, and/or can you provide more details on how I might be able to reproduce?

danielbachhuber avatar May 03 '16 12:05 danielbachhuber

Have you run into the issue recently, and/or can you provide more details on how I might be able to reproduce?

Actually, it wasn't so difficult to reproduce once I took a look 😄

danielbachhuber avatar May 03 '16 12:05 danielbachhuber

Looking forward to these improvements!

TheLastCicada avatar May 03 '16 21:05 TheLastCicada

Looking forward to these improvements!

wp cli update --nightly :)

danielbachhuber avatar May 03 '16 21:05 danielbachhuber