Professional Web Applications Themes

apartmant thread safety - ASP Components

I'm rather confused about this whole threading business of IIS, ASP and COM components. We have an apartment threaded component with a function that is very resource intensive. One call takes about three seconds and 10mb of memory. Consider the following code: STDMETHODIMP SomeTest::Test(BSTR word) { DoMemoryAndProcessIntensiveOperation(); return S_OK; } I was under the impression that IIS serializes calls to the component, so that all memory is released before the next call comes in, but it looks like it is possible for IIS to have more than one call executing at the same time. Is that correct? What happens if ...

  1. #1

    Default apartmant thread safety

    I'm rather confused about this whole threading business of IIS, ASP and COM
    components.
    We have an apartment threaded component with a function that is very
    resource intensive. One call takes about three seconds and 10mb of memory.
    Consider the following code:

    STDMETHODIMP SomeTest::Test(BSTR word)
    {
    DoMemoryAndProcessIntensiveOperation();
    return S_OK;
    }

    I was under the impression that IIS serializes calls to the component, so
    that all memory is released before the next call comes in, but it looks like
    it is possible for IIS to have more than one call executing at the same
    time. Is that correct? What happens if client requests are coming in faster
    than it can handle?

    Is there some info on this?


    Serve Laurijssen Guest

  2. #2

    Default Re: apartmant thread safety

    It's not actually an IIS thing. It's how COM threading works. Inside COM
    goes over this in detail.

    Calls to a specific Single Threaded Apartment (i.e. Apartment 2) are
    serialized. But each ASP page runs in a separate COM STA apartment, so you
    could have 25 * # CPU's STAs (i.e. 50 on a dual proc). Each will have calls
    serialized to it, but they can each run in parallel.

    So, in your example, you could have 50
    DoMemoryAndProcessIntensiveOperations() going at the same time. Also, COM
    only serializes at the interface level. If your function relies on global
    variables, then you still must provide some protection for them.

    If you want to limit the number of simultaneous calls, you could use a
    Semaphore to gate access to 'x' simultaneous threads. The problem then
    would be that all other ASP pages that attempt to call will go into a WAIT
    until a Semaphore slot becomes available. Another option (I don't recommend
    this, but some have done it this way) is to mark the component as Single
    Threaded (instead of Apartment). This will cause only one instance to be
    active at one time. However, this is most likely going to cause some pretty
    severe scaling problems.

    Another solution for highly intensive operations w/high latencies is to
    decouple the call via MSMQ. Basically the page would post the call into the
    queue and return immediately to the user. Then have the page refresh a few
    seconds later to see if the operation had completed. Then you could control
    the number of simultaneous calls yourself.

    Pat

    "Serve Laurijssen" <csnospam.comp.com> wrote in message
    news:Et4Yb.559249$_x2.1259960zonnet-reader-1...
    > I'm rather confused about this whole threading business of IIS, ASP and
    COM
    > components.
    > We have an apartment threaded component with a function that is very
    > resource intensive. One call takes about three seconds and 10mb of memory.
    > Consider the following code:
    >
    > STDMETHODIMP SomeTest::Test(BSTR word)
    > {
    > DoMemoryAndProcessIntensiveOperation();
    > return S_OK;
    > }
    >
    > I was under the impression that IIS serializes calls to the component, so
    > that all memory is released before the next call comes in, but it looks
    like
    > it is possible for IIS to have more than one call executing at the same
    > time. Is that correct? What happens if client requests are coming in
    faster
    > than it can handle?
    >
    > Is there some info on this?
    >
    >

    Pat [MSFT] Guest

Similar Threads

  1. A question about thread safety and the Acrobat SDK
    By holmesd@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 5
    Last Post: October 3rd, 03:52 PM
  2. Thread safety/synchronization?
    By Mike Summers in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: April 8th, 04:01 PM
  3. Replies: 1
    Last Post: October 31st, 08:34 AM
  4. Ruby interpreter thread safety
    By Thomas Sondergaard in forum Ruby
    Replies: 4
    Last Post: September 4th, 11:46 AM
  5. Thread safety of vm_copy
    By Glen Low in forum Mac Programming
    Replies: 2
    Last Post: July 20th, 06:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139