locked
OWIN health middleware response very slow RRS feed

  • Question

  • User2082812578 posted

    Hi,

    Hi. I have a problem with health endpoint. There is self hosted OWIN WebApi

    I have simple health check middleware which first at all middlewares chain. Sometimes health check response time 10-20 seconds (every 5-10-15 minutes), at normal case 30-40ms.

    HAProxy calls health endpoint every some seconds. Timeout 5 seconds. And when HAProxy got timeout from health endpoint, it makes node unavailalbe and of course all connection drop :(

    Middleware:

        public override async Task Invoke(IOwinContext context)
        {
        	var request = context.Request;
                
        	if (request.Uri.AbsolutePath.ToLower() != "/health")
        	{           
        		await Next.Invoke(context);       
        		return;
        	}
        
        	context.Response.Headers.Set("Content-Type", "application/json");
        	if (request.Method == "GET")    
        	{
        		if (!Health.Healthy)
               	{         
        			context.Response.StatusCode = 503;    
        		}
        	}
        	else   
        	{    
        		context.Response.StatusCode = 400;   
        	}
        }

    How can I investigate where is problem? Of course problem connected with load, threads, locks, other WEBApis on the same server etc., because problem "doesn't exist" at night (count of HAProxy timeouts are very small  in comparison with day). Or maybe problem with my middleware?

    Monday, December 5, 2016 7:48 PM

All replies

  • User-2057865890 posted

    Hi Olegmkr,

    To catch an exception that an async task throws, place the await expression in a try block, and catch the exception in a catch block.

    try
    {
        await Next.Invoke(context);
    }
    catch (Exception ex)
    {
        ...
    }

    Best Regards,

    Chris

    Tuesday, December 6, 2016 6:29 AM
  • User2082812578 posted

    Hi,

    Yes, I have the same middleware as you wrote, but after health middleware.

    I think you don't understand a problem. Service "works" well, but sometimes health endpoint response longer than normal and these longer responses affecting HAProxy and service becomes unavailable by HAProxy, but it works.

    Question: How investigate these longer responses and why it's happends.

    Oleg

    Tuesday, December 6, 2016 6:52 AM
  • User-2057865890 posted

    Hi Olegmkr,

    It might be a concurrent requests issue. Try to increase the number of concurrent requests.

    https://www.asp.net/mvc/overview/performance/using-asynchronous-methods-in-aspnet-mvc-4#ServerConfig 

    Best Regards,

    Chris

    Thursday, December 15, 2016 9:14 AM