2

I'm having a FileUploadHandler.ashx in a web service to upload files to server in win forms application.

Even if FileUploadHandler made async / sync (tried both), it's taking time for every 5th Request...

I've a large no.of files, looping them to upload and for every consecutive 5th Request takes so much time....

I've created a log file to check which request is taking time as it follows below:

Request 1; Time Taken: 0.0717544 Request 2; Time Taken: 0.019239
Request 3; Time Taken: 0.0297877 Request 4; Time Taken: 0.0041714
Request 5; Time Taken: 99.9442763 Request 6; Time Taken: 0.031179
Request 7; Time Taken: 0.0332562 Request 8; Time Taken: 0.0037856
Request 9; Time Taken: 0.0283765 Request 10; Time Taken: 99.9690294

My FileUploadHandler.ashx code as follows:

 /// <summary>
/// Summary description for FileUploadHandler
/// </summary>
public class FileUploadHandler : IHttpAsyncHandler
{
    public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
    {
        AsynchOperation asynch = new AsynchOperation(cb, context, extraData);
        asynch.StartAsyncWork();
        return asynch;
    }

    public void EndProcessRequest(IAsyncResult result)
    {
    }

    public void ProcessRequest(HttpContext context)
    {

    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

class AsynchOperation : IAsyncResult
{
    private bool _completed;
    private Object _state;
    private AsyncCallback _callback;
    private HttpContext _context;

    private GCloudUploadingModel gclouduploadingdatamodel;

    bool IAsyncResult.IsCompleted { get { return _completed; } }
    WaitHandle IAsyncResult.AsyncWaitHandle { get { return null; } }
    Object IAsyncResult.AsyncState { get { return _state; } }
    bool IAsyncResult.CompletedSynchronously { get { return false; } }

    public AsynchOperation(AsyncCallback callback, HttpContext context, Object state)
    {
        _callback = callback;
        _context = context;
        _state = state;
        _completed = false;
    }




    public void StartAsyncWork()
    {
        try
        {

            ThreadPool.QueueUserWorkItem(new WaitCallback(StartAsyncTask), null);
        }
        catch (Exception ex)
        {

            // SEND ERROR MAIL TO TECHNICAL TEAM
            using (CommonBussinessAccess ErrorSending = new CommonBussinessAccess())
            {
                ErrorSending.SendFailureInfoEmailToTechnicalTeam(new PracticeModel(), this.GetType().Name, "StartAsyncWork", ex.Message, ex, new EMRWebExceptionTraceLogModel());
            }
        }
        finally
        {
            _completed = true;
            _callback(this);
        }


    }

  private void StartAsyncTask(Object workItemState)
  {
        try
        {
                  //Uploading code....
        }
        finally
        {

        }
  }

Please Help...

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
Abdul Rahman
  • 115
  • 1
  • 9

1 Answers1

3

It happens based on Failure Settings for an Application Pool.

  • rapidFailProtectionInterval: Specifies the number of minutes before the failure count for a process is reset.
  • rapidFailProtectionMaxCrashes: Specifies the maximum number of failures that are allowed within the number of minutes specified by the rapidFailProtectionInterval attribute.

The default value for both attributes is 5. It means if you have 5 unhandled exceptions in less than 5 minutes, then the application will restart.

if you are going to change those values using IIS Manager, then you can find those settings by selecting the application pool of your application → Advanced SettingsMaximum Failures and Failure Interval (minutes) in property grid:

enter image description here

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • But I ain't getting any exception in service, any other causes for pool restarting problem ?? – Abdul Rahman Feb 26 '18 at 08:42
  • There are multiple reasons for an application restart, for example writing something in application directory. But it will restart the application immediately. Since your application is restarting in every 5 requests, to me it's a symptom of having 5 unhandled exceptions in less than 5 minutes. – Reza Aghaei Feb 26 '18 at 09:24