Skip to content

Commit

Permalink
[Perf Tests] Storage file share perf tests - track 1 and track 2 (#12746
Browse files Browse the repository at this point in the history
)

### Depends on #12662 and #12737

### Changes in the PR
- Track 2 tests are part of the test folder, which would be compiled along with the regular tests and would require changes if the API is updated
- Track 1 tests - a separate npm project, takes dependence on the perf package, doesn't get compiled along with the regular tests

### To run track 2 tests
1. Build the storage-file-share package `rush build -t storage-file-share`.
2. Navigate to `storage-file-share` folder `cd sdk\storage\storage-file-share\`.
3. Create a storage account and populate the .env file at `storage\storage-file-share` folder with `ACCOUNT_NAME` and `ACCOUNT_KEY` variables.
4. Run the tests as shown below
   - download
     - `npm run perfstress-test:node -- StorageFileShareDownloadTest --warmup 2 --duration 7 --iterations 2 --parallel 2`
   - download to file
     - `npm run perfstress-test:node -- StorageFileShareDownloadToFileTest --warmup 2 --duration 7 --iterations 2 --parallel 2`
   - upload
     - `npm run perfstress-test:node -- StorageFileShareUploadTest --warmup 2 --duration 7 --iterations 2 --parallel 2`
   - upload from file
     - `npm run perfstress-test:node -- StorageFileShareUploadFromFileTest --warmup 2 --duration 7 --iterations 2 --parallel 2`

### To run track 1 tests
1. Navigate to `test-utils\perfstress` folder `cd sdk\test-utils\perfstress\`
2. Build the package `rush update && rush build -t test-utils-perfstress`
3. Pack the perf package `rushx pack`
4. Navigate to `storage-file-share\test\perfstress\track-1` folder `cd sdk\storage\storage-file-share\test\perfstress\track-1`.
5. Install the perf package `npm i ..\..\..\..\..\test-utils\perfstress\azure-test-utils-perfstress-1.0.0.tgz`
6. Run `npm install` to get `storage-file-share V10`.
7. Create a storage account and populate the .env file with `ACCOUNT_NAME` and `ACCOUNT_KEY` variables.
8. Run the tests as follows
   - download
     - `npm run perfstress-test:node -- StorageFileShareDownloadTest --warmup 2 --duration 7 --iterations 2 --parallel 2`
   - upload
     - `npm run perfstress-test:node -- StorageFileShareUploadTest --warmup 2 --duration 7 --iterations 2 --parallel 2`
  • Loading branch information
HarshaNalluru authored Jan 21, 2021
1 parent 1d7e0e4 commit 13196dd
Show file tree
Hide file tree
Showing 16 changed files with 470 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sdk/storage/storage-file-share/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix",
"lint": "eslint package.json api-extractor.json src test --ext .ts -f html -o storage-file-share-lintReport.html || exit 0",
"pack": "npm pack 2>&1",
"perfstress-test:node": "cross-env TS_NODE_COMPILER_OPTIONS=\"{\\\"module\\\": \\\"commonjs\\\"}\" ts-node test/perfstress/track-2/index.spec.ts",
"prebuild": "npm run clean",
"test:browser": "npm run clean && npm run build:test && npm run unit-test:browser",
"test:node": "npm run clean && npm run build:test && npm run unit-test:node",
Expand Down Expand Up @@ -122,6 +123,7 @@
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/test-utils-recorder": "^1.0.0",
"@azure/test-utils-perfstress": "^1.0.0",
"@microsoft/api-extractor": "7.7.11",
"@rollup/plugin-commonjs": "11.0.2",
"@rollup/plugin-multi-entry": "^3.0.0",
Expand Down
14 changes: 14 additions & 0 deletions sdk/storage/storage-file-share/test/perfstress/track-1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
### Guide

1. Navigate to `test-utils\perfstress` folder `cd sdk\test-utils\perfstress\`
2. Build the package `rush update && rush build -t test-utils-perfstress`
3. Pack the perf package `rushx pack`
4. Navigate to `storage-file-share\test\perfstress\track-1` folder `cd sdk\storage\storage-file-share\test\perfstress\track-1`.
5. Install the perf package `npm i ..\..\..\..\..\test-utils\perfstress\azure-test-utils-perfstress-1.0.0.tgz`
6. Run `npm install` to get `storage-file-share V10`.
7. Create a storage account and populate the .env file with `ACCOUNT_NAME` and `ACCOUNT_KEY` variables.
8. Run the tests as follows
- download
- `npm run perfstress-test:node -- StorageFileShareDownloadTest --warmup 2 --duration 7 --iterations 2 --parallel 2`
- upload
- `npm run perfstress-test:node -- StorageFileShareUploadTest --warmup 2 --duration 7 --iterations 2 --parallel 2`
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressOptionDictionary, drainStream } from "@azure/test-utils-perfstress";
import { Aborter, FileURL } from "@azure/storage-file";
import { StorageFileShareTest } from "./storageTest";
import { generateUuid } from "@azure/core-http";

interface StorageFileShareDownloadTestOptions {
size: number;
}

export class StorageFileShareDownloadTest extends StorageFileShareTest<
StorageFileShareDownloadTestOptions
> {
buffer = Buffer.alloc(this.parsedOptions.size.value!);
public options: PerfStressOptionDictionary<StorageFileShareDownloadTestOptions> = {
size: {
required: true,
description: "Size in bytes",
shortName: "sz",
longName: "size",
defaultValue: 1024
}
};

static fileName = generateUuid();
fileClient: FileURL;

constructor() {
super();
this.fileClient = FileURL.fromDirectoryURL(
this.directoryClient,
StorageFileShareDownloadTest.fileName
);
}

public async globalSetup() {
await super.globalSetup();
await this.fileClient.create(Aborter.none, this.parsedOptions.size.value!);
await this.fileClient.uploadRange(Aborter.none, this.buffer, 0, this.parsedOptions.size.value!);
}

async runAsync(): Promise<void> {
const downloadResponse = await this.fileClient.download(Aborter.none, 0);
await drainStream(downloadResponse.readableStreamBody!);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressProgram, selectPerfStressTest } from "@azure/test-utils-perfstress";
import { StorageFileShareDownloadTest } from "./download.spec";
import { StorageFileShareUploadTest } from "./upload.spec";
console.log("=== Starting the perfStress test ===");

const perfStressProgram = new PerfStressProgram(
selectPerfStressTest([StorageFileShareDownloadTest, StorageFileShareUploadTest])
);

perfStressProgram.run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "track-1",
"version": "1.0.0",
"description": "1. Navigate to `test-utils\\perfstress` folder `cd sdk\\test-utils\\perfstress\\`\r 2. Build the package `rush update && rush build -t test-utils-perfstress`\r 3. Pack the perf package `rushx pack`\r 4. Navigate to `storage-file-share\\test\\perfstress\\track-1` folder `cd sdk\\storage\\storage-file-share\\test\\perfstress\\track-1`.\r 5. Install the perf package `npm i ..\\..\\..\\..\\..\\test-utils\\perfstress\\azure-test-utils-perfstress-1.0.0.tgz`\r 6. Run `npm install` to get `storage-file-share V10`.\r 7. Create a storage account and populate the .env file with `ACCOUNT_NAME` and `ACCOUNT_KEY` variables.\r 8. Run the tests as follows\r - download\r - `npm run perfstress-test:node -- StorageFileShareDownloadTest --warmup 2 --duration 7 --iterations 2 --parallel 2`\r - download to file\r - `npm run perfstress-test:node -- StorageFileShareDownloadToFileTest --warmup 2 --duration 7 --iterations 2 --parallel 2`\r - upload\r - `npm run perfstress-test:node -- StorageFileShareUploadTest --warmup 2 --duration 7 --iterations 2 --parallel 2`\r - upload from file\r - `npm run perfstress-test:node -- StorageFileShareUploadFromFileTest --warmup 2 --duration 7 --iterations 2 --parallel 2`",
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@azure/storage-file": "^10.3.0",
"@azure/test-utils-perfstress": "file:../../../../../test-utils/perfstress/azure-test-utils-perfstress-1.0.0.tgz"
},
"scripts": {
"perfstress-test:node": "ts-node index.spec.ts"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressTest, getEnvVar } from "@azure/test-utils-perfstress";
import {
ServiceURL,
ShareURL,
DirectoryURL,
StorageURL,
SharedKeyCredential,
Aborter
} from "@azure/storage-file";

// Expects the .env file at the same level as the "test" folder
import * as dotenv from "dotenv";
import { generateUuid } from "@azure/core-http";
dotenv.config({ path: "../../../.env" });

export abstract class StorageFileShareTest<TOptions> extends PerfStressTest<TOptions> {
shareServiceClient: ServiceURL;
shareClient: ShareURL;
directoryClient: DirectoryURL;
static shareName = generateUuid();
static dirName = generateUuid();

constructor() {
super();
const connectionString = getEnvVar("STORAGE_CONNECTION_STRING");
const accountName = getValueInConnString(connectionString, "AccountName");
const accountKey = getValueInConnString(connectionString, "AccountKey");
const sharedKeyCredential = new SharedKeyCredential(accountName, accountKey);
this.shareServiceClient = new ServiceURL(
`https://${accountName}.file.core.windows.net`,
StorageURL.newPipeline(sharedKeyCredential)
);
this.shareClient = ShareURL.fromServiceURL(
this.shareServiceClient,
StorageFileShareTest.shareName
);
this.directoryClient = DirectoryURL.fromShareURL(
this.shareClient,
StorageFileShareTest.dirName
);
}

