|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Saturday, May 04, 2013 11:13 AM
Points: 9,855,
Visits: 9,374
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, February 07, 2013 11:06 AM
Points: 13,
Visits: 270
|
|
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 ......
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Wednesday, March 06, 2013 12:56 AM
Points: 898,
Visits: 1,045
|
|
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
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Wednesday, March 06, 2013 12:56 AM
Points: 898,
Visits: 1,045
|
|
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
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, February 07, 2013 11:06 AM
Points: 13,
Visits: 270
|
|
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.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, March 25, 2011 3:26 PM
Points: 22,
Visits: 80
|
|
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
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, February 07, 2013 11:06 AM
Points: 13,
Visits: 270
|
|
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.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, March 25, 2011 3:26 PM
Points: 22,
Visits: 80
|
|
| 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.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, February 07, 2013 11:06 AM
Points: 13,
Visits: 270
|
|
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.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 6:48 AM
Points: 1,065,
Visits: 1,328
|
|
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
|
|
|
|