Anyone had any experience doing async DB queries?
Generically, what I need to do is the following:
-
Execute a synchronous call to a stored proc that returns an int ID
-
Execute one or more less time-critical and generally less resource-intensive calls to other SPs that take that Id as input. These can / should run asynchronously, they are basically “upsert” operations that can be fire-and-forget so far as the caller is concerned, although, any errors should be logged.
Basically a name/address is created in step 1 and step 2 associates optional phone #s, email addresses and other components to that name/address combo.
I am using .NET with Sql Server but I’m more interested in the practical problems you’ve encountered in these kinds of applications than in the specific details of a solution. I will have to decide between async / await syntax and more of a Task.Run(delegate) or parallel approach (time slicing vs true independent threads).
In the past this has worked okay with everything synchronous but I’m looking for opportunities to improve overall throughput and these operations seem like a good opportunities. We are talking processing maybe 200 entities per second so I worry about enough of a work backlog developing that some sort of wall will be hit where the thread pool is full. That’s fine if it degrades gracefully to synchronous throughput until it can catch up. It is not so great if everything tanks and the whole parade stops.
Historically I have tended to really follow the KISS principle with this kind of thing, to the point of having other command line or Windows service processes that I can feed work to via a queue table, vaguely similar to Xojo’s approach to “multi-threading”, for such things. But it is time for me to fully explore my options here.
Any thoughts / experiences anyone has to share as to a general architectural approach / rules of thumb / antipatterns would be much appreciated.