Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 11th, 2006, 04:17 PM
bhushanm bhushanm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 32 bhushanm User rank is Private First Class (20 - 50 Reputation Level)bhushanm User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 2 m 6 sec
Reputation Power: 3
Question Calling two SPs at once....

Hi,

I have been assigned this Performance tuning project. It consists of a single SP being called that processes data by calling other SPs from within itself, one after the other. There are 20 such SPs being called. On studying the code, i found that some SPs are independant of each other, i.e., they do not depend on the other's output parameters for their processing. Therefore there is no need to wait for one SP to finish before calling the other.

Is there any way in oracle to call such SPs simultaneously, rather than seraily??

Reply With Quote
  #2  
Old August 11th, 2006, 04:56 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 6 h 19 m 24 sec
Reputation Power: 48
As close as it gets might be to create asynchronous transactions.

Otherwise, after asking around, I'd say "No".

Reply With Quote
  #3  
Old August 11th, 2006, 05:25 PM
shammat shammat is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2003
Location: Munich, Bavaria
Posts: 1,045 shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 8 h 24 m 6 sec
Reputation Power: 68
Why don't you simply take those that can run independently out of the "main" procedure and schedule them at their own?

Reply With Quote
  #4  
Old August 11th, 2006, 05:27 PM
bhushanm bhushanm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 32 bhushanm User rank is Private First Class (20 - 50 Reputation Level)bhushanm User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 2 m 6 sec
Reputation Power: 3
Quote:
Originally Posted by jim mcnamara
As close as it gets might be to create asynchronous transactions.

Otherwise, after asking around, I'd say "No".


Thanks for the reply. Can u please guide me to a site that has more information regarding asynchronous transactions, possibly with examples.

Reply With Quote
  #5  
Old August 11th, 2006, 05:28 PM
bhushanm bhushanm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 32 bhushanm User rank is Private First Class (20 - 50 Reputation Level)bhushanm User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 2 m 6 sec
Reputation Power: 3
Quote:
Originally Posted by shammat
Why don't you simply take those that can run independently out of the "main" procedure and schedule them at their own?


They depend on the parent procedure for their input params but not on one another.

Reply With Quote
  #6  
Old August 12th, 2006, 02:28 AM
shammat shammat is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2003
Location: Munich, Bavaria
Posts: 1,045 shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 8 h 24 m 6 sec
Reputation Power: 68
Quote:
Originally Posted by bhushanm
They depend on the parent procedure for their input params but not on one another.
How many input params are we talking about? How difficult is it to get those params? If it's not too many and not too difficult then, you could simply feed those to a second (,third, fourth, ...) procedure.

Reply With Quote
  #7  
Old August 13th, 2006, 01:02 PM
bhushanm bhushanm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 32 bhushanm User rank is Private First Class (20 - 50 Reputation Level)bhushanm User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 2 m 6 sec
Reputation Power: 3
how do you multithread in ORACLE

Quote:
Originally Posted by shammat
How many input params are we talking about? How difficult is it to get those params? If it's not too many and not too difficult then, you could simply feed those to a second (,third, fourth, ...) procedure.


I wanna rephrase the question. The details are the same, but the question is :

How do i multithread an ORACLE SP? Is there any way to multithread in ORACLE?

Reply With Quote
  #8  
Old August 15th, 2006, 12:17 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 6 h 19 m 24 sec
Reputation Power: 48
Do you know tkprof?

Instead of trying to thread a needle with a camel, have you run extensive profiling?
I can usually cut as much as 90% off Oracle run-time by creating good queries on indexed columns, adding indexes, or using hints like:
/*+ parallel */ for massive queries on multi-cpu boxes.

/*+ parallel */ "multithreads" a single operation that returns a lot of rows, for example.

