I have a PLINQ query as such...
batch
.AsParallel()
.WithExecutionMode(ParallelExecutionMode.ForceParallelism)
.WithCancellation(cancellationToken);
.Select(i => new { instruction = i, accountKey = new AccountKey(i.x, i.y, i.z) })
.GroupBy(x => x.accountKey)
.ForAll(grouping =>
{
foreach (var instructionBatch in grouping.OrderBy(i => i.instruction.FileRow).Select(i => i.instruction))
{
// High CPU method.
}
});
In a batch, there can be 10,000 records. These make calls to the High CPU method which in turn is making calls out to web-services and saving info to databases.
On my physical 64bit pc i7-4770 CPU @ 3.40 GHz 16.0GB ram. The service where this code is run from fires up around 32 threads and sits around 150,000 - 200,000 KB memory usage.
On a Hyper-V test environment which is a 64 bit virtual machine E5-2630 v3 @2.40GHz it generates over 200 threads and memory hits nearly the 2gb limit.
Is there any reason why it is firing up so many threads and why memory is not being released on the virtual machine?
Do I need to use WithDegreeOfParallelism. If this process might be called simultaneously with 4 different batches (1 x 1 record, 1 x 100 records, 1 x 1000 and 1 x 10,000 for example) does this mean that when if I specify a WithDegreeOfParallelism the 4 batches will each fire with that number of threads, even the batch of 1 record?
Thanks for any assistance.