Conversation
jderusse
left a comment
There was a problem hiding this comment.
You should split this PR in 2:
- adding the
uploadPartCopyoperation in S3 - adding a new method in SimpleS3 that use the new method of S3
| $bytePosition = 0; | ||
| $parts = []; | ||
| for ($i = 1; $bytePosition < $contentLength; ++$i) { | ||
| $startByte = $bytePosition; | ||
| $endByte = $bytePosition + $partSize - 1 >= $contentLength ? $contentLength - 1 : $bytePosition + $partSize - 1; | ||
| $parts[] = $this->doMultipartCopy($destBucket, $destKey, $uploadId, $i, "{$srcBucket}/{$srcKey}", $startByte, $endByte); | ||
| $bytePosition += $partSize; | ||
| } |
There was a problem hiding this comment.
| $bytePosition = 0; | |
| $parts = []; | |
| for ($i = 1; $bytePosition < $contentLength; ++$i) { | |
| $startByte = $bytePosition; | |
| $endByte = $bytePosition + $partSize - 1 >= $contentLength ? $contentLength - 1 : $bytePosition + $partSize - 1; | |
| $parts[] = $this->doMultipartCopy($destBucket, $destKey, $uploadId, $i, "{$srcBucket}/{$srcKey}", $startByte, $endByte); | |
| $bytePosition += $partSize; | |
| } | |
| $partIndex = 1; | |
| $startByte = 0; | |
| while ($startByte < $contentLength) { | |
| $endByte = min($startByte + $partSize, $contentLength) - 1; | |
| $parts[] = $this->doMultipartCopy($destBucket, $destKey, $uploadId, $partIndex, "{$srcBucket}/{$srcKey}", $startByte, $endByte); | |
| $startByte += $partSize; | |
| $partIndex ++; | |
| } |
| for ($i = 1; $bytePosition < $contentLength; ++$i) { | ||
| $startByte = $bytePosition; | ||
| $endByte = $bytePosition + $partSize - 1 >= $contentLength ? $contentLength - 1 : $bytePosition + $partSize - 1; | ||
| $parts[] = $this->doMultipartCopy($destBucket, $destKey, $uploadId, $i, sprintf('%s/%s', $srcBucket, $srcKey), $startByte, $endByte); |
There was a problem hiding this comment.
would it make sens to run this in parallel?
There was a problem hiding this comment.
makes sense
but i have no idea how to implement this))
There was a problem hiding this comment.
How this could be runned in parallel?
There was a problem hiding this comment.
Avoid consuming the response: When you access a property (calling a getter) the response blocks until the response is fully processed.
once again, I don't know if it's better to run theses requests in sequence or parallel.
(Maybe run too many requests in parallel have worse performance) => you need to check AWS recommendations for this.
to process requests in parallel you should do something like
for (...) {
$responses[] = $client->uploadPartCopy(...)
}
$success = true;
foreach ($responses as $response) {
try {
$copyPartResult = $response->getCopyPartResult();
$parts[] = new CompletedPart(['ETag' => $copyPartResult->getEtag(), 'PartNumber' => $partNumber]);
} catch (\Throwable $e) {
$success = false;
break'
}
}
if (!$success) {
$this->abortMultipartUpload(['Bucket' => $bucket, 'Key' => $key, 'UploadId' => $uploadId]);
foreach ($responses as $response) {
try {
$response->cancel();
} catch (\Throwable $e) {
// ...
}
}
throw ...;
}
There was a problem hiding this comment.
Got it!
Seems like the only limit is 10 000 connections (equal to parts)
https://docs.aws.amazon.com/AmazonS3/latest/userguide/qfacts.html
Anyway, think that 10k connections, even without body, it is too much.
AWS SDK has concurrency option for such copy
Will see how to implement it here
|
Closing in favor of #1592 |
fix #1589