简体   繁体   中英

Running multiple instances of a program to speed up process?

I have a program that performs a long running process. Loops through thousands of records, one at a time, and calls a stored proc each iteration. Would running two instances of a program like this with one processing half the records and the other processing the other half speed up the processing?

Here are the scenarios:

  1. 1 program, running long running process
  2. 2 instances of program on same server, connecting to same database, each responsible for processing half (50%) of the records.
  3. 2 instance on different server, connecting to the same database, each responsible for half (50%) of the records.

Would scenario 2 or 3 run twice as fast as 1? Would there be a difference between 2 and 3? The main bottleneck is the stored proc call that takes around half a second.

Thanks!

This depends on a lot of factors. Also note that threads may be more appropriate than processes. Or maybe not. Again: it depends. But: is this work CPU-bound? Network-bound? Or bound by what the database server can do? Adding concurrency helps with CPU-bound, and when talking to multiple independent resources. Fighting over the same network connection or the same database server is unlikely to improve things - and can make things much worse.

Frankly, from the sound of it your best bet may be to re-work the sproc to work in batches (rather than individual records).

To answer this question properly you need to know what the resource utilization of the database server currently us: can it take extra load? Or simpler - just try it and see .

It really depends what the stored procedure is doing. If the stored procedure is going to be updating the records, and you have a single database instance then there is going to be contention when writing the data back.

The values at play here, are:

  1. The time it takes to read the data in to your application memory (and this is also dependent on whether you are using client-side or sql-server-side cursors).
  2. The time it takes to process, or do your application logic.
  3. The time it takes to write an updated item back (assuming the proc updates).

One solution (and this is by no means a perfect solution without knowing the exact requirements), is:

  1. Have X servers read Y records, and process them.
  2. Have those servers write the results back to a dedicated writing server in a serialized fashion to avoid the contention.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM