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

BASTA! 2021 - Deep Dive in async/await bei Backend-APIs

BASTA! 2021 - Deep Dive in async/await bei Backend-APIs

Slides zu meinem Vortrag auf der BASTA! 2021.

Sebastian Gingter

September 21, 2021
Tweet

More Decks by Sebastian Gingter

Other Decks in Programming

Transcript

  1. 9 ▪ ▪ ▪ ▪ ▪ ▪ ▪ Deep-dive in

    async/await bei Backend-APIs
  2. 10 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. 11 • • • ▪ ▪ ▪ ▪ ▪ 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. 12 • • • • • • • • •

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

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

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

    “Systems Performance: Enterprise and the Cloud“, 2013, Brendan Gregg, Pearson Verlag
  10. 21 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
  11. 24 ▪ ▪ ▪ ▪ ▪ ▪ ⏳ ▪ ▪

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

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

    • EndSomething(result) • • DoSomethingAsync() • event SomethingCompleted • • Task[<T>] DoSomethingAsync()
  14. 28 • • async Task<> MyMethodAsync() • • • await

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

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

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