Stored Procedure Runs 24,000% slower via SSIS (via SQL Agent job) vs Manual Execution via SSMS

Viewed 1270

I am facing a very weird issue where a stored procedure runs very slowly via SSIS package (run via SQL Agent job) compare to if I run it manually in SSMS.

Via the job, it takes ~2 hours, where manually running it takes only 30 seconds!

Exact same stored procedure and run on the same server.

This is the structure of the flow in the SSIS package:

The SSIS control flow

The stored procedure's name in question is BR_SHP_Timekeeper_Costs.

The Execute SQL Task with the same name uses ADO.NET connection manager and run:

EXEC BR_SHP_Timekeeper_Costs @p1, @p2

As you can see also, this task is "chained" by precedence constraint so that it will run on its own, i.e. won't be contending with other tasks.

What I noticed was that during the execution of the package (via SQL Agent), when it hits that task, I could see lots of CXPACKET wait type in Activity Monitor and CPU is running 97-99%.

FYI, the server has 8 vCPU with MAXDOP is set to 0 and Cost of Parallelism Threshold is set to 5

So far, I have tried / investigated / found out the following:

  1. There is only 1 cached execution plan for this stored procedure and it is used by both the SSIS and SSMS (manually running the stored procedure)

  2. Created a dummy SQL Agent Job running T-SQL - EXEC BR_SHP_Timekeeper_Costs. The job was completed in ~30 seconds.

  3. Created a dummy SSIS package which only contains a Execute SQL Task and runs the same stored procedure using ADO.NET connection manager. Then run it via a new SQL Agent Job. Completed in ~30 seconds.

What else can I check here?

Any ideas why this happens? I've been scratching my head for a week or so..

1 Answers
Related