473,387 Members | 1,440 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,387 software developers and data experts.

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.Threading.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 1541
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**************@TK2MSFTNGP09.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.Threading.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.com> wrote in message
news:eM*************@TK2MSFTNGP10.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**************@TK2MSFTNGP09.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.Threading.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****************@TK2MSFTNGP15.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.com> wrote in message
news:eM*************@TK2MSFTNGP10.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**************@TK2MSFTNGP09.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.Threading.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 #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**************@TK2MSFTNGP09.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.Threading.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
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...
42
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...
6
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...
6
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...
3
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...
35
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? ...
3
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...
2
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...
167
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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.