473,756 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threads sharing objects in memory during high volume use

I have written a graphing engine (very similar to what BigCharts.com
offers). Basically, it's an ASPX page that accepts parameters and calls
back-end business objects (dlls) to create a graph. When the graph is
created as a jpeg, it is returned to the browser as binary data. When it is
used at a low volume, it performs great and returns correctly drawn graphs
in a timely manner. However when the amount of traffic is increased to a
high volume, the graphs come back distorted. I've done some research on this
issue and have found that when .NET creates an object in memory, it is not
thread safe. For instance, if an ASPX page gets called several times at
once and each call creates an object called oGraph, it will create several
oGraph objects. However, when an instance of the ASPX page goes to reference
the properties or methods of oGraph, it doesn't care about which instance in
memory that it uses. It will use one that it didn't create. What I end up
with is mutated graphs. For example, if two calls were made simultaneously
to create a 90 day IBM graph and a one day intraday MSFT graph, I will end
up with a graph with IBM as the title and a plot that reflects MSFT intraday
data. Many times it just looks like pieces of one graph drawn on top of the
other. Does anyone know of a way to tell the ASPX page (and the objects it
calls) to 'mind it's own business', so to say, and only use the specific
instances of objects it initiates? I have tried using
System.Threadin g.Monitor.Enter \Exit on all of my objects and have also tried
the SyncLock blocks, as well. Any help with this would be greatly
appreciated.
Nov 19 '05 #1
5 1572
you don't say which graphic library you are using. is it thread safe? (many
aren't). did you use vb module fields? these are not thread safe. by default
asp.net is thread safe, and object instances are local to the the running
thread.

-- bruce (sqlwork.com)
"Ron Mexico" <mi***********@ mworld.com> wrote in message
news:uW******** ******@TK2MSFTN GP09.phx.gbl...
I have written a graphing engine (very similar to what BigCharts.com
offers). Basically, it's an ASPX page that accepts parameters and calls
back-end business objects (dlls) to create a graph. When the graph is
created as a jpeg, it is returned to the browser as binary data. When it
is used at a low volume, it performs great and returns correctly drawn
graphs in a timely manner. However when the amount of traffic is increased
to a high volume, the graphs come back distorted. I've done some research
on this issue and have found that when .NET creates an object in memory, it
is not thread safe. For instance, if an ASPX page gets called several
times at once and each call creates an object called oGraph, it will create
several oGraph objects. However, when an instance of the ASPX page goes to
reference the properties or methods of oGraph, it doesn't care about which
instance in memory that it uses. It will use one that it didn't create.
What I end up with is mutated graphs. For example, if two calls were made
simultaneous ly to create a 90 day IBM graph and a one day intraday MSFT
graph, I will end up with a graph with IBM as the title and a plot that
reflects MSFT intraday data. Many times it just looks like pieces of one
graph drawn on top of the other. Does anyone know of a way to tell the
ASPX page (and the objects it calls) to 'mind it's own business', so to
say, and only use the specific instances of objects it initiates? I have
tried using System.Threadin g.Monitor.Enter \Exit on all of my objects and
have also tried the SyncLock blocks, as well. Any help with this would be
greatly appreciated.

Nov 19 '05 #2
Thank you for the quick reply, Mr. Barker. I am using the graphics library
that comes with .NET (GDI+, I guess) System.Drawing. Graphics and
System.Drawing. Bitmap are the objects. If ASP.NET is thread safe by
default, how else would I be getting combined images? Here's a more
descriptive explanation of how the application works: There are basically
three 'layers' to my application.

1. The ASPX page. All it does is take the parameters from the querys
string and create a new instance of the SecurityGraph object (an object I
wrote) and set some properties (Ticker symbol, plot color, graph
height/width, frequency, etc). The SecurityGraph object has a Generate
method. The last thing the ASPX page does is call that method.

2. SecurityGraph. When the Generate method is called in the SecurityGraph
object, the database is queried based on the information set in the
properties of the SecurityGraph object set by the ASPX page which are loaded
into the new instance of the MWGraph object.