public async globalSetup() {
await this.shareClient.create(Aborter.none);
await this.directoryClient.create(Aborter.none);
}

public async globalCleanup() {
await this.shareClient.delete(Aborter.none);
}
}

export function getValueInConnString(
connectionString: string,
argument: "AccountName" | "AccountKey"
) {
const elements = connectionString.split(";");
for (const element of elements) {
if (element.trim().startsWith(argument)) {
return element.trim().match(argument + "=(.*)")![1];
}
}
return "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressOptionDictionary } from "@azure/test-utils-perfstress";
import { Aborter, FileURL } from "@azure/storage-file";
import { StorageFileShareTest } from "./storageTest";
import { generateUuid } from "@azure/core-http";

interface StorageFileShareUploadTestOptions {
size: number;
}
export class StorageFileShareUploadTest extends StorageFileShareTest<
StorageFileShareUploadTestOptions
> {
buffer = Buffer.alloc(this.parsedOptions.size.value!);
fileClient: FileURL;
public options: PerfStressOptionDictionary<StorageFileShareUploadTestOptions> = {
size: {
required: true,
description: "Size in bytes",
shortName: "sz",
longName: "size",
defaultValue: 1024
}
};

constructor() {
super();
const fileName = generateUuid();
this.fileClient = FileURL.fromDirectoryURL(this.directoryClient, fileName);
}

async setup() {
await this.fileClient.create(Aborter.none, this.parsedOptions.size.value!);
}

async runAsync(): Promise<void> {
await this.fileClient.uploadRange(Aborter.none, this.buffer, 0, this.parsedOptions.size.value!);
}
}
14 changes: 14 additions & 0 deletions sdk/storage/storage-file-share/test/perfstress/track-2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
### Guide

1. Build the storage-file-share package `rush build -t storage-file-share`.
2. Navigate to `storage-file-share` folder `cd sdk\storage\storage-file-share\`.
3. Create a storage account and populate the .env file at `storage\storage-file-share` folder with `ACCOUNT_NAME` and `ACCOUNT_KEY` variables.
4. Run the tests as shown below
- download
- `npm run perfstress-test:node -- StorageFileShareDownloadTest --warmup 2 --duration 7 --iterations 2 --parallel 2`
- download to file
- `npm run perfstress-test:node -- StorageFileShareDownloadToFileTest --warmup 2 --duration 7 --iterations 2 --parallel 2`
- upload
- `npm run perfstress-test:node -- StorageFileShareUploadTest --warmup 2 --duration 7 --iterations 2 --parallel 2`
- upload from file
- `npm run perfstress-test:node -- StorageFileShareUploadFromFileTest --warmup 2 --duration 7 --iterations 2 --parallel 2`
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { generateUuid } from "@azure/core-http";
import { PerfStressOptionDictionary, drainStream } from "@azure/test-utils-perfstress";
import { ShareFileClient } from "../../../src";

import { StorageFileShareTest } from "./storageTest.spec";
interface StorageFileShareDownloadTestOptions {
size: number;
}

export class StorageFileShareDownloadTest extends StorageFileShareTest<
StorageFileShareDownloadTestOptions
> {
public options: PerfStressOptionDictionary<StorageFileShareDownloadTestOptions> = {
size: {
required: true,
description: "Size in bytes",
shortName: "sz",
longName: "size",
defaultValue: 1024
}
};
static fileName = generateUuid();
fileClient: ShareFileClient;

constructor() {
super();
this.fileClient = this.directoryClient.getFileClient(StorageFileShareDownloadTest.fileName);
}

public async globalSetup() {
await super.globalSetup();
await this.fileClient.uploadData(Buffer.alloc(this.parsedOptions.size.value!));
}

async runAsync(): Promise<void> {
const downloadResponse = await this.fileClient.download();
await drainStream(downloadResponse.readableStreamBody!);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressOptionDictionary } from "@azure/test-utils-perfstress";
import { ShareFileClient } from "../../../src";
import fs from "fs";
import util from "util";
const fileExists = util.promisify(fs.exists);
const mkdir = util.promisify(fs.mkdir);
const deleteFile = util.promisify(fs.unlink);

import { StorageFileShareTest } from "./storageTest.spec";
import { generateUuid } from "@azure/core-http";
interface StorageFileShareDownloadTestOptions {
size: number;
}

const localDirName = "temp";

export class StorageFileShareDownloadToFileTest extends StorageFileShareTest<
StorageFileShareDownloadTestOptions
> {
public options: PerfStressOptionDictionary<StorageFileShareDownloadTestOptions> = {
size: {
required: true,
description: "Size in bytes",
shortName: "sz",
longName: "size",
defaultValue: 1024
}
};
static fileName = generateUuid();
fileClient: ShareFileClient;
localFileName: string;

constructor() {
super();
this.fileClient = this.directoryClient.getFileClient(
StorageFileShareDownloadToFileTest.fileName
);
this.localFileName = generateUuid();
}

public async globalSetup() {
await super.globalSetup();
if (!(await fileExists(localDirName))) await mkdir(localDirName);
await this.fileClient.uploadData(Buffer.alloc(this.parsedOptions.size.value!));
}

public async cleanup() {
await deleteFile(`${localDirName}/${this.localFileName}`);
}

async runAsync(): Promise<void> {
await this.fileClient.downloadToFile(`${localDirName}/${this.localFileName}`, 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PerfStressProgram, selectPerfStressTest } from "@azure/test-utils-perfstress";
import { StorageFileShareDownloadTest } from "./download.spec";
import { StorageFileShareDownloadToFileTest } from "./downloadToFile.spec";
import { StorageFileShareUploadTest } from "./upload.spec";
import { StorageFileShareUploadFromFileTest } from "./uploadFromFile.spec";

console.log("=== Starting the perfStress test ===");

const perfStressProgram = new PerfStressProgram(
selectPerfStressTest([
StorageFileShareDownloadTest,
StorageFileShareDownloadToFileTest,
StorageFileShareUploadTest,
StorageFileShareUploadFromFileTest
])
);

perfStressProgram.run();
Loading

0 comments on commit 13196dd

Please sign in to comment.