473,386 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 IHttpAsyncHandler and uses
custom thread pool class from DevelopMentor.ThreadPool
-http://staff.develop.com/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 1744

"Bill Thorne" <Bi********@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.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********@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.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********@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.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 WaitForSingleObject on a native
event semaphore (or mutex, pick your poison).

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

"Bill Thorne" <Bi********@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.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
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...
7
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...
3
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...
11
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...
9
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: ...
2
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...
20
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...
4
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...
5
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.