Actual multithreading has to be done at a different level than from inside Oracle. You will have to rewrite PL/SQL into Proc*C and call pthreads (if you're on unix). You can do it in Windows as well with Pro*C and the Windows API.

If you really want to keep it in Oracle, then write the C code, then put it into a library, and then call the Pro*C procedure from within Oracle. Your DBA will have to set up a listener, and you'll have to do a lot of re-coding. Hence my profiling comment.

Reply With Quote
  #9  
Old August 15th, 2006, 04:26 PM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 693 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 1 h 1 m 30 sec
Reputation Power: 20
I have another thought:

Don't know if you've used the job queue (dbms_job) but you could have multiple job threads running and then submit each procedure as a job. Then your wrapper program would have to poll the job queue to see when all were finished.

Bit of a hack but probably easier than going the pro C route.

Reply With Quote
  #10  
Old August 15th, 2006, 06:24 PM
bhushanm bhushanm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 32 bhushanm User rank is Private First Class (20 - 50 Reputation Level)bhushanm User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 2 m 6 sec
Reputation Power: 3
Thanks guys for your comments...

I am a rookie at this entire performance tuning scenario. I am learning as i go along.

I am currently exploring the possibilities Jim mentioned. I am running dbms_stat to gather statistics for the tables and indexed columns, etc., to give the CBO the data it requires. Have noticed in a few cases that the explain plan has changed to fast full scan of index rather than a full table scan after the sttistics were gathered.

I am sure that this will result in performance gain. This is however, a maintenance kind of thing and will be an ongoing affair.

However, i do need to find a way to make many function calls at once. I have done some reading on <b>dbms_job</b>, and would appreciate if someone pointed me to a site where i can get some working examples of the same.

Some doubts i guess i can ask right here:

1) The oracle documentation says that a job is broken (after 16 retries) if oracle finds an exception. If i handle the exception to return an error value, will that do? (Probably yes, but just wanted to confirm)

2) How will i convey to the parent procedure that the job completed successfully? I read that one can use dbms_pipe to do that but i am not sure how to implement it. Please please point me to a resource regarding this, or any other method.

3) Can i inform the different error states to the parent procedure?

ex:

select ...;
EXCEPTION
WHEN no data found THEN
return 77; (failure)
When too many rows THEN
return 88; (failure)
WHEN OTHERS THEN
return 99; (failure)

return 0; (success)

Thanks for all your help guys...

Reply With Quote
  #11  
Old August 16th, 2006, 10:05 AM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 6 h 19 m 24 sec
Reputation Power: 48
dbms_job is like a queue manager - cron or Windows scheduler.
You can use it to "multiplex" jobs if you need it, but if the process over all is not a batch kind of thing it may be more problem than it's worth.

After you finish analyzing tables, you really should
Code:
alter session set sql_trace true;
@myplsql

Then run tkprof against the trace file. Save the report.

Next go to ask tom and search on how to use tkprof. He has a lot of information on interpreting tkprof output.
http://asktom.oracle.com/pls/ask/f?p=4950:1::RESET::1
And while you are there download SQL developer, which does a lot of this stuff for you.
If you have an Oracle license it's free.

My experience is that almost always somebody has constructed a query or two that is
a complete bottleneck.

Yes, return <error value> will work. You may want to learn about RAISE in pl/sql for user-defined errors. If there are user defined conditions that are errors, this is may be a better approach.

Reply With Quote
  #12  
Old August 16th, 2006, 02:04 PM
mateoc15's Avatar
mateoc15 mateoc15 is offline
C A R D S
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: The 'Ville
Posts: 784 mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 9 h 59 m 12 sec
Reputation Power: 12
Basic question as something to consider:

*Are any of the procedures recursive (calls itself)?
*Do they all access the same tables?
*Are indexes built on the main tables?
*Have you tried optimizing the queries within the procedures first? (that's where I would start)
__________________
Reinventing the wheel again

Reply With Quote
  #13  
Old August 17th, 2006, 06:05 PM
bhushanm bhushanm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 32 bhushanm User rank is Private First Class (20 - 50 Reputation Level)bhushanm User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 2 m 6 sec
Reputation Power: 3
Quote:
Originally Posted by jim mcnamara
Yes, return <error value> will work. You may want to learn about RAISE in pl/sql for user-defined errors. If there are user defined conditions that are errors, this is may be a better approach.


Thanks for the info jim...we use RAISE when we want to exit the procedure at the point of error. If we need to give information regarding the error to the calling process, we use the return method.

Also, just to clarify...if i have two out params in the function call, plus a return value, will the dbms_job automatically return them back to the calling function after execution?

Reply With Quote
  #14  
Old August 17th, 2006, 06:08 PM
bhushanm bhushanm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 32 bhushanm User rank is Private First Class (20 - 50 Reputation Level)bhushanm User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 6 h 2 m 6 sec
Reputation Power: 3
Quote:
Originally Posted by mateoc15
Basic question as something to consider:

*Are any of the procedures recursive (calls itself)?
*Do they all access the same tables?
*Are indexes built on the main tables?
*Have you tried optimizing the queries within the procedures first? (that's where I would start)


Hi mateoc15....

the answers are:

*no
*they all access the same table
*yes
*on-going

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Calling two SPs at once....


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump