I wrote a program modeled after the accepted answer for Throttling asynchronous tasks. See code below. My program is essentially an ad-hoc DB "text search" tool. It runs on a Win 7 client machine. The program composes a large collection of SELECT
statements (hundreds to thousands of them) and sends them to a remote DB server (The Win 7 client and the DB server are on the same A.D. domain. The DB server searched is only ever the read-only
secondary
server in an Always On Availability Group
). Each invocation of the Download
method creates 1-to-many SELECT
queries (one SELECT per table column being searched) for one DB table. The Download
method is invoked 1-to-thousands of times (once per table being searched).
TPL Dataflow
works good so long as I limit the search to no more that 60-70 tables. More than that and it chokes (I think) the SQL Server Database
and/or the DB server machine. I've played with various MaxDegreeOfParallelism
and BoundedCapacity
values in attempt to control the client. With MaxDegreeOfParallelism = 8
(the number of processors on my client machine, I can see that CPU and DISK peg on the DB server machine. With MaxDegreeOfParallelism = 1
and BoundedCapacity = 1
, The CPU and DISK are ok on the DB server machine, but in the act of submitting the queries, my database read code:
SqlDataReader sqlDataReader = await sqlCommand.ExecuteReaderAsync();
dataTable_TableDataFromFieldQuery.Load(sqlDataReader);
eventually throws an exception "server has become unresponsive"
What tools can I use on the DB server to identify the choke point? Even assuming that I need to improves my queries, what do I look for and where?
Code from the other S.O. question modified for my use
var downloader = new TransformBlock<string, DataTable>(tableName => Download(tableName), new ExecutionDataflowBlockOptions {MaxDegreeOfParallelism={various values 1-5, BoundedCapacity={various values 1-5} } );
var buffer = new BufferBlock<DataTable>();
downloader.LinkTo(buffer);
foreach(var tableName in tableNames)
await downloader.SendAsync(tableName);
downloader.Complete();
await downloader.Completion;
IList<DataTable> responses;
if (buffer.TryReceiveAll(out responses))
{
//process all DataTables
}