Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

STA Comes Not from STAbility : Page 2

Microsoft proclaims VB 6 and STA components as stable enterprise architecture for the middle tier. On the other hand you can find lots of strong restrictions for STA under COM+. You should learn all the restrictions as well as investigate their real reasons and possible effects before picking out some particular architecture. This time the author helps you to study a piece of Microsoft day-to-day advice "Don't make blocking calls from STA."


advertisement

TEST

It will take you half an hour to write a test revealing the behavior of STA objects making out-of calls under COM+.



1.      Create some COM EXE. Name that CmpExe. It does not matter what language you use and whether you make it as service or not.

2.      Expose its method via COM interface, let’s name it MtdExe.

3.      Write the code of MtdExe sleeping for a while, say, 300 ms and returning after that.

4.      Create some COM DLL CmpDll in VC++ with public method MtdDll. Mark that as STA. Keep in mind you could also create that component with VB6 but further you will need to insert pieces of Assembler to measure things.

5.      Write the code of MtdDll creating that COM EXE and calling its method MtdExe.

6.      Place that COM DLL under COM+ in a server application.

Now that we have got a simple infrastructure emulating a real system we can stress that system. Use Microsoft Application Center Test from VS.NET Enterprise Edition or something like that. As for me, I used simple bomber process whose goal was just to create a new thread, so that later that thread creates the COM DLL, calls its method MtdDll and measures time of the call.

FIRST RESULTS

Launch that and see after a while system will just hang. On my machine system hangs after about 200 calls to MtdDll. CPU activity drops to near zero and the system remains in that state forever. The system hangs during the call from CmpDll to CmdExe. Just hangs silently.

INVESTIGATION

After I had installed debug symbols for Windows 2000 Service Pack 3, adjusted AD+ (MS KB PSS ID Number: 286350 HOWTO: Use Autodump+ to Troubleshoot "Hangs" and "Crashes")and worked with WinDbg I caught the cause. The reason was a stack overflow in dllhost.exe process (COM+ Application). Let’s see the whole picture of stack exhausting.

As expected, all STA COM DLLs shared a thread pool of 10 threads (from 7+1 to 10*1). Below comes a sample table (Fig. 1) that shows how free stack space was changing when the COM DLL was serving 50 requests. Each line corresponds to one thread; the first column shows stack space while serving the first request (for each thread), and so forth. To avoid excessive clattering of the table, when stack space didn’t change in comparison to the previous measurement, the actual value is replaced with an austerisk. Mind you, that initial stack size, allocated by COM for every thread, is 256K, and tests have shown that a single request consumes 20K of stack space (at the point of logging, that is the beginning of MtdExe).

                               

Thread 1

139264

118784

*

*

*

*

                 

Thread 2

143360

122880

*

*

*

*

*

               

Thread 3

143360

122880

*

*

*

*

                 

Thread 4

143360

122880

*

*

*

                   

Thread 5

139264

118784

*

*

*

                   

Thread 6

139264

118784

*

*

*

                   

Thread 7

143360

122880

*

*

                     

Thread 8

139264

118784

*

*

                     

Thread 9

131072

110592

*

*

                     

Thread 10

135168

114688

*

*

                     

Fig. 1

Number of Requests

Minimum Free Stack Space

100

110592

150

86016

200

Stack Overflow

Fig. 2 shows the flashpoint where stack gets overflowed.

Below are the functions that were used to obtain the total stack size and the available stack space.

DWORD GetStackSize()

{



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date