Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3397962
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:35:31+00:00 2026-05-18T04:35:31+00:00

I want to get the community’s perspective on this. If I have a process

  • 0

I want to get the community’s perspective on this. If I have a process which is heavily DB/IO bound, how smart would it be to parallelize individual process paths using the Task Parallel library?

I’ll use an example … if I have a bunch of items, and I need to do the following operations

  1. Query a DB for a list of items
  2. Do some aggregation operations to group certain items based on a dynamic list of parameters.
  3. For each grouped result, Query the database for something based on the aggregated result.
  4. For each grouped result, Do some numeric calculations (3 and 4 would happen sequentially).
  5. Do some inserts and updates for the result calculated in #3
  6. Do some inserts and updates for each item returned in #1

Logically speaking, I can parallelize into a graph of tasks at steps #3, #5, #6 as one item has no bearing on the result of the previous. However, each of these will be waiting on the database (sql server) which is fine and I understand that we can only process as far as the SQL server will let us.

But I want to logically distribute the task on the local machine so that it processes as fast as the Database lets us without having to wait for anything on our end. I’ve done some mock prototype where I substitute the db calls with Thread.Sleeps (I also tried some variations with .SpinWait, which was a million times faster), and the parallel version is waaaaay faster than the current implementation which is completely serial and not parallel at all.

What I’m afraid of is putting too much strain on the SQL server … are there any considerations I should consider before I go too far down this path?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:35:31+00:00Added an answer on May 18, 2026 at 4:35 am

    Another option would be to create a pipeline so that step 3 for the second group happening at the same time as step 4 for the first group. And if you can overlap the updates at step 5, do that too. That way you’re doing concurrent SQL accesses and processing, but not over-taxing the database because you only have two concurrent operations going on at once.

    So you do steps 1 and 2 sequentially (I presume) to get a collection of groups that require further processing. Then. your main thread starts:

    for each group
      query the database
      place the results of the query into the calc queue
    

    A second thread services the results queue:

    while not end of data
      Dequeue result from calc queue
      Do numeric calculations
      place the results of the query into the update queue
    

    A third thread services the update queue:

    while not end of data
      Dequeue result from update queue
      Update database
    

    The System.Collections.Concurrent.BlockingCollection<T> is a very effective queue for this kind of thing.

    The nice thing here is that if you can scale it if you want by adding multiple calculation threads or query/update threads if the SQL Server can handle more concurrent transactions.

    I use something very similar to this in a daily merge/update program, with very good results. That particular process doesn’t use SQL server, but rather standard file I/O, but the concepts translate very well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two quick questions which I just want to get the community's opinions
Basically I want get data I already have accessed from javascript and passing it
I want to get 100 and example from this string ?connect:100/username:example/ I searched in
Basically, I just want to be able to get the parameter community_name, can this
I'm using Intellij IDEA 10.5 Community. If I have a long String and want
User has_one UserProfile which has_one Community. Given a community_id, I want a list of
http://ds.arm.com/ds-5-community-edition/ I have a 64 bit installation of Ubuntu 12.04 Precise Pangolin, i want
I want to build an dashboard for which back end will be Pentaho community
New to this community... I have to say I love this resource though, it's
I've thought of a few ways of doing this but I want to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.