Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««1234»»»

Execute T-SQL Scripts in Parallel Expand / Collapse
Author
Message
Posted Tuesday, September 1, 2009 3:39 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Thursday, June 5, 2014 10:54 AM
Points: 9,902, Visits: 9,480
RBarryYoung (8/31/2009)
Where is sp_exec_init documented?


Still waiting for an answer ... ?


-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #781127
Posted Tuesday, September 1, 2009 3:57 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, May 20, 2014 2:29 PM
Points: 16, Visits: 280
RBarryYoung (9/1/2009)
RBarryYoung (8/31/2009)
Where is sp_exec_init documented?


Still waiting for an answer ... ?


Sorry, I haven't written a lot document yet. Do you only want to know how to call it? It's like:

EXEC dbo.sp_exec_init [@worker_num=4]

The @worker_num means how many worker processes you want to run your sql's. It's optional argument.

Indeed that's the wrapper of this stored procedure in the pmaster database. The code is not long or fancy, I think you guys can figure it out. Forgive me this time since my work load is heavy at present.

CREATE procedure [dbo].[p_exec_init]
@worker_num smallint = 4
as
......




Post #781134
Posted Friday, March 19, 2010 8:14 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 7:24 AM
Points: 928, Visits: 1,114
Excellent piece of code! I implemented it to speed-up some Datawarehouse processing routines. Processing time dropped from 500 minutes to 70 minutes!


Wilfred
The best things in life are the simple things
Post #886398
Posted Wednesday, March 24, 2010 4:44 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 7:24 AM
Points: 928, Visits: 1,114
Nested tasks not possible?
Situation: from a main routine, I execute a subroutine with sp_exec. inside this subroutine, some calculations are done (a generated SQL statment). If I execute this SQL statement with sp_exec it seems it's not executed at all. no error message either. Can't find the reason. (SQLStatement is ok, checked)

exec mainroutine
-- in loop: sp_exec subroutine
-- in loop: sp_exec sql statement

Question: can you add another process from within a parallel process?


Wilfred
The best things in life are the simple things
Post #888805
Posted Wednesday, March 24, 2010 4:33 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, May 20, 2014 2:29 PM
Points: 16, Visits: 280
If you simply sp_exec in loops, notice still they (many worker spids) are all controlled by current master SPID and in theory they will all run in the same parallel scope. However, you can use sp_exec_wait to control the running sequence between sql groups. Like the following pseudo code:

sp_exec_init

loop begin
sp_exec '...'
sp_exec '...'

loop begin
sp_exec '...'
loop end
sp_exec_wait

sp_exec '...'
sp_exec '...'

loop end

sp_exec_end


If you really want to start other parallel scopes within current parallel process, the following pseudo code shows the trick. You can launch a worker spid to run the sp_exec script.

--This is in current master process
sp_exec_init

--This will launch a worker process who will master a bunch of worker spids
sp_exec '
sp_exec_init
sp_exec ''...''
sp_exec ''...''
sp_exec_wait
sp_exec_end
'

--This will launch another worker process who will master a bunch of worker spids
sp_exec '
sp_exec_init
sp_exec ''...''
sp_exec ''...''
sp_exec_wait
sp_exec_end
'
sp_exec_wait
sp_exec_end


Anytime you can look at pmaster.dbo.exec_queue table to debug the running of your script.



Post #889408
Posted Friday, May 7, 2010 12:20 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, July 24, 2014 11:51 AM
Points: 23, Visits: 103
I like the tool, however is there anyway to have it return rows? I have a need to execute multiple sprocs in parallel but these procs return result sets for a report.

Thanks for your time,
Robb
Post #918268
Posted Friday, May 7, 2010 3:09 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, May 20, 2014 2:29 PM
Points: 16, Visits: 280
Robb Melancon (5/7/2010)
I like the tool, however is there anyway to have it return rows? I have a need to execute multiple sprocs in parallel but these procs return result sets for a report.

Thanks for your time,
Robb



The method I've been using is to create a table in tempdb (don't use those like #tmp but use a real table like tempdb.dbo.tmp_result), and let all the parallel runing scripts insert into the table. Then you can collect combined results after all sprocs return.



Post #918374
Posted Monday, May 10, 2010 8:26 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, July 24, 2014 11:51 AM
Points: 23, Visits: 103
Thanks for the reply. The only problem with using temps is that they would need to be global or declared directly in temp database like you said. This is fine for single user but when you have multiple users running reports I'd need to create a guid per each run of the report and filter on the guid. There will be other problem potentially with this like locking for inserts while some other user is running a report etc. It may be the only solution though. Another thing I thought would be passing the table as a parameter but this may have some performance issues. Anyway, thanks again for the reply.
Post #919049
Posted Monday, May 10, 2010 1:04 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, May 20, 2014 2:29 PM
Points: 16, Visits: 280
Robb Melancon (5/10/2010)
Thanks for the reply. The only problem with using temps is that they would need to be global or declared directly in temp database like you said. This is fine for single user but when you have multiple users running reports I'd need to create a guid per each run of the report and filter on the guid. There will be other problem potentially with this like locking for inserts while some other user is running a report etc. It may be the only solution though. Another thing I thought would be passing the table as a parameter but this may have some performance issues. Anyway, thanks again for the reply.


In that case, perhaps you can create seperate temp tables for each users instead of filtering on a guid column, like:

tmp_5B12952D614E497A93F7EA670B279A75
tmp_5C0EDDEFE61740EDAB5A0DDBC67088F0


I think that won't require filtering on guid and won't have locking issues. Only need to optimize tempdb a bit or even creating a user database as the temp db.



Post #919261
Posted Thursday, June 17, 2010 4:06 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, July 24, 2014 3:58 AM
Points: 1,270, Visits: 1,540
Wilfred van Dijk (3/19/2010)
Excellent piece of code! I implemented it to speed-up some Datawarehouse processing routines. Processing time dropped from 500 minutes to 70 minutes!


I am intrigued how you achieved this, can you please give a brief example...

After some subtle changes in our ETL processes I can now see how!


_____________________________________________________________________________________
gsc_dba
Post #938755
« Prev Topic | Next Topic »

Add to briefcase ««1234»»»

Permissions Expand / Collapse