views:

108

answers:

1

I am using aspcompat page attribute in ASP.NET so the com components I call can get at ASP intrinsic objects (Request, Response, Application, etc)

I have quickly created a new test project, one asp.net page and a vb6 com component.

The page does this:

for (int i = 0; i < 1000; i++)
   Application["string" + i] = i.ToString();
  Debug.WriteLine(string.Format("{0} done adding strings to app",Environment.TickCount));
  var asp = new ASPTest.CompClass();
  asp.SetProcessId();

Basically I add stuff in the application object and then call the com component.

Set context = GetObjectContext
If Not context Is Nothing Then
    Set app = context("Application")
    Set ses = context("Session")
    Set resp = context("Response")
    If Not app Is Nothing Then
        OutputDebugString "" & GetTickCount & " writing response"
        resp.Write "I see application from vb <br/>"
        OutputDebugString "" & GetTickCount & " before "
        For i = 100 To 200
            resp.Write GetTickCount & " i = " & app("string" & i) & "<br/>"
        Next
        OutputDebugString "" & GetTickCount & " after "
    End If
Else
    OutputDebugString "No context"
End If

The problem is that the more stuff I put in the application the slower the vb code becomes. Not all the code though, just when I first try to invoke any method on intrinsic objects, in my example my first resp.Write call. If I add 10000 items in the app resp.Write takes ten seconds to complete, 60000 => timeout.

It seems that when I touch any intrinsic object the first time the runtime does something nasty to make the objects available to COM.

Have you ever seen this? Any suggestion is much appreciated.

A: 

This is almost certainly a problem with threading, probably having the Interop performing thread context switches with every call from the VB component to the classes in the context.

I'm not the expert here, so I might (probably wil) get corrected, but I believe you need to make sure your VB component is also STA, just like the ASP.NET page marked with the aspcompat=true sets it. If you keep all the components in the same thread, there won't be any context switches (which require very expensive marshalling).

Alan McBee
threading is fine, it is something about the amount of data I put in the Application object. If I put few items only there is no delay.
Cosmin Onea
Well, no, that's actually sounding exactly like a thread-marshalling bottleneck -- the more is in Application, the more has to be marshalled. The series of articles "Production Debugging for .NET Framework Applications" <http://msdn.microsoft.com/en-us/library/ms954594.aspx looks like it clearly explains where marshalling happens, but I haven't finished reading it yet to see if completely explains the behavior you mention.
Alan McBee
how would you explain that it happens only the first time I touch a context object? after the first call everything is lightning fast.
Cosmin Onea
Again, I'm a little out of my expertise here, so don't totally rely on what I'm saying. But I would suggest that once the context has been marshalled from the caller (ASP.NET) to the callee(VB COM object) (the marshalling, btw, is always delayed until the first call you make to it), it doesn't need to marshall it back to the caller, so everything else would go pretty fast.
Alan McBee