0

I am creating async api endpoints in DNN (Formerly DotNetNuke).

It is an open source CMS and the source code is here: https://github.com/dnnsoftware/Dnn.Platform It's mainly a webforms application but it supports webapi and MVC too.

Here is the code I have:

[HttpGet]
[AllowAnonymous]
public async Task<IHttpActionResult> TestAsync()
{
    await Task.Delay(2000);
    return this.Ok(new { message = "Hello from async." });
}

[HttpGet]
[AllowAnonymous]
public IHttpActionResult TestSync()
{
    Thread.Sleep(2000);
    return this Ok(new { message = "Hello from sync." });
}

When I do load testing comparing the same method with and without async I get about the same results and it looks like even though the async endpoints work fine, they do not behave async.

If I run the very same endpoints and load tests in a new web application project I get about triple the throughput on the async endpoint vs the normal one.

My question is, what could make this behave non-async in DNN ?

It am putting some links here to what I have looked at in case someone has a clue on what could be the issue.

Looks like default.aspx is setup with async although I guess the webapi pipeline does not depend on default.aspx https://github.com/dnnsoftware/Dnn.Platform/blob/develop/DNN%20Platform/Website/Default.aspx

My controller class inherits from DnnApiController https://github.com/dnnsoftware/Dnn.Platform/blob/develop/DNN%20Platform/DotNetNuke.Web/Api/DnnApiController.cs

Dependency injection is used to find all the controllers that implement DnnApiController https://github.com/dnnsoftware/Dnn.Platform/blob/develop/DNN%20Platform/DotNetNuke.Web/Api/DnnApiController.cs

Routes are registered this way: https://github.com/dnnsoftware/Dnn.Platform/blob/9f83285a15d23203cbaad72d62add864ab5b8c7f/DNN%20Platform/DotNetNuke.Web/Api/Internal/ServicesRoutingManager.cs

I am unsure how this pipeline works and if maybe I missed some obvious entry point that simply needs to be made async or what. Any help is welcome.

Daniel Valadas
  • 301
  • 3
  • 10
  • The load testing details would help the investigation here, especially the number of concurrent connections. – tia Feb 05 '22 at 10:17
  • I think you're seeing one of the benefits of `async/await`. A lot of requests can be handled at the same time, because the main thread is not blocked while awaiting. – Poul Bak Feb 05 '22 at 10:58
  • What makes you feel that async here is not async enough? – Sir Rufo Feb 05 '22 at 11:13
  • 1
    I suggest, you use a `StopWatch` to measure the time it takes to run the method. If it takes 2 sec., then all is fine. – Poul Bak Feb 05 '22 at 11:14
  • For the load testing I used K6 with 200 virtual users for 1m with a 1 second sleep after each access to the API. With the DNN one I get a throughput of about 8 requests per second for both async and sync. With a plain API project (without DNN) I get about 30 requests/second without async and it moves to about 90 requesters per second with async. – Daniel Valadas Feb 05 '22 at 20:05
  • Now I might have pointed the finger at DNN too soon though, I moved the project that is working as supposed to IIS and it now misbehaves the same exact way, trying to figure out if I have some IIS issue... – Daniel Valadas Feb 05 '22 at 20:06
  • Have you try run async in parallel and use `Task.WhenAll` method ? – erw13n Feb 06 '22 at 11:41

0 Answers0