on 06-04-2015 9:09 AM
Greetings!
In our batch scheduler, we call the same stored procedure (let's call it "my_proc") twice.
batch job 1a: execute my_proc("dinosaurs")
batch job 1b: execute my_proc("humans")
Now I list it as 1a and 1b because they can run in any sequence (normally 1a always runs first, followed by 1b 2 minutes later in reality).
My problem:
When 1a runs first, followed by 1b, the result is:
1) "dinosaurs" ends up dealing with about 30k records and runs in about 6 seconds
2) "humans" ends up dealing with about 180k records and runs in about 20 minutes
It's been this way for a long time, so we tried a couple things to improve the situation to confusing results:
Experiment 1) Recompiled the stored procedure and then executed batch job 1b, so that it'd store the query plan for this first run and it finished in about 35 seconds, which is a vast improvement from 20 minutes. Next, batch job 1a ran that night in its normal 6 seconds. About 24 hours later, we let the batch run on its own so 1a runs first in 6 seconds, but 1b runs in its normal 20 minutes again!
Experiment 2) Force job 1b to always run first, followed by 1a. This resulted in job 1b always running in 35 seconds, followed by 1a running in 6 seconds!
Question
Now one solution we have is to force a dependency so that 1a depends on 1b before execution, however we'd like to decouple these jobs as they really shouldn't depend on each other from a data perspective. Does anyone know what the problem is and what the possible solutions may be?
One theory I have is that the procedure cache is coming into play here, but, if that is the case, I don't know how to fix this unless I create a new stored procedure maybe with the same name? (Before you ask me to try this, we can't replicate this in a test environment as they always run fast with the same data set for some reason, trying various combination of execution sequences. Production is where we are experiencing this performance issue.)
Thank you in advance!
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.