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 12»»

Traces question Expand / Collapse
Author
Message
Posted Tuesday, October 1, 2013 3:49 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Today @ 12:30 AM
Points: 524, Visits: 1,158
Hi,

I'm running a server trace to determine where the procedures take more time to execute.
I'm tracking events 10, 12, 43 and 45.
My procedures call lots of other procedures but my main question is: shouldn't the sum of the time taken inside a procedure (ObjectType = 'procedure name') be the same as the time taken by it's execution (TextData LIKE 'EXEC procedure name')?
The procedure proc0 calls proc1 and the sum of proc1 takes 0,23ms (event 45 and objectype = 'proc1'). but event 43 of proc1 takes 5ms...
Is the difference from SQL "loading" and parsing proc1? proc1 is already in cache so no time to do that should be taken...

Why does this happen?

Thanks,
Pedro




If you need to work better, try working less...


  Post Attachments 
proc0_proc1_times.xlsx (9 views, 10.03 KB)
Post #1500321
Posted Wednesday, October 2, 2013 8:57 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 12:10 PM
Points: 5,669, Visits: 6,475
I'm not sure I'm clear on this...

Proc 0 is taking less time than Proc 1, right?

Nothing else happens in Proc 0 except that EXEC statement, right?

In which case this makes total sense to me because all Proc 0 does is send the call and then end execution. Proc 0 isn't using any of its resources after it sends the call and Proc 1 requires time to execute.

But if I'm misreading your post, please let me know.


Brandie Tarvin, MCITP Database Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1500806
Posted Wednesday, October 2, 2013 9:06 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Today @ 12:30 AM
Points: 524, Visits: 1,158
Brandie Tarvin (10/2/2013)
I'm not sure I'm clear on this...

Proc 0 is taking less time than Proc 1, right?

Nothing else happens in Proc 0 except that EXEC statement, right?

In which case this makes total sense to me because all Proc 0 does is send the call and then end execution. Proc 0 isn't using any of its resources after it sends the call and Proc 1 requires time to execute.

But if I'm misreading your post, please let me know.


That's it...
The start time in proc1 statement "EXEC proc0" and proc0 1st execution aren't the same.
That difference is the time SQL takes to "load" proc0 so it can be executed?

Pedro




If you need to work better, try working less...
Post #1500810
Posted Wednesday, October 2, 2013 10:29 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 12:10 PM
Points: 5,669, Visits: 6,475
They are two totally different stored procedures. You shouldn't be looking at their execution times collectively. Proc 0 will always take less time than Proc 1 because the only thing it does is say "Hey, SQL Server, Run this other guy."

Which is a very weird way of doing things. Why aren't you just calling Proc 1 straight instead?


Brandie Tarvin, MCITP Database Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1500847
Posted Wednesday, October 2, 2013 10:48 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Today @ 12:30 AM
Points: 524, Visits: 1,158
The code was written by c# programmers so it has loads of "modularity" so it can be used on several operations...
For example, proc0 is launch sales document and proc1 is validate document type that's also used when launching purchases documents...
The time "wasted" on calling other SPs from inside other SPs is huge... in the end over 50 different procs are called...

Pedro




If you need to work better, try working less...
Post #1500853
Posted Wednesday, October 2, 2013 11:56 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 12:10 PM
Points: 5,669, Visits: 6,475
Is it something you can start removing bit by bit as you look at this stuff?

Brandie Tarvin, MCITP Database Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1500871
Posted Wednesday, October 2, 2013 1:10 PM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Today @ 12:30 AM
Points: 524, Visits: 1,158
It's what I'm trying to do...
So far I'm removing cursors and other bad programmer's habits from sql server...
Do to the procedures design (call Sps from Sps) it has a lot of cursors.
Also some UPDATE statements do lock to themselves and other things...

Pedro




If you need to work better, try working less...
Post #1500893
Posted Thursday, October 3, 2013 5:19 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 12:10 PM
Points: 5,669, Visits: 6,475
Remember, not all cursors are bad. Some of them are necessary, and some of them can be faster than regular WHILE loops or other code. It just depends on the cursor.

But definitely exam each one of them to determine just how necessary they are.


Brandie Tarvin, MCITP Database Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1501118
Posted Thursday, October 3, 2013 5:28 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Today @ 12:30 AM
Points: 524, Visits: 1,158
Brandie Tarvin (10/3/2013)
Remember, not all cursors are bad. Some of them are necessary, and some of them can be faster than regular WHILE loops or other code. It just depends on the cursor.


No while loops here... Just to give you an example of what I've found, there's a trigger on a table ProductStore that has for each product the quantity on a store.
The update/insert/delete triggers call a SP that updates quantity on the Products table. But does it using a cursor to go over the INSERTED and DELETED records an calls the procedure updateProductQuantity @product, @newquantity, @type (delete or add).
This can be replaced inside the trigger with
UPDATE Produts SET Qnt = Qnt + t.Qnt FROM (SELECT Product, SUM(Qnt) Qnt FROM INSERTED GROUP BY Product) t WHERE t.Product = Products.Product

and the same with DELETED...
No need to go over each record in INSERTED and DELETED and call a procedure...

Thanks,
Pedro




If you need to work better, try working less...
Post #1501121
Posted Thursday, October 3, 2013 6:14 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 12:10 PM
Points: 5,669, Visits: 6,475
OUCH!

I feel for you. I really do.


Brandie Tarvin, MCITP Database Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1501145
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse