Skip to content

Commit

Permalink
Add perf tests for MS Azure File Storage (T1) API (#17555)
Browse files Browse the repository at this point in the history
* Add perf tests for MS Azure File Storage (T1) API
  • Loading branch information
Mohit-Chakraborty authored Dec 20, 2020
1 parent 59a2698 commit 7600467
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 50 deletions.
1 change: 1 addition & 0 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
<PackageReference Update="Microsoft.Azure.ResourceManager" Version="[1.1.0-preview]" />
<PackageReference Update="Microsoft.Azure.Services.AppAuthentication" Version="[1.0.3, 2.0.0)" />
<PackageReference Update="Microsoft.Azure.Storage.Blob" Version="11.1.7" />
<PackageReference Update="Microsoft.Azure.Storage.File" Version="11.2.2" />
<PackageReference Update="Microsoft.Azure.Storage.Queue" Version="11.1.7" />
<PackageReference Update="Microsoft.Azure.Test.HttpRecorder" Version="[1.13.3, 2.0.0)" />
<PackageReference Update="Microsoft.Azure.WebJobs.Extensions" Version="4.0.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"solution": {
"path": "..\\..\\Azure.Storage.sln",
"projects": [
"..\\..\\common\\Perf\\Azure.Test.Perf\\Azure.Test.Perf.csproj",
"..\\core\\Azure.Core.TestFramework\\src\\Azure.Core.TestFramework.csproj",
"Azure.Storage.Common\\src\\Azure.Storage.Common.csproj",
"Azure.Storage.Files.Shares\\perf\\Azure.Storage.Files.Shares.Perf\\Azure.Storage.Files.Shares.Perf.csproj",
"Azure.Storage.Files.Shares\\perf\\Microsoft.Azure.Storage.File.Perf\\Microsoft.Azure.Storage.File.Perf.csproj",
"Azure.Storage.Files.Shares\\src\\Azure.Storage.Files.Shares.csproj"
]
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using Azure.Core.TestFramework;

namespace Microsoft.Azure.Storage.File.Perf
{
/// <summary>
/// Represents the ambient environment in which the test suite is being run, offering access to information such as environment variables.
/// </summary>
internal sealed class PerfTestEnvironment : TestEnvironment
{
/// <summary>
/// The shared instance of the <see cref="PerfTestEnvironment"/> to be used during test runs.
/// </summary>
public static PerfTestEnvironment Instance { get; } = new PerfTestEnvironment();

/// <summary>
/// The storage account endpoint suffix of the cloud to use for testing.
/// </summary>
public new string StorageEndpointSuffix => base.StorageEndpointSuffix ?? "core.windows.net";

/// <summary>
/// The name of the Files Shares storage account to test against.
/// </summary>
/// <value>The Files Shares storage account name, read from the "AZURE_STORAGE_ACCOUNT_NAME" environment variable.</value>
public string FilesSharesAccountName => GetVariable("AZURE_STORAGE_ACCOUNT_NAME");

/// <summary>
/// The shared access key of the Files Shares storage account to test against.
/// </summary>
/// <value>The Files Shares storage account key, read from the "AZURE_STORAGE_ACCOUNT_KEY" environment variable.</value>
public string FilesSharesAccountKey => GetVariable("AZURE_STORAGE_ACCOUNT_KEY");

/// <summary>
/// The connection string for accessing the Files Shares storage account used for testing.
/// </summary>
public string FileShareAddressString { get; }

/// <summary>
/// Credentials used to authenticate access to the Microsoft Azure storage account used for testing.
/// </summary>
public Auth.StorageCredentials StorageCredentials { get; }

/// <summary>
/// Initializes a new instance of the <see cref="PerfTestEnvironment"/> class.
/// </summary>
public PerfTestEnvironment()
{
FileShareAddressString = $"{Uri.UriSchemeHttps}://{FilesSharesAccountName}.file.{StorageEndpointSuffix}";

StorageCredentials = new Auth.StorageCredentials(FilesSharesAccountName, FilesSharesAccountKey);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Storage.File" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\..\..\..\common\Perf\Azure.Test.Perf\Azure.Test.Perf.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Reflection;
using Azure.Test.Perf;

await PerfProgram.Main(Assembly.GetEntryAssembly(), args);
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Azure.Test.Perf;

namespace Microsoft.Azure.Storage.File.Perf.Scenarios
{
/// <summary>
/// The performance test scenario focused on downloading files from the Microsoft Azure File Shares storage.
/// </summary>
/// <seealso cref="Azure.Test.Perf.PerfTest{SizeOptions}" />
public sealed class DownloadFile : PerfTest<SizeOptions>
{
/// <summary>
/// Reference to the Share used by the test in the Microsoft Azure File service.
/// </summary>
private CloudFileShare _cloudFileShare;

/// <summary>
/// Reference to the file used by the test in the Microsoft Azure File service.
/// </summary>
private CloudFile _cloudFile;

/// <summary>
/// Local stream uploaded to Microsoft Azure File service.
/// </summary>
private readonly Stream _stream;

/// <summary>
/// Initializes a new instance of the <see cref="DownloadFile"/> class.
/// </summary>
/// <param name="options">The set of options to consider for configuring the scenario.</param>
public DownloadFile(SizeOptions options) : base(options)
{
_stream = RandomStream.Create(options.Size);
}

public override void Dispose(bool disposing)
{
_stream.Dispose();
base.Dispose(disposing);
}

/// <summary>
/// Creates a cloud file share to be used by the test.
/// Also, creates a file reference in the cloud file share and uploads data stream to the cloud file.
/// </summary>
/// <returns></returns>
public override async Task SetupAsync()
{
await base.SetupAsync();

PerfTestEnvironment testEnvironment = PerfTestEnvironment.Instance;
_cloudFileShare = new CloudFileShare(new Uri($"{testEnvironment.FileShareAddressString}/{Guid.NewGuid()}"), testEnvironment.StorageCredentials);

await _cloudFileShare.CreateAsync();

_cloudFile = _cloudFileShare.GetRootDirectoryReference().GetFileReference(Path.GetRandomFileName());
await _cloudFile.CreateAsync(Options.Size);
await _cloudFile.UploadFromStreamAsync(_stream);
}

/// <summary>
/// Deletes the cloud file share created by the test.
/// </summary>
public override async Task CleanupAsync()
{
await _cloudFileShare.DeleteAsync();
await base.CleanupAsync();
}

/// <summary>
/// Downloads a file from the Microsoft Azure File service by calling <see cref="CloudFile.DownloadToStream(Stream, AccessCondition, FileRequestOptions, OperationContext)"/>.
/// </summary>
/// <param name="cancellationToken">The token used to signal cancellation request.</param>
public override void Run(CancellationToken cancellationToken)
{
_cloudFile.DownloadToStream(Stream.Null);
}

/// <summary>
/// Downloads a file from the Microsoft Azure File service by calling <see cref="CloudFile.DownloadToStreamAsync(Stream, AccessCondition, FileRequestOptions, OperationContext, CancellationToken)"/>.
/// </summary>
/// <param name="cancellationToken">The token used to signal cancellation request.</param>
public override async Task RunAsync(CancellationToken cancellationToken)
{
await _cloudFile.DownloadToStreamAsync(Stream.Null, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Azure.Test.Perf;

namespace Microsoft.Azure.Storage.File.Perf.Scenarios
{
/// <summary>
/// The performance test scenario focused on uploading files to the Microsoft Azure File Shares storage.
/// </summary>
/// <seealso cref="Azure.Test.Perf.PerfTest{SizeOptions}" />
public sealed class UploadFile : PerfTest<SizeOptions>
{
/// <summary>
/// Reference to the Share used by the test in the Microsoft Azure File service.
/// </summary>
private CloudFileShare _cloudFileShare;

/// <summary>
/// Reference to the file used by the test in the Microsoft Azure File service.
/// </summary>
private CloudFile _cloudFile;

/// <summary>
/// Local stream uploaded to Microsoft Azure File service.
/// </summary>
private readonly Stream _stream;

/// <summary>
/// Initializes a new instance of the <see cref="UploadFile"/> class.
/// </summary>
/// <param name="options">The set of options to consider for configuring the scenario.</param>
public UploadFile(SizeOptions options) : base(options)
{
_stream = RandomStream.Create(options.Size);
}

public override void Dispose(bool disposing)
{
_stream.Dispose();
base.Dispose(disposing);
}

/// <summary>
/// Creates a cloud file share to be used by the test.
/// Also, creates a file reference in the cloud file share.
/// </summary>
/// <returns></returns>
public override async Task SetupAsync()
{
await base.SetupAsync();

PerfTestEnvironment testEnvironment = PerfTestEnvironment.Instance;
_cloudFileShare = new CloudFileShare(new Uri($"{testEnvironment.FileShareAddressString}/{Guid.NewGuid()}"), testEnvironment.StorageCredentials);

await _cloudFileShare.CreateAsync();

_cloudFile = _cloudFileShare.GetRootDirectoryReference().GetFileReference(Path.GetRandomFileName());
await _cloudFile.CreateAsync(Options.Size);
}

/// <summary>
/// Deletes the cloud file share created by the test.
/// </summary>
public override async Task CleanupAsync()
{
await _cloudFileShare.DeleteAsync();
await base.CleanupAsync();
}

/// <summary>
/// Downloads a file from the Microsoft Azure File service by calling <see cref="CloudFile.UploadFromStream(Stream, AccessCondition, FileRequestOptions, OperationContext)"/>.
/// </summary>
/// <param name="cancellationToken">The token used to signal cancellation request.</param>
public override void Run(CancellationToken cancellationToken)
{
_stream.Seek(0, SeekOrigin.Begin);

_cloudFile.UploadFromStream(_stream);
}

/// <summary>
/// Downloads a file from the Microsoft Azure File service by calling <see cref="CloudFile.UploadFromStreamAsync(Stream, AccessCondition, FileRequestOptions, OperationContext, CancellationToken)"/>.
/// </summary>
/// <param name="cancellationToken">The token used to signal cancellation request.</param>
public override async Task RunAsync(CancellationToken cancellationToken)
{
_stream.Seek(0, SeekOrigin.Begin);

await _cloudFile.UploadFromStreamAsync(_stream, cancellationToken);
}
}
}
Loading

0 comments on commit 7600467

Please sign in to comment.