From 99f47aa65e024d538d00741905b8da8f489ce5e2 Mon Sep 17 00:00:00 2001 From: Erik OLeary Date: Fri, 4 Dec 2020 15:53:36 -0600 Subject: [PATCH] Support for tweaking concurrency parameters to not overwhelm low RU containers --- .vscode/launch.json | 31 ++++++++++++++++++++++++++++++- DbCopier.cs | 5 ++--- Program.cs | 21 +++++++++++++++++++-- README.md | 12 +++++------- Wivuu.AzCosmosCopy.csproj | 4 ++-- 5 files changed, 58 insertions(+), 15 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1ca6583..cbdbb19 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,14 @@ "request": "launch", "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/net5.0/AzCosmosCopy.dll", - "args": [], + "args": [ + "-s", "${input:source}", + "--sd", "${input:sourcedb}", + "-d", "${input:dest} ", + "--dd", "${input:destdb}", + "--pc", "1", + "--pd", "5" + ], "cwd": "${workspaceFolder}", "console": "internalConsole", "stopAtEntry": false @@ -21,5 +28,27 @@ "request": "attach", "processId": "${command:pickProcess}" } + ], + "inputs": [ + { + "id": "source", + "description": "Source account connection string", + "type": "promptString" + }, + { + "id": "sourcedb", + "description": "Source account database", + "type": "promptString" + }, + { + "id": "dest", + "description": "Destination account connection string", + "type": "promptString" + }, + { + "id": "destdb", + "description": "Destination account database", + "type": "promptString" + }, ] } \ No newline at end of file diff --git a/DbCopier.cs b/DbCopier.cs index 3e5d3d3..c4077ba 100644 --- a/DbCopier.cs +++ b/DbCopier.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization; @@ -211,7 +210,7 @@ async Task CopyDataPipeline(ChannelWriter channel) var buffer = new BufferBlock(new () { - BoundedCapacity = options.MaxContainerBufferSize, + BoundedCapacity = Math.Max(options.MaxContainerBufferSize, options.MaxContainerParallel), CancellationToken = cancellationToken }); @@ -284,7 +283,7 @@ Func CopyContainerFactory(ChannelWriter(new () { - BoundedCapacity = options.MaxDocCopyBufferSize, + BoundedCapacity = Math.Max(options.MaxDocCopyBufferSize, options.MaxDocCopyParallel), CancellationToken = cancellationToken }); diff --git a/Program.cs b/Program.cs index 38a5085..20e0013 100644 --- a/Program.cs +++ b/Program.cs @@ -24,6 +24,14 @@ new Option( new [] { "-m", "--minimal" }, "Output minimal information" + ), + + new Option( + new [] { "--pc", "--parallel-containers" }, "Parallel container copies" + ), + + new Option( + new [] { "--pd", "--parallel-documents" }, "Parallel document copies" ) }; @@ -57,14 +65,21 @@ }; var sourceClient = new CosmosClient(args.Source, dbOptions); - var destClient = new CosmosClient(args.Destination ?? args.Source, dbOptions); + + var destClient = new CosmosClient( + string.IsNullOrWhiteSpace(args.Destination) ? args.Source : args.Destination, + dbOptions); var copyOptions = new DbCopierOptions( sourceClient, destClient, args.SourceDatabase, args.DestinationDatabase ?? args.SourceDatabase - ); + ) + { + MaxContainerParallel = args.ParallelContainers, + MaxDocCopyParallel = args.ParallelDocuments, + }; var result = args.Minimal ? await DbCopier.CopyMinimal(copyOptions, cancellation.Token) @@ -89,4 +104,6 @@ class Args public string? Destination { get; init; } public string? DestinationDatabase { get; init; } public bool Minimal { get; set; } + public int ParallelContainers { get; set; } = 10; + public int ParallelDocuments { get; set; } = 100; } \ No newline at end of file diff --git a/README.md b/README.md index 0167830..7a07f2d 100644 --- a/README.md +++ b/README.md @@ -23,14 +23,12 @@ Command line ``` Options: -s, --source Source connection string (required) - --sd, --source-database Source database name (required) - -d, --destination Destination connection string + --sd, --source-database Source database name (required) + -d, --destination Destination connection string --dd, --destination-database Destination database name -m, --minimal Output minimal information + --parallel-containers, --pc Parallel container copies + --parallel-documents, --pd Parallel document copies --version Show version information - -?, -h, --help Show help and usage information + -?, -h, --help Show help and usage information ``` - - -## Coming soon -- Support for tweaking concurrency parameters to not overwhelm low RU containers \ No newline at end of file diff --git a/Wivuu.AzCosmosCopy.csproj b/Wivuu.AzCosmosCopy.csproj index 059a3b0..2dc7dba 100644 --- a/Wivuu.AzCosmosCopy.csproj +++ b/Wivuu.AzCosmosCopy.csproj @@ -12,13 +12,13 @@ AzCosmosCopy ./nupkg - 0.0.4 + 1.0.0 Erik O'Leary Wivuu Wivuu AzCosmosCopy Copy cosmos db databases. - - Handle errors and cancellation in tui + - Support for tweaking concurrency parameters to not overwhelm low RU containers cosmos;cosmosdb;azure;copy https://github.com/wivuu/Wivuu.AzCosmosCopy