473,547 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET Poor performance with long-running COM object calls

We have a COM object that has been wrappered for use in .NET and which can
make calls which can take a while to execute. These are mainframe
integration calls that might perform a lot of data entry and gathering,
returning the results to the ASP.NET caller.

I have tried an AsyncPage class (implements IHttpAsyncHandl er and uses
custom thread pool class from DevelopMentor.T hreadPool
-http://staff.develop.c om/woodring); I have tried the thread start-join trick
and no matter what, all pages stop when a call is made into the COM object
until the call returns.

In my internal logging I see that only one "real" system thread is used for
all the calls/pages/threads due to the way ASP.NET is hosting the CLR (I
guess).

This is very frustrating--does anyone know a way that you can FORCE ASP.NET
to use REAL SYSTEM THREADS, 1 per ASPX page execution instead of these
"girly-man" threads in the .NET clr, which seem to all freeze in dismay
whenever one of them dives into a COM object?

I'm sure there are many excuses for this odd trait of ASP.NET but I consider
it a bug anytime a "next generation" of a product behaves in a less robust
manner than its predecessor. The multithreading in ASP.NET is poor. Long
running pages shouldn't hold-up short running pages.
Nov 18 '05 #1
4 1759

"Bill Thorne" <Bi********@dis cussions.micros oft.com> wrote in message
news:EC******** *************** ***********@mic rosoft.com...
We have a COM object that has been wrappered for use in .NET and which can
make calls which can take a while to execute. These are mainframe
integration calls that might perform a lot of data entry and gathering,
returning the results to the ASP.NET caller.
. . . The multithreading in ASP.NET is poor. Long
running pages shouldn't hold-up short running pages.


No they don't. Threading in .NET is far superior to COM. What you are
seeing is probably a result of not setting the apartment model of your
threads correctly to work with your fusty old COM component.

What is the threading model of the COM component?
Did you set AspCompat='True ' on the ASPX page?
David
Nov 18 '05 #2
Sorry, forgot to mention that yes, tried the MTA option on the threading
model at the beginning since this is so easy to try. Didn't change anything-
next thing to try was the spawn new thread, start it (run long-running com
call in it) then join it, which wasn't very hard. Next thing to try was the
async http interface and async page class which was a pain, and still didn't
work.

aspcompat makes no sense for this COM object, which is a C++ multithreaded
object.

The problem starts "at the top" when the aspx.cs code is run as a CLR
"thread" instead of a win32 true system thread. Because the CLR is operating
in this separate multitasking model, it is apparently incapable of task
switching if it is inside a COM/unmanaged function.

I suppose you could posit that the threading model in ASP.NET is "superior"
to ASP for homogeneous short-lived ASPX pages in environments with very large
numbers of users. However, for environments with some legacy requirements
(including COM components that are non-trivial to convert to managed), the
"self-contained" threading model in the CLR has a very poor performance
profile for environments with, simply, "more than one" concurrent user. If
you only have a hundred or so active users, concurrent requests probably
won't run over 20 or so. I honestly in all my years of low-to-high level
systems coding have never seen any issue with win32 being able to
context-switch 20 system threads, even hundreds which is actually what it is
doing in the OPSYS anyway!

I am a big .NET and ASP.NET fan and have bet a huge amount of tools
development effort on it, but it doesn't mean I have to love every aspect
unconditionally . I would love to be corrected and provided a real solution
to my problem: the context switching in the CLR engine is simply not
compatible with COM objects, STA or MTA.

In a COM call = no CLR context switch
No context switch = no multitasking
No multitasking = step backwards

If there is a directive I can put in my ASPX page that requests a 1-1 CLR
thread to system thread...hooray . Anyone know of one? Sure sounds like a
good idea for those of us that need it.

Otherwise, I have to schedule-in an immediate upgrade of the COM component
to a mixed managed/unmanaged code implementation and have concerns about how
far into the codebase I will have to go to enable a context switch when
inside the ASP.NET CLR environment.

"David Browne" wrote:

"Bill Thorne" <Bi********@dis cussions.micros oft.com> wrote in message
news:EC******** *************** ***********@mic rosoft.com...
We have a COM object that has been wrappered for use in .NET and which can
make calls which can take a while to execute. These are mainframe
integration calls that might perform a lot of data entry and gathering,
returning the results to the ASP.NET caller.

. . .
The multithreading in ASP.NET is poor. Long
running pages shouldn't hold-up short running pages.


No they don't. Threading in .NET is far superior to COM. What you are
seeing is probably a result of not setting the apartment model of your
threads correctly to work with your fusty old COM component.

What is the threading model of the COM component?
Did you set AspCompat='True ' on the ASPX page?
David

Nov 18 '05 #3

"Bill Thorne" <Bi********@dis cussions.micros oft.com> wrote in message
news:52******** *************** ***********@mic rosoft.com...
Sorry, forgot to mention that yes, tried the MTA option on the threading
model at the beginning since this is so easy to try. Didn't change
anything-
next thing to try was the spawn new thread, start it (run long-running com
call in it) then join it, which wasn't very hard. Next thing to try was
the
async http interface and async page class which was a pain, and still
didn't
work.

aspcompat makes no sense for this COM object, which is a C++ multithreaded
object.
You didn't answer the question about the threading model of your COM
component. And you didn't answer the question about whether you set
ASPCOMPAT=true.
The problem starts "at the top" when the aspx.cs code is run as a CLR
"thread" instead of a win32 true system thread. Because the CLR is
operating
in this separate multitasking model, it is apparently incapable of task
switching if it is inside a COM/unmanaged function.
You are gravely mistaken.

I suppose you could posit that the threading model in ASP.NET is
"superior"
to ASP for homogeneous short-lived ASPX pages in environments with very
large
numbers of users. However, for environments with some legacy requirements
(including COM components that are non-trivial to convert to managed), the
"self-contained" threading model in the CLR has a very poor performance
profile for environments with, simply, "more than one" concurrent user.
If
you only have a hundred or so active users, concurrent requests probably
won't run over 20 or so. I honestly in all my years of low-to-high level
systems coding have never seen any issue with win32 being able to
context-switch 20 system threads, even hundreds which is actually what it
is
doing in the OPSYS anyway!

I am a big .NET and ASP.NET fan and have bet a huge amount of tools
development effort on it, but it doesn't mean I have to love every aspect
unconditionally . I would love to be corrected and provided a real
solution
to my problem: the context switching in the CLR engine is simply not
compatible with COM objects, STA or MTA.

In a COM call = no CLR context switch
No context switch = no multitasking
No multitasking = step backwards

If there is a directive I can put in my ASPX page that requests a 1-1 CLR
thread to system thread...hooray . Anyone know of one? Sure sounds like a
good idea for those of us that need it.


CLR threads wrap system threads. This may not be the case in future
versions of the CLR, but it's true now.
ASPCOMPAT=true will start your CLR threads as STA threads, and is intended
to prevent exactly the behavior you are complaining about.

From
http://msdn.microsoft.com/library/de...netchapt07.asp

When you call a COM object from a managed application, make sure that the
managed code's apartment matches the COM object's apartment type. By using
matching apartments, you avoid the thread switch associated with
cross-apartment calls.
.. . .

Use ASPCOMPAT When You Call STA Objects from ASP.NET
All .NET threads are MTA threads by default. Therefore, cross-apartment
calls and thread switches do not occur when you create and call COM objects
with an apartment type of Free, Both, or Neutral. However, cross-apartment
calls and thread switches occur when you create and call apartment-threaded
COM objects.
David
Nov 18 '05 #4
David, Thank you for your persistance despite my flaming.

My confusion arose from the documentation on aspcompat which focuses on
Apartment COM objects and VB. My COM object is a "both" model and the
problem I was encountering wasn't one of any breakage, just of being
locked-out.

Indeed, the aspcompat did fix the problem, and is also fixing a problem we
have with a mixed-model integration library also, which has no COM involved
but does have complex unmanaged code hanging on semaphors shared across
processes. These also get hung-up when one aspx page is waiting on a call
into the unmanaged code which deep-down as a WaitForSingleOb ject on a native
event semaphore (or mutex, pick your poison).

Once again, appreciate your help.
"David Browne" wrote:

"Bill Thorne" <Bi********@dis cussions.micros oft.com> wrote in message
news:52******** *************** ***********@mic rosoft.com...
Sorry, forgot to mention that yes, tried the MTA option on the threading
model at the beginning since this is so easy to try. Didn't change
anything-
next thing to try was the spawn new thread, start it (run long-running com
call in it) then join it, which wasn't very hard. Next thing to try was
the
async http interface and async page class which was a pain, and still
didn't
work.

aspcompat makes no sense for this COM object, which is a C++ multithreaded
object.

You didn't answer the question about the threading model of your COM
component. And you didn't answer the question about whether you set
ASPCOMPAT=true.
The problem starts "at the top" when the aspx.cs code is run as a CLR
"thread" instead of a win32 true system thread. Because the CLR is
operating
in this separate multitasking model, it is apparently incapable of task
switching if it is inside a COM/unmanaged function.


You are gravely mistaken.

I suppose you could posit that the threading model in ASP.NET is
"superior"
to ASP for homogeneous short-lived ASPX pages in environments with very
large
numbers of users. However, for environments with some legacy requirements
(including COM components that are non-trivial to convert to managed), the
"self-contained" threading model in the CLR has a very poor performance
profile for environments with, simply, "more than one" concurrent user.
If
you only have a hundred or so active users, concurrent requests probably
won't run over 20 or so. I honestly in all my years of low-to-high level
systems coding have never seen any issue with win32 being able to
context-switch 20 system threads, even hundreds which is actually what it
is
doing in the OPSYS anyway!

I am a big .NET and ASP.NET fan and have bet a huge amount of tools
development effort on it, but it doesn't mean I have to love every aspect
unconditionally . I would love to be corrected and provided a real
solution
to my problem: the context switching in the CLR engine is simply not
compatible with COM objects, STA or MTA.

In a COM call = no CLR context switch
No context switch = no multitasking
No multitasking = step backwards

If there is a directive I can put in my ASPX page that requests a 1-1 CLR
thread to system thread...hooray . Anyone know of one? Sure sounds like a
good idea for those of us that need it.


CLR threads wrap system threads. This may not be the case in future
versions of the CLR, but it's true now.
ASPCOMPAT=true will start your CLR threads as STA threads, and is intended
to prevent exactly the behavior you are complaining about.

From
http://msdn.microsoft.com/library/de...netchapt07.asp

When you call a COM object from a managed application, make sure that the
managed code's apartment matches the COM object's apartment type. By using
matching apartments, you avoid the thread switch associated with
cross-apartment calls.
.. . .

Use ASPCOMPAT When You Call STA Objects from ASP.NET
All .NET threads are MTA threads by default. Therefore, cross-apartment
calls and thread switches do not occur when you create and call COM objects
with an apartment type of Free, Both, or Neutral. However, cross-apartment
calls and thread switches occur when you create and call apartment-threaded
COM objects.
David

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1997
by: David Gray | last post by:
Hello Gurus, SQL Server 2000 Windows 2003 Server, Standard Edition. Firstly I'm not a SQL server DBA but have a little experience with Oracle 9i and Oracle Rdb. An application that I've inherited has started performing very very slowly over the last few days, as far as I know there have been no
7
2613
by: qvx | last post by:
Hi all, I have a performance problem in my app. It is a poor man's version of OCR app. I started this app as a prototype before implementing it in C++. But now, after I have a working copy in Python, I don't feel like doing the job again in C++. A speed improvement of at least 5 times would be necessary (I have to process several hundreds...
3
5255
by: sac | last post by:
I am using DB2 v8.1 on UNIX. At times the database shows extremely poor performance. I do not have dba/admin rights nor do I have the web based client for db2 v8.1. I have only command line access. Also DBA support starts after our jobs have completed. (1) Is there any command that I could use from command line to find out the process...
11
2823
by: Daveo | last post by:
Hi there, Since splitting my database, one form in particular takes about 10 times as long to load and refresh, compared to the unsplit version on the server. The code behind it contains 36 SQL statements which populate individual text boxes on the form - could that be why? Thanks - David
9
12735
by: oafyuf | last post by:
Hi, I'm having performanbce issues with StreamReader and was wondering what I could do to improve it... The following takes around 3 seconds to process! The content of the response is: "<?xml version="1.0" ?><ERROR>ORA-01403: no data found</ERROR>" HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strURIQuery);
2
2031
by: Segfahlt | last post by:
I have a fairly simple C# program that just needs to open up a fixed width file, convert each record to tab delimited and append a field to the end of it. The input files are between 300M and 600M. I've tried every memory conservation trick I know in my conversion program, and a bunch I picked up from reading some of the MSDN C# blogs, but...
20
2086
by: John Mark Howell | last post by:
I had a customer call about some C# code they had put together that was handling some large arrays. The performance was rather poor. The C# code runs in about 22 seconds and the equivalent C++.Net code runs in 0.3 seconds. Can someone help me understand why the C# code performance is so poor? I rewote the C# code to use a single...
4
2675
by: Jim Devenish | last post by:
I have converted an Access back-end to SQL Server back-end but am having some problems. The Access to Access application has been running well for some years. I have successfully copied all the data to SQL Server and linked the tables to the front end .mdb (I am not using .adp). Some queries were performing poorly so I have converted...
5
1462
by: Aykut Canturk | last post by:
Dear friends, I recently decided to move vb.net 2005 from vb6. my projects has average of 200 forms and 20 modules. I mostly write enterprise solution about production automation like applications. In VB6 it takes 15 to 20 second to open a project and almost less than 2 second to see the form after I click to project explorer. Compiling to...
6
6381
by: Bob | last post by:
Hi, I have a fairly large but not massive project. Visual Studio 2005 is starting to act very strange when I debug the project. For instance, if i set a break point, I often can't expand an array to see the contents. Instead, it will say "function evaluation timed out". Also, it takes a very long time to start and stop debugging, and...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
6030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5361
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1922
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.