I am new with Async and await using C# Programming. In WebAPI, we have created two API Controllers one with Async and await Programming and other is without that. We have done load testing using JMeter and we have got following results. Users Sync Async ________________________________________________________________________________ 100 No Errors No Errors 500 No Errors No Errors 750 No Errors Errors - (59.0 %) - 502 Bad Gateway 763 No Errors Errors 764 No Errors Errors 765 Errors - (0.13 %) - 502 Bad Gateway Errors 1000 Errors Errors Can you any please explain/suggest which approach is best or how can we proceed ? What I have tried: API Code : ==================================================================================== GetPersonalDetailsController - Async and await Used ==================================================================================== public async Task<IHttpActionResult> GET([FromUri] RequestQueryListDTO objAPIRequest) { DateTime startResponseTime = DateTime.Now; Response objResponse = null; string strResponse = string.Empty; var HeaderType = Request.Content.Headers.ContentType; ProductBAL objProductBAL = null; try { if (objAPIRequest != null) { Task<Response> tskGetProductDetails = Task<Response>.Run(() => { objProductBAL = new ProductBAL(); return objProductBAL.GetProductDetails(objAPIRequest); //Business Access Layer Logic calling }); objResponse = await tskGetProductDetails; } else { objResponse = new Response(); objResponse.ReturnCode = -1; objResponse.ReturnMessage = "Missing Parameters."; } } catch (Exception ex) { \\ Exception Logging } finally { objProductBAL = null; } objResponse.ResponseTime = Math.Round((DateTime.Now - startResponseTime).TotalMilliseconds).ToString(); if (objResponse.ReturnCode == Convert.ToInt32(General.ReturnCode)) { return Content<Response>(HttpStatusCode.BadRequest, objResponse); } else { return Ok(objResponse); } } ======================================================================== GetPDPController - Without using Async and await ======================================================================== public IHttpActionResult GET([FromUri] RequestQueryListDTO objAPIRequest) { DateTime startResponseTime = DateTime.Now; Response objResponse = null; string strResponse = string.Empty; var HeaderType = Request.Content.Headers.ContentType; try { if (objAPIRequest != null) { //Business Access Layer Logic calling } else { objResponse = new Response(); objResponse.ReturnCode = -1; objResponse.ReturnMessage = "Missing Parameters."; } } catch (Exception ex) { // Exception Logging Code } finally { objProductBAL = null; } objResponse.ResponseTime = Math.Round((DateTime.Now - startResponseTime).TotalMilliseconds).ToString(); if (objResponse.ReturnCode == Convert.ToInt32(General.ReturnCode)) { return Content<Response>(HttpStatusCode.BadRequest, objResponse); } else { return Ok(objResponse); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)