question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve async performance

See original GitHub issue

I have a (non-public) test case that executes two bulk read queries (in a batch); one that returns 31K rows of int,string,int,int and a second that returns 37K rows of int,int,int,int. The remote server is MySQL 5.6 on Linux, about 10ms away from my test box.

On full .NET 4.6.2 on Windows 10, the sync codepath uses less than one core and completes in 4s; the async code path uses over 300% CPU and takes 20s wall time.

sync:
real   4.043s
total  1.922s
user   1.438s
sys    0.484s

async:
real   20.840s
total  68.422s
user   47.531s
sys    20.891s

With dotnet, the results are even worse:

sync:
real   4.336s
total  1.953s
user   1.469s
sys    0.484s

async:
real   24.468s
total  85.703s
user   59.219s
sys    26.484s

Some investigation with dotTrace and dotPeek on the full .NET Framework shows that Socket.ReceiveAsync (used in the async code path) takes 2s of CPU time while Socket.Receive (which blocks until the data is received) only takes 1.5s. Moreover, Socket.ReceiveAsync appears to only return false (i.e., receive completed synchronously) on failure; a successful result always completes asynchronously, meaning that we suffer the penalty of a callback being queued to the threadpool on top of the extra CPU time just to initiate the operation!

Additionally, network bandwidth (shown in Task Manager) is noticeably lower for the async case than the sync case.

We may need to find some way to get the benefits of asynchronous I/O without the overhead of Socket.ReceiveAsync, perhaps by #163 or by writing custom P/Invoke for the full .NET Framework on Windows.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bgraingercommented, Jan 25, 2017

BufferedByteReader may be useful here; I’ll plan to take a look later.

0reactions
caleblloydcommented, Jan 25, 2017

I’m hacking on it as we speak; I’m using BufferedByteReader 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can using async-await give you any performance benefits?
In short and very general case - No, it usually will not. But it requires few words more, because "performance" can be understood...
Read more >
An Extremely Easy Tip to Improve Web Performance With ...
In this article, I want to tell you something very important when it comes to better performance when using async / await that's...
Read more >
Improve the performance with asynchronous functions to ...
To run the process in an asynchronous way, we need to call the function without the await keyword. In this case, the method...
Read more >
How to Improve Page Speed with async and defer
We will deep dive into visually understanding two special HTML attributes, async and defer , and how they help improve page loading.
Read more >
Improving Performance with Async/Await and Promise.all()
One way to improve performance is to map the promises into an array and use Promise.all() to wait for all of them to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found