Posts tagged sta
I was recently involved in a rather tricky ASP COM problem. The ASP application was extremely fast serving pages but every 15 minutes (give or take), the response times would spike to 30 seconds or more. Of course, the first thing to check is how many threads are assigned to service the page queue, and it was the default 15, so no problem there. Then I noticed that the that processor use was very low, and on a 4 processor machine, only one was used and basically not at all.
It turns out that the pages were using a COM object that was single threaded (STA for the COM nerds), and this object was basically blocking all the ASP threads, which makes total sense. So I started to look at the ASP queue using perfmon, and this was the graph that presented itself.
You can see that the queue builds over time and then suddenly collapses. Well, again, this makes sense. The server processes each page one at a time until the queue becomes too big, at which point it makes an effort to clear the queue and ignore incoming requests. Depending on the queue size, it took about 15 seconds to clear it. However, I wasn’t stoked about rewriting an old COM object using MTA. The trick COM synchronization. Basically, you can use COM synchronization to enable the COM system to manage access to the object in memory. Everything that doesn’t use the COM object gets multi-threaded and only the code that uses the COM object is blocked.
It’s dead simple to setup up and it beats having to rewrite old code. You can read about COM synchronization in this MSDN article.