Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Thinktecture Webinar async/await in .NET

Thinktecture Webinar async/await in .NET

Slides for my webinar about async/await in .NET.

Sebastian Gingter

May 19, 2021
Tweet

More Decks by Sebastian Gingter

Other Decks in Technology

Transcript

  1. 3 ▪ 😨 ▪ ▪ ▪ ▪ ▪ Deep-dive in

    async/await bei Backend-APIs
  2. 5 ▪ ▪ ▪ ▪ ▪ ▪ ▪ Deep-dive in

    async/await bei Backend-APIs
  3. 6 Deep-dive in async/await bei Backend-APIs Kern 1 Kern 2

    Kern 3 Kern 4 P2 T1 P2 T2 P3 T1 P1 T2 P3 T2 OS Scheduler P1 T1
  4. 7 • • • ▪ ▪ ▪ ▪ Deep-dive in

    async/await bei Backend-APIs * Zahlen für Windows, Quelle: “Windows Internals“, Solomin, Russinovich et al. Jeffrey Richter sagt hingegen: 30 ms in Windows, Linux hat andere Zeiten…
  5. 8 • • • • • • • • •

    • Deep-dive in async/await bei Backend-APIs
  6. 9 Deep-dive in async/await bei Backend-APIs Kern 1 Kern 2

    Kern 3 Kern 4 P2 T1 P2 T2 P3 T1 P1 T1 P3 T2 P1 T2 Kontext-Wechsel Kontext- & Prozess-Wechsel
  7. 10 • • • • • • • • •

    Deep-dive in async/await bei Backend-APIs ALU & FPU Registers 0 Registers 1 Classic CPU Core CPU Core with Hyper-Threading
  8. 11 Deep-dive in async/await bei Backend-APIs Kern 1 Kern 2

    Kern 3 Kern 4 P2 T1 P2 T2 MyProc T1 P1 T2 P1 T1 MyProc T2 MyProc T3 MyProc T4 MyProc T5 MyProc T7 MyProc T6
  9. 13 Deep-dive in async/await bei Backend-APIs Task Task-Liste Threadpool T1

    Threadpool T2 Kern 1 Kern 3 Kern 2 Kern 4 Threadpool T3 Threadpool T4 Threadpool Management Jeder Pool-Thread arbeitet Tasks in einer Endlosschleife ab Completed Tasks
  10. 16 ▪ ▪ ▪ ▪ ▪ ▪ ⏳ ▪ ▪

    ▪ Deep-dive in async/await bei Backend-APIs ReadFile API: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-readfile
  11. 17 ▪ ▪ ▪ ▪ ▪ ▪ ⏳ ▪ Deep-dive

    in async/await bei Backend-APIs ReadFile API: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-readfile
  12. 19 • • async Task<> MyMethodAsync() • • • await

    OtherMethodAsync() • • await • • • • Deep-dive in async/await bei Backend-APIs
  13. 22 • • task.GetAwaiter().GetResult() → ❌ • Thread.Sleep() → ❌

    • await Task.Delay() → ✔ • Thread.SpinWait() • → ❌ • → ✔ Deep-dive in async/await bei Backend-APIs
  14. 23 • • var task1 = DoSomethingAsync(); var task2 =

    DoSomethingElseAsync(); await Task.WhenAll(task1, task2); • • • Task.Factory.StartNew(…, TaskCreationOptions.LongRunning); • • • Deep-dive in async/await bei Backend-APIs