Skip to content

Commit

Permalink
Support for tweaking concurrency parameters to not overwhelm low RU c…
Browse files Browse the repository at this point in the history
…ontainers
  • Loading branch information
onionhammer committed Dec 4, 2020
1 parent 38f6da1 commit 99f47aa
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 15 deletions.
31 changes: 30 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
},
]
}
5 changes: 2 additions & 3 deletions DbCopier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -211,7 +210,7 @@ async Task CopyDataPipeline(ChannelWriter<CopyDiagnostic> channel)

var buffer = new BufferBlock<ContainerProperties>(new ()
{
BoundedCapacity = options.MaxContainerBufferSize,
BoundedCapacity = Math.Max(options.MaxContainerBufferSize, options.MaxContainerParallel),
CancellationToken = cancellationToken
});

Expand Down Expand Up @@ -284,7 +283,7 @@ Func<ContainerProperties, Task> CopyContainerFactory(ChannelWriter<CopyDiagnosti
var buffer = new BufferBlock<Document>(new ()
{
BoundedCapacity = options.MaxDocCopyBufferSize,
BoundedCapacity = Math.Max(options.MaxDocCopyBufferSize, options.MaxDocCopyParallel),
CancellationToken = cancellationToken
});
Expand Down
21 changes: 19 additions & 2 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@

new Option(
new [] { "-m", "--minimal" }, "Output minimal information"
),

new Option<int?>(
new [] { "--pc", "--parallel-containers" }, "Parallel container copies"
),

new Option<int?>(
new [] { "--pd", "--parallel-documents" }, "Parallel document copies"
)
};

Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ Command line
```
Options:
-s, --source <source> Source connection string (required)
--sd, --source-database <source-database> Source database name (required)
-d, --destination <destination> Destination connection string
--sd, --source-database <source-database> Source database name (required)
-d, --destination <destination> Destination connection string
--dd, --destination-database <destination-database> Destination database name
-m, --minimal Output minimal information
--parallel-containers, --pc <parallel-containers> Parallel container copies
--parallel-documents, --pd <parallel-documents> 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
4 changes: 2 additions & 2 deletions Wivuu.AzCosmosCopy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
<ToolCommandName>AzCosmosCopy</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>

<VersionPrefix>0.0.4</VersionPrefix>
<VersionPrefix>1.0.0</VersionPrefix>
<Authors>Erik O'Leary</Authors>
<Company>Wivuu</Company>
<Product>Wivuu AzCosmosCopy</Product>
<Description>Copy cosmos db databases.</Description>
<ReleaseNotes>
- Handle errors and cancellation in tui
- Support for tweaking concurrency parameters to not overwhelm low RU containers
</ReleaseNotes>
<PackageTags>cosmos;cosmosdb;azure;copy</PackageTags>
<PackageProjectUrl>https://github.com/wivuu/Wivuu.AzCosmosCopy</PackageProjectUrl>
Expand Down

0 comments on commit 99f47aa

Please sign in to comment.