Request takes longer than maximum time and I get error 500 - c#

My loadbalancer is set to maximum time - 120 seconds.
However when I process big data, it takes more time than that and I get error 500 - Service is temporarily unavailable.
How can I handle this issue?

A simple way of doing this is offloading the long running job to a separate "job server" and returning a web page immediately.
The "job server" can update job status in the database when completed or with progress as the job runs, and your web clients can poll the web server using AJAX or during normal page loads, looking for jobs marked as completed in the database and displaying a link to the result.
That way, no web request will take very long time at all and the client can go on starting more jobs or go on navigating the site while the job runs, even if your jobs run for hours.

Related

C# Best way to keep UI responsive during heavy workload

Our webserver generates a file on the fly for download. This takes about two minutes of heavy processing because it's taking 1000 word templates, mail merging them, converting them to pdf, then making a zip out of those 1000 files. The processing is freezing the web server from being able to do anything else in the mean time which is a problem since it's hosting 23 subdomains for clients and they noticed it freezing.
How can i force the UI thread to get some work done? I've been looking at Thread.Sleep and Thread.Yield but perhaps i'm not implementing them correctly. I'm very new to the concept of threading.
When starting the processing on the web server, generate a "job ID" and store it somewhere (such as a database). Add an endpoint so the client can query the status of the job. When the processing is complete, the user can use the job ID to get the resulting file(s). It works like this:
User wants to process files. They call the start endpoint, which returns a JobId.
The server begins processing that job in a non-request thread, or the job is picked up and processed by another server dedicated to that task. When the thread completes, it updates the job's status accordingly.
Later...
User wants to know the status of their process. They call the status endpoint using their JobId periodically. The server replies with some status information to show the user.
Later...
Once the job's status has changed to 'complete', the user can call the result endpoint with their JobId to get the final file(s).
The heavy processing should be done in a non-UI, non-request thread so other users are unaffected.
Using this approach, you can even do the processing on another server entirely. All the web server is doing is allowing the user to create and query processing jobs.

WebService duration time in IIS timed out

I have problem. I send multiple request to IIS Web Service (written in c# and .net platform). Every call need about 20 sec to proces. When I send 350 request, I get only half responses, and half time outs:
The operation has timed out
What to change, to correct process all requests.

Determining response time for IIS requests

We have a web service that is called by a third party. Third party's rules are that the service must return a response within 10 seconds.
We log all of the processing time, from when we receive the request, to when the web method exits.
Our problem: our third party is telling us that we are taking over 10 seconds, but according to our logs, we are finished processing well within time limit.
I suspect that the third party is having a connectivity problem, and that the time is lost after we complete processing, but while the response is coming down the wire. Our in-application logging can't captuer that timing (that I know of) because our web method has already returned.
Is there any IIS logging feature that we could use capture the time spent returning the response?
The time-taken entry in your logs accounts for the time it takes for the client to send the acknowledgment back to the server or reset the connection.
http://blogs.msdn.com/b/mike/archive/2008/11/13/time-vs-time-taken-fields-in-iis-logging.aspx
You'll want to also make use of the win32-status to determine when there is an issue.

asp.net connection reset with long running process

In an asp.net web form, I keep getting a connection reset error message. The page is doing a some long running processing (about 2-5 minutes).
I have no problem when the web request comes from the same machine as the web server. But when the request originates across the network, I get a connection reset error about 1:30 or 2 minutes into waiting for a response.
I have set the in web.config for this application and put the application it's own application pool.
What else can I try?
Edit
The purpose of this page is to accept input from the user, calculate something, and send the result back to them. The long running calculation isn't something I can offload until a later time.
A common way to handle this is to kick of a background thread to process your data, but immediately return an identifier to the browser, normally as a link. When the link is clicked, the server checks to see if processing is complete - if it is, show the results, if not, display a "please wait" message and the link again, or auto-refresh the page...
Do not make the browser wait for this long. Make the request asynchronous, make it return right away. If you need to make user wait - do it using Javascript

ASP.NET background processing blocks status or UI feedback

I know this question has been asked many times, but my problem is a little different.
I have page which lets user download and upload excel file. During downloading excel, it takes approx 2 mins to generate the file. I have added checkpoints which updates the database with status like (started processing, working on header ...etc). I have done the same thing for upload.
I also have a ajax request which checks the database in fixed interval and prints status to user to give feedbacks like (started processing, working on header ...etc).
The problem is, i get the feedback only when the process is complete. It looks like the session is blocked during the background process and any other request(ajax) are only completed once the background process is over. ajax makes approx 10 requests within 4 sec intervals.I get the 10 response back only in the end.
I have tried two iframes and also frames, one running the ajax and other running the process, Doesn't work. i tried separate browser(Process running in IE, ajax running in FF) and that works (so i now my code works). Can anybody advise? Thanks
p.s. My environment is IIS 6, ASP.NET 3.5 with MVC 1.0 browser is IE6.0
Your browser has a limitation on the number of connections that can be working concurrently.
I believe IE has a limitation of 2 connections. That means that even if you are running AJAX requests you can only have two requests running concurrently at the same time.
That is most likely why you're not seeing results until the end, because it's processing other connections and doesn't get to the status request until it's already done. That also explains why it works when you do it from different browsers, because you don't suffer from the same connection limitation.
Here's an article that details the issue.
This is exactly what i was looking for
(asynchronous-processing-in-asp-net-mvc-with-ajax-progress-bar)
Using delegate BeginInvoke of IAsyncResult helped with the blocked session

Categories