Skip to content

Conversation

@mrow4a
Copy link
Contributor

@mrow4a mrow4a commented Apr 27, 2018

Description

Don't check for existence in the storage (e.g. objectstorage) twice if we know it is not a part file.

In that section of the code, we were checking for file existence in the storage twice for the same path. In case of part file we indeed need to check twice, but otherwise not.

There is no difference for Filesystem storage, but Objectstorage/Files_primary_s3 is affected.

  • Requires unit tests adjustments due to changed function

How did I test

perf-obj-part

@mrow4a
Copy link
Contributor Author

mrow4a commented Apr 27, 2018

These function was confusing (readFirstBlock), so better compare differences in the PhpStorm

* @param string|resource $path
* @return string
*/
protected function readFirstBlock($path) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readFirstBlock was generalized for resource and storage -> I created dedicated functions, readResourceFirstBlock and readStorageFirstBlock.

Copy link
Contributor Author

@mrow4a mrow4a Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"readFirstBLock function" was also checking if path exists.. loosing 1 query per PUT.

*/
protected function getHeader($path) {
$filecacheExists = false;
if (\is_resource($path)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I handle the "header" logic separately for resource and separately for storage.

$firstBlock = $this->readStorageFirstBlock($realFile);
$filecacheExists = true;
$path = $realFile;
} else if ($realFile != $path && $this->storage->file_exists($path)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes no sense to ask again if $realFile==$path..

Copy link
Contributor Author

@mrow4a mrow4a Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to this fact, we are wining here 1 filecache query for each PUT. @DeepDiver1975 @PVince81 @butonic

$realFile = $this->util->stripPartialFileExtension($path);
$targetExists = $this->file_exists($realFile) || $this->file_exists($path);
$targetExists = false;
if ($this->file_exists($realFile) || ($realFile != $path && $this->file_exists($path))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are wining another 2 filecache queries here (file_exists function with objecstore needs 2 queries to be performed per call) @PVince81 @DeepDiver1975 @butonic

@codecov
Copy link

codecov bot commented May 5, 2018

Codecov Report

Merging #31299 into master will decrease coverage by <.01%.
The diff coverage is 56%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #31299      +/-   ##
============================================
- Coverage     63.46%   63.46%   -0.01%     
- Complexity    18529    18534       +5     
============================================
  Files          1167     1167              
  Lines         69498    69505       +7     
  Branches       1264     1264              
============================================
+ Hits          44108    44111       +3     
- Misses        25021    25025       +4     
  Partials        369      369
Flag Coverage Δ Complexity Δ
#javascript 52.58% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 64.71% <56%> (-0.01%) 18534 <2> (+5)
Impacted Files Coverage Δ Complexity Δ
lib/private/Encryption/Util.php 63.28% <ø> (ø) 49 <0> (ø) ⬇️
lib/private/Files/Storage/Wrapper/Encryption.php 64.49% <56%> (-0.38%) 161 <2> (+5)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7797c05...e84fc1c. Read the comment docs.

@PVince81
Copy link
Contributor

conflicts

@mrow4a
Copy link
Contributor Author

mrow4a commented May 19, 2018

Resolved conficts, and added description above how I tested it (including queires analysis)

@mrow4a
Copy link
Contributor Author

mrow4a commented May 19, 2018

However, if this PR #28166 goes into live (cache in filecache), this PR is more of refactoring and cleaning the code.

@mrow4a
Copy link
Contributor Author

mrow4a commented May 20, 2018

Can be obsoleted by #31486

@mrow4a
Copy link
Contributor Author

mrow4a commented Jun 30, 2018

I refresh this PR, since due to the fact there is no decision on introducing "cache of filecache", this PR is fixing the code logic.

@PVince81 @DeepDiver1975 @butonic

$firstBlock = '';
}
}
$firstBlock = $this->readFirstBlock($path);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using one generalized function, which introduced issue - I have two dedicated ones.

$path = $realFile;
// Original file pointed by part file exists in the storage
$firstBlock = $this->readStorageFirstBlock($realFile);
} else if ($realFile != $path && $this->storage->file_exists($path)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont check if file_exists again, if realFile is the same as path (points to the same file)

@mrow4a
Copy link
Contributor Author

mrow4a commented Aug 12, 2018

Most likely being closed with #31958

@mrow4a
Copy link
Contributor Author

mrow4a commented Nov 12, 2018

Obsoleted by #31958

@mrow4a mrow4a closed this Nov 12, 2018
@mrow4a mrow4a deleted the optimize_put_6 branch November 12, 2018 18:40
@lock lock bot locked as resolved and limited conversation to collaborators Nov 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants