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

Thinktecture Webinar: Web-API mit Turbo: Deep-dive in async/await für Backend-APIs

Thinktecture Webinar: Web-API mit Turbo: Deep-dive in async/await für Backend-APIs

Slides for my webinar.

Sebastian Gingter

February 16, 2022
Tweet

More Decks by Sebastian Gingter

Other Decks in Programming

Transcript

  1. 7 ▪ ▪ ▪ ▪ ▪ ▪ ▪ Deep-dive in

    async/await bei Backend-APIs
  2. 8 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
  3. 9 • • • ▪ ▪ ▪ ▪ ▪ 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…
  4. 10 • • • • • • • • •

    • Deep-dive in async/await bei Backend-APIs
  5. 11 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
  6. 12 • • • • • • • • •

    Deep-dive in async/await bei Backend-APIs
  7. 13 Deep-dive in async/await bei Backend-APIs ALU & FPU Registers

    0 Registers 1 CPU Core with Hyper-Threading Classic CPU Core
  8. 14 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. 15 Deep-dive in async/await bei Backend-APIs • • • Quelle:

    “Systems Performance: Enterprise and the Cloud“, 2013, Brendan Gregg, Pearson Verlag
  10. 18 ▪ ▪ ▪ ▪ ▪ ▪ ⏳ ▪ ▪

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

    in async/await bei Backend-APIs ReadFile API: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-readfile
  12. 21 Deep-dive in async/await bei Backend-APIs • • IAsyncResult BeginSomething()

    • EndSomething(result) • • DoSomethingAsync() • event SomethingCompleted • • Task[<T>] DoSomethingAsync() P
  13. 24 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
  14. 25 • • • • • 🤯 • • Deep-dive

    in async/await bei Backend-APIs
  15. 27 • • async Task<> MyMethodAsync() • • • await

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

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

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