Fixes album export by reducing memory usage of the scripts. #18
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix-album-export"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Chunks the output buffer to 4kB chunks. This means the Download.php
script will no longer run out of memory when trying to stream a
tar file the output buffer.
@ -63,4 +56,0 @@
);
while($asset = $iterator->Next())
{
$files[] = join(DIRECTORY_SEPARATOR, array('.', $asset->getSubdir(), $asset->getFilename()));
Is this change still useful? It seems like an array with only paths (
$files
) and not the file contents should not get so large as to hit a memory limit.In the old situation the export would fail on the first chunk leaving behind a .tar of ~0kb, This means that the list of files of an album of around 270 pictures already consumed a considerable amount of memory. So I would still like to keep this more "streaming" approach as a optimization.
I don't think that's possible, because if the memory limit was hit while building the array of file names, there would be no tar file at all, since
tar
is invoked after$files
has been built.While I don't think the streaming approach is wrong, this feels like a premature optimization (and certainly one that should not be necessary).
@ -67,4 +56,1 @@
}
}
$descriptorspec = array(
The current code uses
proc_open
, but you might want to look intopassthru
.I'm currently using ther tar's -T functionality to read a list of files in a file seperated by a "\0" byte. and I skipping the file all together by using - as the argument to -T and feeding it the files on STDIN. After a quick look at the passthru i don't think such a thing is possible. and I think i will run out of "command line" space to execute the tar command with passthru.
Agreed that
passthru
is probably the better solution, especially if you're not expecting to handle anything onSTDOUT
orSTDERR
.I do not think the proposed solution to use
STDIN
to manually feed filenames will provide much in the way of performance benefit. If anything, I thinktar
can enumerate files more quickly than a PHP script.@ -28,3 +28,3 @@
// The real magic starts here!
ob_start();
ob_start(null, 32768);
I haven't looked at the rest of the framework, but you might want to consider disabling the output buffer before calling
tar
. This code could then check whether an output buffer is still active withob_get_level
.@aaron what are your thoughts on this? I'm not familiar enough to comment on this.
I agree with @minnozz; much better to disable it locally (i.e. in the download controller) with
ob_end_flush
. In general, output buffering is quite useful.@ -98,0 +83,4 @@
foreach($album_ids as $album_id)
{
$iterator = AssetIterator::getByOptions(
array(
This is an aside, but I'd like to stick to new-style (bracketed) arrays, that is
[]
instead ofarray()
.This is being superseded by PR !19
Pull request closed