Options

System.Net.UnsafeNclNativeMethods+SafeNetHandles.accept() ??

NorbiNorbi Posts: 2
I am profiling our ASP.NET 2.0 based Web application with ANTS4 on W2208 and VS2008, and after having optimized a lot of COM Interop inefficiences came to the point when ANTS is roughly indicating that

Server.OnStart ...
Transition to unmanaged code ...
System.Net.UnsafeNclNativeMethods+SafeNetHandles.accept() ... 66%

Server.OnSocketAccept ... 32%

where our own code is only around 10% or so. But as I still want to get out more from our app (as it has been ported from ASP to ASP.NET and is currently only slightly better that original ASP one), I tried to understand what's behind System.Net.UnsafeNclNativeMethods+SafeNetHandles.accept() ...
and why it is consuming so much ...

So I wrote very simple aspx page that does almost nothing but only one call of a function that simply count down an integer value and thus using a lot of resources:

Shared Sub MyPause(ByVal intValue As Integer)
While (intvalue)
intvalue = intvalue - 1
End While
End Sub

and i call this function with very high value. Then I start it within ANTS4, let it run for a minute or so and stop profiling: then I mark cca 20 seconds of the run time somewhere in the middle, and am quite surprised that ANTS shows cca ...

Server.OnStart ...
Transition to unmanaged code ...
System.Net.UnsafeNclNativeMethods+SafeNetHandles.accept() ... 50%

Server.OnSocketAccept ...
... MyPause ... 50%

Could anyone explain to me please why ANTS indicates so much for unmanaged code as during the indicated period apparently only managed code (Mypause) has been running without any network communication etc. ???

Thank you very much in advance

Comments

  • Options
    ANTS profiler has two display modes, Wall-clock time and CPU time. A Thread.Sleep(1000) will have a wall-clock time of 1000ms and a CPU time of 0ms. A tight loop like your method MyPause should have a wall-clock time of 30s, and a CPU time of 30s (assuming the method runs for 30s).

    Accept() is a method that runs for the entire length of a web-server. It just sits in the background, and does nothing virtually for the whole length of your program. It can safely be ignored. It should have a 'wall-clock time' of 30s (if your program lasts 30s), and a CPU time of near-zero. Hence both methods (accept and MyPause) run for 30s simultaneously, and so are both shown as taking 50% of the total time.

    I imagine you would like optimize methods that take up a lot of CPU time, and ignore methods (like "Accept") that use no resources. Switching from 'Wall clock time' to 'CPU time' enables this. However, due to a bug in ANTS Profiler 4, the method Accept is not recognized as blocking, so will falsely give a high CPU-time. Please ignore this high CPU-time of 'Accept' when optimizing your code.

    I hope this helps!
    Jason Crease
    Red Gate Software
Sign In or Register to comment.