Last active
December 4, 2020 09:13
-
-
Save OksanaH/42a1fa831ca73465e1a4d4d7e053dfac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void CopyFast() | |
{ | |
Stopwatch sw = new Stopwatch(); | |
sw.Start(); | |
Task[] tasks = new Task[totalSegments]; | |
for (int segment = 0; segment < totalSegments; segment++) | |
{ | |
int tmpSegment = segment; | |
tasks[segment] = Task.Run(() => ScanSegment(tmpSegment)); | |
} | |
Task.WaitAll(tasks); | |
sw.Stop(); | |
Console.WriteLine($"Copy fast - {sw.ElapsedMilliseconds} milliseconds elapsed"); | |
Console.ReadLine(); | |
} | |
private static async Task ScanSegment(int tmpSegment) | |
{ | |
var request = new ScanRequest | |
{ | |
TableName = sourceTableName, | |
Segment = tmpSegment, | |
TotalSegments = totalSegments, | |
}; | |
var result = await client.ScanAsync(request); | |
for (var i = 0; i < result.Items.Count; i += 25) | |
{ | |
var items = result.Items.Skip(i).Take(25).ToArray(); | |
var req = new BatchWriteItemRequest | |
{ | |
RequestItems = new Dictionary<string, List<WriteRequest>> | |
{ | |
{ | |
destinationTableNameFast, | |
items.Select(i => new WriteRequest(new PutRequest(i))).ToList() | |
} | |
} | |
}; | |
await client.BatchWriteItemAsync(req); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment