Skip to content

Commit eabe50c

Browse files
committed
CommandProcessors: Initial queue sizes based on batch size
1 parent 5e56cda commit eabe50c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Orm/Xtensive.Orm/Orm/Providers/CommandProcessing/BatchingCommandProcessor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Xtensive.Orm.Providers
1515
internal sealed class BatchingCommandProcessor : CommandProcessor, ISqlTaskProcessor
1616
{
1717
private readonly int batchSize;
18-
private Queue<SqlTask> tasks = new Queue<SqlTask>();
18+
private Queue<SqlTask> tasks;
1919

2020
void ISqlTaskProcessor.ProcessTask(SqlLoadTask task, CommandProcessorContext context)
2121
{
@@ -290,7 +290,7 @@ private void PutTasksForExecution(CommandProcessorContext context)
290290
}
291291
else {
292292
context.ProcessingTasks = tasks;
293-
tasks = new Queue<SqlTask>();
293+
tasks = new Queue<SqlTask>(batchSize);
294294
}
295295
}
296296

@@ -328,6 +328,7 @@ public BatchingCommandProcessor(CommandFactory factory, int batchSize, int maxQu
328328
{
329329
ArgumentValidator.EnsureArgumentIsGreaterThan(batchSize, 1, nameof(batchSize));
330330
this.batchSize = batchSize;
331+
this.tasks = new Queue<SqlTask>(batchSize);
331332
}
332333
}
333334
}

Orm/Xtensive.Orm/Orm/Providers/CommandProcessing/SimpleCommandProcessor.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ namespace Xtensive.Orm.Providers
1414
{
1515
internal sealed class SimpleCommandProcessor : CommandProcessor, ISqlTaskProcessor
1616
{
17-
private Queue<SqlTask> tasks = new();
17+
// equals to default batch size from SessionConfiguration
18+
// hard to choose particular value so let it be some known number :)
19+
private const int DefaultTaskQueueCapacity = 25;
20+
21+
private Queue<SqlTask> tasks = new(DefaultTaskQueueCapacity);
1822

1923
void ISqlTaskProcessor.ProcessTask(SqlLoadTask task, CommandProcessorContext context)
2024
{
@@ -52,7 +56,7 @@ void ISqlTaskProcessor.ProcessTask(SqlPersistTask task, CommandProcessorContext
5256
public override void ExecuteTasks(CommandProcessorContext context)
5357
{
5458
context.ProcessingTasks = tasks;
55-
tasks = new Queue<SqlTask>();
59+
tasks = new Queue<SqlTask>(DefaultTaskQueueCapacity);
5660

5761
while (context.ProcessingTasks.Count > 0) {
5862
AllocateCommand(context);
@@ -80,7 +84,7 @@ public override void ExecuteTasks(CommandProcessorContext context)
8084
public override async Task ExecuteTasksAsync(CommandProcessorContext context, CancellationToken token)
8185
{
8286
context.ProcessingTasks = tasks;
83-
tasks = new Queue<SqlTask>();
87+
tasks = new Queue<SqlTask>(DefaultTaskQueueCapacity);
8488

8589
while (context.ProcessingTasks.Count > 0) {
8690
AllocateCommand(context);

0 commit comments

Comments
 (0)