Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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