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

ASP.Net Memory problems..

I have an ASP.Net page which does some very memory intensive GDI+
processing. This page is being called using AJAX by another script
which I have no control over. What is happening is that the consuming
script is attempting to call my page hundreds of times which is causing
'Out of Memory' exceptions.

Is there any way I can change the behaviour either in my code or in IIS
to throttle the connections but keep them in a queue of some sort? I
can handle maybe 10 requests at a time, but I would want to queue up
requests in excess of this to be processed in order rather than give
timeout errors. This needs to be handled from my end rather than the
AJAX script end. Is this possible?

Sep 4 '06 #1
2 1161
Chris Ashley wrote:
I have an ASP.Net page which does some very memory intensive GDI+
processing. This page is being called using AJAX by another script
which I have no control over. What is happening is that the consuming
script is attempting to call my page hundreds of times which is causing
'Out of Memory' exceptions.

Is there any way I can change the behaviour either in my code or in IIS
to throttle the connections but keep them in a queue of some sort? I
can handle maybe 10 requests at a time, but I would want to queue up
requests in excess of this to be processed in order rather than give
timeout errors. This needs to be handled from my end rather than the
AJAX script end. Is this possible?
Certainly it should be possible. I had a system where I had to slow
down my response based on how many bad attempts had come from a
particular IP address, but obviously not tie up the servers threads by
having them sit in a Thread.Sleep or equivalent. All parlance below is
VB, but if you're in C# it should translate.

My page implements IHttpAsyncHandler. I have a Shared Sub New which
creates a queue (I use SortedList in my implementation, Queue is
probably more appropriate for you) and a thread. This thread sits in a
loop (with suitable sleeps when idle) and scans the queue for requests
to process (in my case, to see if they've been sat waiting long
enough). It then takes the requests off of the queue and processes
them.

The BeginProcessRequest function (part of IHttpAsyncHandler) takes the
details of the request, puts them into an object that implements
IAsyncResult, and it is these objects which are queued onto the above
mentioned queue (they store the context and the Me reference).
EndProcessRequest is empty, as is ProcessRequest. A helper function
takes the dequeued request and uses the stored Me reference to find the
page object. It then calls MyBase.ProcessRequest on the context which
was initially passed to BeginProcessRequest.

As you can hopefully see, the above model decouples the incoming
requests to their time of processing, but uses the normal ASP.Net
system (process request) to perform the normal processing.

What would you need to do for your system to work? Well, I'd recommend
that instead of one thread sitting and looping, you use 10 (or however
many you find is the right number - make it parameterisable).

Pseudocode of the thread body would be

While notAborted
Wait on "somethings arrived" autoreset event
While finding things to do
Synclock the queue
Check if there's a request on the queue.
If there is, dequeue it
End Synclock
If we dequeue a request, go to processing
End While
End While

And then the enqueueing code looks like this
Synclock the queue
Enqueue the request
Set the "somethings arrived" event
End Synclock

Course, you're still going to face memory issues, even doing this,
since every pending request has to have it's page object and context in
memory.

Another route might be to write a HttpModule which will intercept
things earlier in the process pipeline (before these objects are
allocated), and use shared state to know how many requests are
currently executing (so hook up event handlers to BeginRequest and
EndRequest, and if it's for the page that needs protecting, determine
how many requests are currently being processed, send it to sleep by
some suitable mechanism until one of those pages hits EndRequest (maybe
allocate a WaitHandle and put it on a queue again, but watch out for
race conditions)

Damien

Sep 4 '06 #2

Damien wrote:
Certainly it should be possible. I had a system where I had to slow
down my response based on how many bad attempts had come from a
particular IP address, but obviously not tie up the servers threads by
having them sit in a Thread.Sleep or equivalent. All parlance below is
VB, but if you're in C# it should translate.

My page implements IHttpAsyncHandler. I have a Shared Sub New which
creates a queue (I use SortedList in my implementation, Queue is
probably more appropriate for you) and a thread. This thread sits in a
loop (with suitable sleeps when idle) and scans the queue for requests
to process (in my case, to see if they've been sat waiting long
enough). It then takes the requests off of the queue and processes
them.
Hi Damien,

That's really useful - thanks ever so much for your extensive reply.

Regards,

Chris

Sep 4 '06 #3

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

Similar topics

5
by: Justice | last post by:
Currently I'm doing some experimenting with the XMLHTTP object in Javascript. Now, the XMLHttp object is asynchronous (at least in this case), and the following code causes a significant memory...
5
by: DLPnet | last post by:
Hello, I m working on Windows and Mac in C++. My application uses a lot of memory since it s dealing with a lot of images. So I load images in a cache when needed and if I haven t enough...
21
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
2
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
9
by: Bruno Barberi Gnecco | last post by:
I'm using PHP to run a CLI application. It's a script run by cron that parses some HTML files (with DOM XML), and I ended up using PHP to integrate with the rest of the code that already runs the...
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: 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:
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,...
0
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...
0
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...
0
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,...

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.