From 6d0e5bdc89b41a77e6a31d29bae9b1ecf18b2a31 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Wed, 11 Jul 2018 11:29:12 -0500 Subject: [PATCH] installed NBench v1.2.0 and am trying to execute it via the runner (#18) * installed NBench v1.2.0 and am trying to execute it via the runner * Added NBench v1.2.1 * Added timeouts to the Azure spec * added expontential backoff for starting Azure table storage journal --- build.fsx | 50 +++++++------------ build.ps1 | 15 ------ .../Akka.Persistence.Azure.TestHelpers.csproj | 2 +- ...Persistence.Azure.Tests.Performance.csproj | 5 +- .../AzureJournalPerfSpecs.cs | 9 ++-- .../Akka.Persistence.Azure.csproj | 8 +-- .../Journal/AzureTableStorageJournal.cs | 45 ++++++++++++----- 7 files changed, 63 insertions(+), 71 deletions(-) diff --git a/build.fsx b/build.fsx index 6b59050..debeb97 100644 --- a/build.fsx +++ b/build.fsx @@ -119,38 +119,26 @@ Target "RunTests" (fun _ -> ) Target "NBench" <| fun _ -> - let nbenchTestPath = findToolInSubPath "NBench.Runner.exe" (toolsDir @@ "NBench.Runner*") - printfn "Using NBench.Runner: %s" nbenchTestPath - - let nbenchTestAssemblies = !! "./src/Akka.Persistence.Azure.Tests.Performance/bin/Release/**/*Tests.Performance.dll" // doesn't support .NET Core at the moment - - let runNBench assembly = - let includes = getBuildParam "include" - let excludes = getBuildParam "exclude" - let teamcityStr = (getBuildParam "teamcity") - let enableTeamCity = - match teamcityStr with - | null -> false - | "" -> false - | _ -> bool.Parse teamcityStr - - let args = StringBuilder() - |> append assembly - |> append (sprintf "output-directory=\"%s\"" outputPerfTests) - |> append (sprintf "concurrent=\"%b\"" true) - |> append (sprintf "trace=\"%b\"" true) - |> append (sprintf "teamcity=\"%b\"" enableTeamCity) - |> appendIfNotNullOrEmpty includes "include=" - |> appendIfNotNullOrEmpty excludes "include=" - |> toText - - let result = ExecProcess(fun info -> - info.FileName <- nbenchTestPath - info.WorkingDirectory <- (Path.GetDirectoryName (FullName nbenchTestPath)) - info.Arguments <- args) (System.TimeSpan.FromMinutes 45.0) (* Reasonably long-running task. *) - if result <> 0 then failwithf "NBench.Runner failed. %s %s" nbenchTestPath args + let projects = + match (isWindows) with + | true -> !! "./src/**/*.Tests.Performance.csproj" + | _ -> !! "./src/**/*.Tests.Performance.csproj" // if you need to filter specs for Linux vs. Windows, do it here + + + let runSingleProject project = + let arguments = + match (hasTeamCity) with + | true -> (sprintf "nbench --nobuild --teamcity --concurrent true --trace true --output %s" (outputPerfTests)) + | false -> (sprintf "nbench --nobuild --concurrent true --trace true --output %s" (outputPerfTests)) + + let result = ExecProcess(fun info -> + info.FileName <- "dotnet" + info.WorkingDirectory <- (Directory.GetParent project).FullName + info.Arguments <- arguments) (TimeSpan.FromMinutes 30.0) + + ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.DontFailBuild result - nbenchTestAssemblies |> Seq.iter runNBench + projects |> Seq.iter runSingleProject //-------------------------------------------------------------------------------- diff --git a/build.ps1 b/build.ps1 index f5a04cd..1d75c51 100644 --- a/build.ps1 +++ b/build.ps1 @@ -30,7 +30,6 @@ Param( ) $FakeVersion = "4.61.2" -$NBenchVersion = "1.0.4" $DotNetChannel = "LTS"; $DotNetVersion = "2.0.0"; $DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/v$DotNetVersion/scripts/obtain/dotnet-install.ps1"; @@ -115,20 +114,6 @@ if (!(Test-Path $FakeExePath)) { } } -########################################################################### -# INSTALL NBench Runner -########################################################################### - -# Make sure NBench Runner has been installed. -$NBenchDllPath = Join-Path $ToolPath "NBench.Runner/lib/net45/NBench.Runner.exe" -if (!(Test-Path $NBenchDllPath)) { - Write-Host "Installing NBench..." - Invoke-Expression "&`"$NugetPath`" install NBench.Runner -ExcludeVersion -Version $NBenchVersion -OutputDirectory `"$ToolPath`"" | Out-Null; - if ($LASTEXITCODE -ne 0) { - Throw "An error occured while restoring NBench.Runner from NuGet." - } -} - ########################################################################### # Docfx ########################################################################### diff --git a/src/Akka.Persistence.Azure.TestHelpers/Akka.Persistence.Azure.TestHelpers.csproj b/src/Akka.Persistence.Azure.TestHelpers/Akka.Persistence.Azure.TestHelpers.csproj index 4ec53a5..95113b8 100644 --- a/src/Akka.Persistence.Azure.TestHelpers/Akka.Persistence.Azure.TestHelpers.csproj +++ b/src/Akka.Persistence.Azure.TestHelpers/Akka.Persistence.Azure.TestHelpers.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netstandard1.6 false diff --git a/src/Akka.Persistence.Azure.Tests.Performance/Akka.Persistence.Azure.Tests.Performance.csproj b/src/Akka.Persistence.Azure.Tests.Performance/Akka.Persistence.Azure.Tests.Performance.csproj index 6d698db..2ae3739 100644 --- a/src/Akka.Persistence.Azure.Tests.Performance/Akka.Persistence.Azure.Tests.Performance.csproj +++ b/src/Akka.Persistence.Azure.Tests.Performance/Akka.Persistence.Azure.Tests.Performance.csproj @@ -3,12 +3,13 @@ - net461 + net461;netcoreapp2.0 - + + diff --git a/src/Akka.Persistence.Azure.Tests.Performance/AzureJournalPerfSpecs.cs b/src/Akka.Persistence.Azure.Tests.Performance/AzureJournalPerfSpecs.cs index 08c738a..e855e6f 100644 --- a/src/Akka.Persistence.Azure.Tests.Performance/AzureJournalPerfSpecs.cs +++ b/src/Akka.Persistence.Azure.Tests.Performance/AzureJournalPerfSpecs.cs @@ -31,6 +31,8 @@ public class AzureJournalPerfSpecs public const int PersistentActorCount = 200; public const int PersistedMessageCount = 20; + public static readonly TimeSpan MaxTimeout = TimeSpan.FromMinutes(6); + public static Config JournalConfig() { if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AZURE_CONNECTION_STR"))) @@ -44,11 +46,12 @@ public static Config JournalConfig(string connectionString) TableName = "PerfTestTable" + TableVersionCounter.IncrementAndGet(); return ConfigurationFactory.ParseString( - @"akka.loglevel = DEBUG + @"akka.loglevel = INFO + akka.persistence.max-concurrent-recoveries = 25 # since Azure seems to have some trouble at 50 akka.persistence.journal.azure-table.class = ""Akka.Persistence.Azure.Journal.AzureTableStorageJournal, Akka.Persistence.Azure"" akka.persistence.journal.plugin = ""akka.persistence.journal.azure-table"" akka.persistence.journal.azure-table.connection-string=""" + connectionString + @""" - akka.persistence.journal.azure-table.verbose-logging = on") + akka.persistence.journal.azure-table.verbose-logging = off") .WithFallback("akka.persistence.journal.azure-table.table-name=" + TableName); } @@ -99,7 +102,7 @@ public void BatchJournalWriteSpec(BenchmarkContext context) for (int i = 0; i < PersistentActorCount; i++) { var task = _persistentActors[i] - .Ask(PersistentBenchmarkMsgs.Finish.Instance); + .Ask(PersistentBenchmarkMsgs.Finish.Instance, MaxTimeout); finished[i] = task; } diff --git a/src/Akka.Persistence.Azure/Akka.Persistence.Azure.csproj b/src/Akka.Persistence.Azure/Akka.Persistence.Azure.csproj index 8eaaf72..4d84f98 100644 --- a/src/Akka.Persistence.Azure/Akka.Persistence.Azure.csproj +++ b/src/Akka.Persistence.Azure/Akka.Persistence.Azure.csproj @@ -3,16 +3,10 @@ - netstandard2.0 + netstandard1.6 Akka.Persistence support for Windows Azure Table storage and Azure blob storage. - - - - - - diff --git a/src/Akka.Persistence.Azure/Journal/AzureTableStorageJournal.cs b/src/Akka.Persistence.Azure/Journal/AzureTableStorageJournal.cs index 6058d58..2d5120c 100644 --- a/src/Akka.Persistence.Azure/Journal/AzureTableStorageJournal.cs +++ b/src/Akka.Persistence.Azure/Journal/AzureTableStorageJournal.cs @@ -43,25 +43,46 @@ public AzureTableStorageJournal() _serialization = new SerializationHelper(Context.System); _storageAccount = CloudStorageAccount.Parse(_settings.ConnectionString); - _tableStorage = new Lazy(() => InitCloudStorage().Result); + _tableStorage = new Lazy(() => InitCloudStorage(5).Result); } public CloudTable Table => _tableStorage.Value; - private async Task InitCloudStorage() + private static readonly Dictionary RetryInterval = new Dictionary() { - var tableClient = _storageAccount.CreateCloudTableClient(); - var tableRef = tableClient.GetTableReference(_settings.TableName); - var op = new OperationContext(); - using (var cts = new CancellationTokenSource(_settings.ConnectTimeout)) + { 5, TimeSpan.FromMilliseconds(100) }, + { 4, TimeSpan.FromMilliseconds(500) }, + { 3, TimeSpan.FromMilliseconds(1000) }, + { 2, TimeSpan.FromMilliseconds(2000) }, + { 1, TimeSpan.FromMilliseconds(4000) }, + { 0, TimeSpan.FromMilliseconds(8000) }, + }; + + private async Task InitCloudStorage(int remainingTries) + { + try { - if (await tableRef.CreateIfNotExistsAsync(new TableRequestOptions(), op, cts.Token)) - _log.Info("Created Azure Cloud Table", _settings.TableName); - else - _log.Info("Successfully connected to existing table", _settings.TableName); - } + var tableClient = _storageAccount.CreateCloudTableClient(); + var tableRef = tableClient.GetTableReference(_settings.TableName); + var op = new OperationContext(); + using (var cts = new CancellationTokenSource(_settings.ConnectTimeout)) + { + if (await tableRef.CreateIfNotExistsAsync(new TableRequestOptions(), op, cts.Token)) + _log.Info("Created Azure Cloud Table", _settings.TableName); + else + _log.Info("Successfully connected to existing table", _settings.TableName); + } - return tableRef; + return tableRef; + } + catch (Exception ex) + { + _log.Error(ex, "[{0}] more tries to initialize table storage remaining...", remainingTries); + if (remainingTries == 0) + throw; + await Task.Delay(RetryInterval[remainingTries]); + return await InitCloudStorage(remainingTries - 1); + } } protected override void PreStart()