0

asp.net .net 4.7 web API

I am accessing a ASP.NET web API via jQuery. JQuery collects a number of ids and sends one ajax request per id.

If there is 1 id the query is processed in 6-10ms If there is more than 1 it can take 500-1000 ms as seen in browser web dev timing or in IIS log access log files. A stopwatch in controller is consistent for all queries below 10ms.

Same issue on both IIS prod server and local Dev machine.

function dashboardLoader() {
    var tcs = $(".dashboardtc");
    for (var i = 0; i < tcs.length; i++) {
        var fid = $(tcs[i]).attr("data-fid");
     
        $.ajax({
            url: '/ctl/dashboardfeature/' + fid,
            type: 'GET',
            cache: false,
            contentType: "application/json",
            success: function (d1) {
                 adjustDashBoardCell(d1);
                },
            error: function (result) {
                console.log(result.Message);
            }
        });

    }
}

API:

 [Authorize]
    [Route("ctl/dashboardfeature/{fid}")]
    [HttpGet]
    public async Task<dashboardFeaturePayload> GetDashboardFeature(string fid)
    {
        try
        {
            var timer = new Stopwatch();
            timer.Start();
            if (!User.Identity.IsAuthenticated) return null;

            string un = User.Identity.Name;

            int fID = fid.val();

            string rtn = await Task.FromResult<string>(DashboardCode.GetDashboardFeatureAPI(fID, true));
            timer.Stop();
            TimeSpan timeTaken = timer.Elapsed;

            System.Diagnostics.Debug.WriteLine(timer.Elapsed.TotalMilliseconds.ToString());

            return new dashboardFeaturePayload(fID, rtn);
        }

        catch (Exception ex)
        {
            AdminTask.ExceptionLoging(ex);
            return new dashboardFeaturePayload(fid.val(), "ERROR");

        }
    }

Would appear to be link to the ability of IIS to process multiple requests arriving in the same time.

Web Dev Timing:

enter image description here

VS Output stopwatch:

enter image description here

Lambda
  • 1,020
  • 2
  • 10
  • 25
  • 1
    So your DDOS-ing your own server? Nice. Maybe look at sending all the IDs in a single request or using an ajax queue? – freedomn-m Jan 13 '22 at 15:49
  • `string rtn = await Task.FromResult(DashboardCode.GetDashboardFeatureAPI(fID, true));` serves no purpose, and can be replaced by `string rtn = DashboardCode.GetDashboardFeatureAPI(fID, true);`. – Richard Deeming Jan 13 '22 at 15:57
  • 1
    Beyond that, do you have session state enabled for your site? If so, requests from a single session will be serialized. [Disable Session state per-request in ASP.Net Web Api (ApiController)](https://stackoverflow.com/a/63957833/124386) – Richard Deeming Jan 13 '22 at 15:59
  • @RichardDeeming I think this may be the reason. Will do more test. – Lambda Jan 13 '22 at 17:28
  • Regardless of serialisation, why would last query be 1 sec not 4 x 10ms = 40ms? very strange. – Lambda Jan 13 '22 at 17:37

0 Answers0