Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement parallel operations #2067

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8717527
feat: implement parallel operations
ddelgrosso1 Aug 15, 2022
22097df
add more parallel operations
ddelgrosso1 Sep 15, 2022
9a59f1f
add header to test file
ddelgrosso1 Sep 15, 2022
d2b241f
update import of fs/promises
ddelgrosso1 Sep 15, 2022
30b45d3
fix pathing on windows, fix mocking of fs promises
ddelgrosso1 Sep 16, 2022
16a5f05
add jsdoc headers to class and uploadMulti
ddelgrosso1 Sep 16, 2022
5a94aa7
add jsdoc comments to remaining functions
ddelgrosso1 Sep 30, 2022
1cc8bae
update comment wording
ddelgrosso1 Oct 24, 2022
face55f
add experimental jsdoc tags
ddelgrosso1 Oct 27, 2022
524a310
feat: add directory generator to performance test framework
ddelgrosso1 Nov 3, 2022
bac3ed8
clarify variable names and comments
ddelgrosso1 Nov 3, 2022
b4bc333
capitalization
ddelgrosso1 Nov 3, 2022
46687c6
wip: transfer manager performance tests
ddelgrosso1 Nov 10, 2022
721aab6
feat: merged in application performance tests (#2100)
shaffeeullah Nov 10, 2022
f5e8121
fix: fixed many bugs (#2102)
shaffeeullah Nov 15, 2022
886dc03
fix: more work on transfer manager perf metrics (#2103)
ddelgrosso1 Nov 15, 2022
94b1c02
fix: performance test refactoring, comments (#2104)
ddelgrosso1 Nov 16, 2022
9793cc6
refactor: refactor constants (#2105)
shaffeeullah Nov 16, 2022
89e8204
linter fixes, download to disk for performance test
ddelgrosso1 Nov 29, 2022
c153ab6
rename transfer manager functions
ddelgrosso1 Nov 29, 2022
4feb1c2
remove callbacks from transfer manager
ddelgrosso1 Nov 29, 2022
0780e50
add more experimental tags, update comments
ddelgrosso1 Nov 29, 2022
c47130b
change signature of downloadManyFiles to accept array of strings or a…
ddelgrosso1 Nov 30, 2022
4c2dda4
linter fix
ddelgrosso1 Nov 30, 2022
aad8f2b
add transfer manager samples and samples tests
ddelgrosso1 Dec 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
191 changes: 191 additions & 0 deletions internal-tooling/performApplicationPerformanceTest.ts
@@ -0,0 +1,191 @@
/*!
* Copyright 2022 Google LLC. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import yargs from 'yargs';
import {promises as fsp, rmSync} from 'fs';
import {Bucket, DownloadOptions, DownloadResponse, UploadOptions} from '../src';
import {performance} from 'perf_hooks';
// eslint-disable-next-line node/no-unsupported-features/node-builtins
import {parentPort} from 'worker_threads';
import {
BLOCK_SIZE_IN_BYTES,
DEFAULT_PROJECT_ID,
DEFAULT_NUMBER_OF_OBJECTS,
DEFAULT_SMALL_FILE_SIZE_BYTES,
DEFAULT_LARGE_FILE_SIZE_BYTES,
NODE_DEFAULT_HIGHWATER_MARK_BYTES,
generateRandomDirectoryStructure,
getValidationType,
performanceTestSetup,
TestResult,
} from './performanceUtils';
import {TRANSFER_MANAGER_TEST_TYPES} from './performanceTest';

const TEST_NAME_STRING = 'nodejs-perf-metrics-application';
const DEFAULT_BUCKET_NAME = 'nodejs-perf-metrics-shaffeeullah';

let bucket: Bucket;

const checkType = getValidationType();

const argv = yargs(process.argv.slice(2))
.options({
bucket: {type: 'string', default: DEFAULT_BUCKET_NAME},
small: {type: 'number', default: DEFAULT_SMALL_FILE_SIZE_BYTES},
large: {type: 'number', default: DEFAULT_LARGE_FILE_SIZE_BYTES},
projectid: {type: 'string', default: DEFAULT_PROJECT_ID},
numobjects: {type: 'number', default: DEFAULT_NUMBER_OF_OBJECTS},
})
.parseSync();

/**
* Main entry point. This function performs a test iteration and posts the message back
* to the parent thread.
*/
async function main() {
let result: TestResult = {
op: '',
objectSize: 0,
appBufferSize: 0,
libBufferSize: 0,
crc32Enabled: false,
md5Enabled: false,
apiName: 'JSON',
elapsedTimeUs: 0,
cpuTimeUs: 0,
status: '[OK]',
};

({bucket} = await performanceTestSetup(argv.projectid, argv.bucket));

switch (argv.testtype) {
case TRANSFER_MANAGER_TEST_TYPES.APPLICATION_UPLOAD_MULTIPLE_OBJECTS:
result = await performWriteTest();
break;
case TRANSFER_MANAGER_TEST_TYPES.APPLICATION_DOWNLOAD_MULTIPLE_OBJECTS:
result = await performReadTest();
break;
// case TRANSFER_MANAGER_TEST_TYPES.APPLICATION_LARGE_FILE_DOWNLOAD:
// result = await performLargeReadTest();
// break;
default:
break;
}
parentPort?.postMessage(result);
}

async function uploadInParallel(
bucket: Bucket,
paths: string[],
options: UploadOptions
) {
const promises = [];
for (const index in paths) {
const path = paths[index];
const stat = await fsp.lstat(path);
if (stat.isDirectory()) {
continue;
}
options.destination = path;
promises.push(bucket.upload(path, options));
}
await Promise.all(promises).catch(console.error);
}

async function downloadInParallel(bucket: Bucket, options: DownloadOptions) {
const promises: Promise<DownloadResponse>[] = [];
const [files] = await bucket.getFiles();
files.forEach(file => {
promises.push(file.download(options));
});
await Promise.all(promises).catch(console.error);
}

/**
* Performs an iteration of the Write multiple objects test.
*
* @returns {Promise<TestResult>} Promise that resolves to a test result of an iteration.
*/
async function performWriteTest(): Promise<TestResult> {
await bucket.deleteFiles(); //start clean

const creationInfo = generateRandomDirectoryStructure(
argv.numobjects,
TEST_NAME_STRING,
argv.small,
argv.large
);

const start = performance.now();
await uploadInParallel(bucket, creationInfo.paths, {validation: checkType});
const end = performance.now();

await bucket.deleteFiles(); //cleanup files
rmSync(TEST_NAME_STRING, {recursive: true, force: true});

const result: TestResult = {
op: 'WRITE',
objectSize: creationInfo.totalSizeInBytes,
appBufferSize: BLOCK_SIZE_IN_BYTES,
libBufferSize: NODE_DEFAULT_HIGHWATER_MARK_BYTES,
crc32Enabled: checkType === 'crc32c',
md5Enabled: checkType === 'md5',
apiName: 'JSON',
elapsedTimeUs: Math.round((end - start) * 1000),
cpuTimeUs: -1,
status: '[OK]',
};
return result;
}

/**
* Performs an iteration of the read multiple objects test.
*
* @returns {Promise<TestResult>} Promise that resolves to an array of test results for the iteration.
*/
async function performReadTest(): Promise<TestResult> {
await bucket.deleteFiles(); // start clean
const creationInfo = generateRandomDirectoryStructure(
argv.numobjects,
TEST_NAME_STRING,
argv.small,
argv.large
);
await uploadInParallel(bucket, creationInfo.paths, {validation: checkType});

const start = performance.now();
await downloadInParallel(bucket, {validation: checkType});
const end = performance.now();

const result: TestResult = {
op: 'READ',
objectSize: creationInfo.totalSizeInBytes,
appBufferSize: BLOCK_SIZE_IN_BYTES,
libBufferSize: NODE_DEFAULT_HIGHWATER_MARK_BYTES,
crc32Enabled: checkType === 'crc32c',
md5Enabled: checkType === 'md5',
apiName: 'JSON',
elapsedTimeUs: Math.round((end - start) * 1000),
cpuTimeUs: -1,
status: '[OK]',
};

rmSync(TEST_NAME_STRING, {recursive: true, force: true});
await bucket.deleteFiles(); //cleanup
return result;
}

main();