3. MWGraph. This object is where the graph actually gets drawn using the
Graphics and Bitmap objects.

So if ASP.NET is thread safe, I'm guessing the only thing that can be
happening to cause the output of several graphs to have shared properties is
because GDI+ isn't thread safe and the Graphics and Bitmap object are being
shared when several graphs are being created at once by the same
aspx-invoked chain of SecurityGraph and MWGraph objects?

As for 'vb module fields', I'm not quite sure what you are referring to.
Please explain further. Thanks again.

"Bruce Barker" <br************ ******@safeco.c om> wrote in message
news:eM******** *****@TK2MSFTNG P10.phx.gbl...
you don't say which graphic library you are using. is it thread safe?
(many aren't). did you use vb module fields? these are not thread safe. by
default asp.net is thread safe, and object instances are local to the the
running thread.

-- bruce (sqlwork.com)
"Ron Mexico" <mi***********@ mworld.com> wrote in message
news:uW******** ******@TK2MSFTN GP09.phx.gbl...
I have written a graphing engine (very similar to what BigCharts.com
offers). Basically, it's an ASPX page that accepts parameters and calls
back-end business objects (dlls) to create a graph. When the graph is
created as a jpeg, it is returned to the browser as binary data. When it
is used at a low volume, it performs great and returns correctly drawn
graphs in a timely manner. However when the amount of traffic is increased
to a high volume, the graphs come back distorted. I've done some research
on this issue and have found that when .NET creates an object in memory,
it is not thread safe. For instance, if an ASPX page gets called several
times at once and each call creates an object called oGraph, it will
create several oGraph objects. However, when an instance of the ASPX page
goes to reference the properties or methods of oGraph, it doesn't care
about which instance in memory that it uses. It will use one that it
didn't create. What I end up with is mutated graphs. For example, if two
calls were made simultaneously to create a 90 day IBM graph and a one day
intraday MSFT graph, I will end up with a graph with IBM as the title and
a plot that reflects MSFT intraday data. Many times it just looks like
pieces of one graph drawn on top of the other. Does anyone know of a way
to tell the ASPX page (and the objects it calls) to 'mind it's own
business', so to say, and only use the specific instances of objects it
initiates? I have tried using System.Threadin g.Monitor.Enter \Exit on all
of my objects and have also tried the SyncLock blocks, as well. Any help
with this would be greatly appreciated.


Nov 19 '05 #3
the .net graphics library is thread safe (but not completely multithreaded -
just a performance issue). your code must not be thread safe.

you either have static (shared in vb) variables, or you used a vb module
variable (a member variable defined in a vb module), instead of instance
data, which has led to your problem.
-- bruce (sqlwork.com)

"Ron Mexico" <mi***********@ mworld.com> wrote in message
news:u4******** ********@TK2MSF TNGP15.phx.gbl. ..
Thank you for the quick reply, Mr. Barker. I am using the graphics
library that comes with .NET (GDI+, I guess) System.Drawing. Graphics and
System.Drawing. Bitmap are the objects. If ASP.NET is thread safe by
default, how else would I be getting combined images? Here's a more
descriptive explanation of how the application works: There are basically
three 'layers' to my application.

1. The ASPX page. All it does is take the parameters from the querys
string and create a new instance of the SecurityGraph object (an object I
wrote) and set some properties (Ticker symbol, plot color, graph
height/width, frequency, etc). The SecurityGraph object has a Generate
method. The last thing the ASPX page does is call that method.

2. SecurityGraph. When the Generate method is called in the SecurityGraph
object, the database is queried based on the information set in the
properties of the SecurityGraph object set by the ASPX page which are
loaded into the new instance of the MWGraph object.

3. MWGraph. This object is where the graph actually gets drawn using the
Graphics and Bitmap objects.

So if ASP.NET is thread safe, I'm guessing the only thing that can be
happening to cause the output of several graphs to have shared properties
is because GDI+ isn't thread safe and the Graphics and Bitmap object are
being shared when several graphs are being created at once by the same
aspx-invoked chain of SecurityGraph and MWGraph objects?

As for 'vb module fields', I'm not quite sure what you are referring to.
Please explain further. Thanks again.

"Bruce Barker" <br************ ******@safeco.c om> wrote in message
news:eM******** *****@TK2MSFTNG P10.phx.gbl...
you don't say which graphic library you are using. is it thread safe?
(many aren't). did you use vb module fields? these are not thread safe.
by default asp.net is thread safe, and object instances are local to the
the running thread.

-- bruce (sqlwork.com)
"Ron Mexico" <mi***********@ mworld.com> wrote in message
news:uW******** ******@TK2MSFTN GP09.phx.gbl...
I have written a graphing engine (very similar to what BigCharts.com
offers). Basically, it's an ASPX page that accepts parameters and calls
back-end business objects (dlls) to create a graph. When the graph is
created as a jpeg, it is returned to the browser as binary data. When it
is used at a low volume, it performs great and returns correctly drawn
graphs in a timely manner. However when the amount of traffic is
increased to a high volume, the graphs come back distorted. I've done
some research on this issue and have found that when .NET creates an
object in memory, it is not thread safe. For instance, if an ASPX page
gets called several times at once and each call creates an object called
oGraph, it will create several oGraph objects. However, when an instance
of the ASPX page goes to reference the properties or methods of oGraph,
it doesn't care about which instance in memory that it uses. It will use
one that it didn't create. What I end up with is mutated graphs. For
example, if two calls were made simultaneously to create a 90 day IBM
graph and a one day intraday MSFT graph, I will end up with a graph with
IBM as the title and a plot that reflects MSFT intraday data. Many times
it just looks like pieces of one graph drawn on top of the other. Does
anyone know of a way to tell the ASPX page (and the objects it calls) to
'mind it's own business', so to say, and only use the specific instances
of objects it initiates? I have tried using
System.Threa ding.Monitor.En ter\Exit on all of my objects and have also
tried the SyncLock blocks, as well. Any help with this would be greatly
appreciate d.



Nov 19 '05 #4
On Tue, 1 Nov 2005 14:41:30 -0500, "Ron Mexico"
<mi***********@ mworld.com> wrote:
For instance, if an ASPX page gets called several times at
once and each call creates an object called oGraph, it will create several
oGraph objects.
Yes, assuming oGraph is not defined with the Shared keyword in VB.
However, when an instance of the ASPX page goes to reference
the properties or methods of oGraph, it doesn't care about which instance in
memory that it uses.
If oGraph is defined as a field in your Page derived class, then a
page instance will always reference the same oGraph object.

It will use one that it didn't create.


You'd only see this problem if oGraph is Shared among multiple
instances, or perhaps you have shared / static fields inside of
oGraph. Perhaps you could share your code?

--
Scott
http://www.OdeToCode.com/blogs/scott/
Nov 19 '05 #5
Looks like you are using a variable that is shared accross sessions. Do you
use a member tagged with the "static" (in c#) or "shared" (in VB.NET)
keywords ?

Those variable are shared accross the whole application and in the case of
ASP.NET it means accross users (as in ASP.NET it's a single application used
by multiple users).

--
Patrice

"Ron Mexico" <mi***********@ mworld.com> a écrit dans le message de
news:uW******** ******@TK2MSFTN GP09.phx.gbl...
I have written a graphing engine (very similar to what BigCharts.com
offers). Basically, it's an ASPX page that accepts parameters and calls
back-end business objects (dlls) to create a graph. When the graph is
created as a jpeg, it is returned to the browser as binary data. When it is used at a low volume, it performs great and returns correctly drawn graphs
in a timely manner. However when the amount of traffic is increased to a
high volume, the graphs come back distorted. I've done some research on this issue and have found that when .NET creates an object in memory, it is not
thread safe. For instance, if an ASPX page gets called several times at
once and each call creates an object called oGraph, it will create several
oGraph objects. However, when an instance of the ASPX page goes to reference the properties or methods of oGraph, it doesn't care about which instance in memory that it uses. It will use one that it didn't create. What I end up
with is mutated graphs. For example, if two calls were made simultaneously
to create a 90 day IBM graph and a one day intraday MSFT graph, I will end
up with a graph with IBM as the title and a plot that reflects MSFT intraday data. Many times it just looks like pieces of one graph drawn on top of the other. Does anyone know of a way to tell the ASPX page (and the objects it calls) to 'mind it's own business', so to say, and only use the specific
instances of objects it initiates? I have tried using
System.Threadin g.Monitor.Enter \Exit on all of my objects and have also tried the SyncLock blocks, as well. Any help with this would be greatly
appreciated.

Nov 19 '05 #6

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

Similar topics

1
4111
by: Dennis Gavrilov | last post by:
Hi, All! I have two questions: strategic and technical. Technical one first: I need to share an array of objects (implemented as hashes, having references to other objects and hashes, sharing done after blessing) between all of the mod_perl2 threads. The structure can grow quite big - tenths of thousands of array elements. It can grow as system operates (not possible to construct at apache startup). Sharing array is OK, but inserting...
42
3200
by: Dan | last post by:
Hello, I have trouble with class calling. I am calling getvolume() with succes in the function CreateCircle but it do not want to call it in ShowCircle() function. I am staying in the same class. I thought that was the point of encapsulation. When the function ShowCircle() is called I get very large number -1.07374e+008 can anyone help me ?
6
2137
by: sathyashrayan | last post by:
Following are the selected thread from the date:30-jan-2005 to 31-jan-2005. I did not use any name because of the subject is important. You can get the original thread by typing the subject "string" in google comp.lang.c archives.Hope this helps.Hope I am not bothering any one. am I? =================================Start=========================== subject: Return to Start of Line? Question: I'd like printf, the next printf, to return...
6
1688
by: Ram P. Dash | last post by:
Hi: I've a third party DLL (not a .NET class library PE) which I use using DllImport attribute in my application running in multiple threads invoking different methods of the same DLL. The memory usage of the application is shooting to 1GB in just 30 minutes. It goes till it's 1.4GB after which I get OutOfMEmory exceptions. If I don't use the DLL, my memory stays put at 100MB.
3
2811
by: ExclusiveResorts | last post by:
Can the CallContext be used reliably for storing request specific data? We are developing an application library that uses the CallContext to keep an IdentityMap (hashtable of business objects that have been loaded from the DB) and a collection of business objects that have been modified during the current request. These object maps need to be globally visible throughout a request and expire at the end of it. The maps are accessed using...
35
4031
by: Carl J. Van Arsdall | last post by:
Alright, based a on discussion on this mailing list, I've started to wonder, why use threads vs processes. So, If I have a system that has a large area of shared memory, which would be better? I've been leaning towards threads, I'm going to say why. Processes seem fairly expensive from my research so far. Each fork copies the entire contents of memory into the new process. There's also a more expensive context switch between...
3
2335
by: James | last post by:
I realize the Garbage Collector does a lot of this for me, but I'm having trouble wrapping my head around something. We've been running into System.OutOfMemoryException on our production servers running ASP.NET 1.1.4322. It's very intermittent and I don't know exactly what's causing it. We do use a lot of a Session variables in our application and I'm wondering if it's possible that when our load is the heaviest, if we're storing large...
2
11327
by: =?Utf-8?B?RGFtZW9u?= | last post by:
Hi - I am attempting to write lines to a file at high volume, multiple threads. Here is my scenario: (initial "WriteToFile" object created via a parent multithreaded process, which receives files, can call custom code for each file received - much like BizTalk) 1. Receive multiple files, each file received creates a "WriteToFile" object
167
8326
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an object should run in its own thread, it should implement this mix-in class. Does this sound like plausible design decision? I'm surprised that C++ doesn't have such functionality, say in its STL. This absence of a thread/object relationship in...
0
9431
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10014
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9844
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9819
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9689
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7226
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6514
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3780
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
3
2647
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.