SlideShare a Scribd company logo
1 of 33
Download to read offline
Organized by Donating to
R&Devents@criteo.com
criteo.com
Medium.com/criteo-labs
@CriteoEng #NYANconf
Debugging asynchronous scenarios
by Christophe Nasarre
Kevin Gosse
NYAN conference
First case: a service refuses to stop
• Still in running state in Windows Services panel
In production → take a memory snaphot
procdump -ma <pid>
Parallel Stack in Visual Studio
• Yes: VS is able to load a memory dump
• This is a nice way to visually see what is going on
→ We are waiting for ClusterClient.Dispose() to end
In production → take a memory snaphot
procdump -ma <pid>
Which foreground thread is still running?
what ClusterClient.Dispose() is waiting for?
Look at the Code Luke!
ActionBlock internals
Task ProcessMessage(TInput message)
{
...
}
In production → take a memory snaphot
procdump -ma <pid>
Which foreground thread is still running?
what ClusterClient.Dispose() is waiting for?
Look at the Code Luke!
Look for _agent state
Task ContinueWith(Action<Task> nextAction,…)
{
Task task = new ContinuationTaskFromTask<TResult>
(this, nextAction,…);
base.ContinueWithCore(task, …);
return task;
}
ContinueWith internals (1|3)
internal void ContinueWithCore(Task continuationTask, …)
{
TaskContinuation taskContinuation =
new StandardTaskContinuation(continuationTask, …);
…
if (!continuationTask.IsCompleted)
{
// add task to m_continuationObject
if (!AddTaskContinuation(taskContinuation, …))
{
taskContinuation.Run(this, …);
}
}
}
ContinueWith internals (2|3)
ContinueWith internals (3|3)
async Task<long> AAA(CancellationToken token)
{
Stopwatch tick = new Stopwatch();
tick.Start();
await BBB(token);
tick.Stop();
return tick.ElapsedMillisecond;
}
async/await Internals (1|2)
async/await Internals (2|2)
async Task AAA()
{
await BBB();
...
}
async Task BBB()
{
...
}
AsyncMethodBuilderCore+MoveNextRunner
Action
TaskSchedulerAwaitTaskContinuation**
Task (returned by BBB)
AAA State machine
Task (returned by AAA)
In production → take a memory snaphot
procdump -ma <pid>
Which foreground thread is still running?
what ClusterClient.Dispose() is waiting for?
Look at the Code Luke!
Look for _agent state
→ Exception broke the responses ActionBlock
BONUS: more continuations
• A few other continuation scenarios that you may encounter
✓ Task.Delay
✓ Task.WhenAny
✓ Special cases
Why a List<object> as continuation?
Task DoStuffAsync()
{
var task = SendAsync();
task.ContinueWith(t => LogStuff(t));
return task;
}
// user code
await DoStuffAsync();
DoSomethingSynchronously()
Task
m_continuationObject
nullStandardTaskContinuation
List<object>
StandardTaskContinuation
*TaskContinuation
Why a empty List<object> as continuation?
async Task DoStuffAsync()
{
var T1 = Task.Run(…);
var T2 = Task.Run(…);
await Task.WhenAny(T1, T2);
… // T2 ends first
}
T1
m_continuationObject
null
T2
m_continuationObject
null
CompleteOnInvokePromise
CompleteOnInvokePromise
empty List<object>object
Investigation 1 - key takeaways
1. Thread call stacks do not give the full picture
• Even Visual Studio parallel stacks is not enough
2. Require clear understanding of Task internals
• m_continuationObject and state machines
3. Start from the blocked task and follow the reverse references chain
• sosex!refs is your friend
Symptoms: 0% CPU and thread count raises
In production → take a memory snaphot
procdump -ma <pid>
look at call stacks in Visual Studio
In production → take a memory snaphot
procdump -ma <pid>
look at call stacks in Visual Studio
→ what are those tasks (we are waiting for) doing?
In production → take a memory snaphot
procdump -ma <pid>
look at call stacks in Visual Studio
→ what are those tasks (we are waiting for) doing?
look at tasks in WinDBG
→ no deadlock but everything is blocked…
ThreadPool internals
static void ProcessRequest()
{
var task = CallbackAsync();
task.Wait();
}
R
C
ThreadPool internals
ThreadPool
R
R
ThreadPool internals
ThreadPool
R R
R
R
R
R
C C
ThreadPool internals
ThreadPool
R R
R
R
C
C
R
R
ThreadPool internals
ThreadPool
R R
R
R
C
C
R R
R
R
R
R
C C
R
R
R
R
DEMO
Simple ThreadPool starvation code
Thread 1 Thread 2
ThreadPool internals
Global queue Local queue Local queue
Task 1
Task 2
Task 5
Task 4
Task 6Task 3
ThreadPool internals
Global queue Local queue
C
Thread 1
Local queue
C
Thread 2
Local queue
C
Thread 3
R
R
R
R
In production → take a memory snaphot
procdump -ma <pid>
look at call stacks in Visual Studio
→ what are those tasks (we are waiting for) doing?
look at tasks in WinDBG
→ no deadlock but everything is blocked…
→ ThreadPool is starved
Investigation 2 - key takeaways
1. Waiting synchronously on a Task is dangerous
2. ThreadPool scheduling is unfair
3. 0% CPU + increasing thread count = sign of ThreadPool starvation
Conclusion
• Understand the underlying data structures
• Think of causality chains instead of threads call stack
• Visual Studio is your friend
• Parallel Stacks to get the big picture
• WinDBG is your true ally
• Use and abuse of sosex !refs
• You knew that waiting on tasks is bad
• Now you know why
Resources
Criteo blog series
• http://labs.criteo.com/
• https://medium.com/@kevingosse
• https://medium.com/@chnasarre
Debugging extensions
• https://github.com/chrisnas/DebuggingExtensions (aka Grand Son Of Strike)
Contacts
• Kevin Gosse @kookiz
• Christophe Nasarre @chnasarre

More Related Content

What's hot

Q Con Performance Testing At The Edge
Q Con   Performance Testing At The EdgeQ Con   Performance Testing At The Edge
Q Con Performance Testing At The EdgeAlois Reitbauer
 
Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Alexander Shulgin
 
Golang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyGolang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyAerospike
 
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevMake Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevJian-Hong Pan
 
Global Interpreter Lock: Episode III - cat &lt; /dev/zero > GIL;
Global Interpreter Lock: Episode III - cat &lt; /dev/zero > GIL;Global Interpreter Lock: Episode III - cat &lt; /dev/zero > GIL;
Global Interpreter Lock: Episode III - cat &lt; /dev/zero > GIL;Tzung-Bi Shih
 
Let's meet your expectations!
Let's meet your expectations!Let's meet your expectations!
Let's meet your expectations!Bartosz Polaczyk
 
Quick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android DevQuick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android DevShuhei Shogen
 
Don't dump thread dumps
Don't dump thread dumpsDon't dump thread dumps
Don't dump thread dumpsTier1 App
 
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)Alexey Fyodorov
 
Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!Michael Barker
 
Ob1k presentation at Java.IL
Ob1k presentation at Java.ILOb1k presentation at Java.IL
Ob1k presentation at Java.ILEran Harel
 
Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.UA Mobile
 
[grcpp] Refactoring for testability c++
[grcpp] Refactoring for testability c++[grcpp] Refactoring for testability c++
[grcpp] Refactoring for testability c++Dimitrios Platis
 
Asynchronní programování
Asynchronní programováníAsynchronní programování
Asynchronní programováníPeckaDesign.cz
 
Deep dive - Concourse CI/CD and Pipelines
Deep dive  - Concourse CI/CD and PipelinesDeep dive  - Concourse CI/CD and Pipelines
Deep dive - Concourse CI/CD and PipelinesSyed Imam
 
Reactive by example - at Reversim Summit 2015
Reactive by example - at Reversim Summit 2015Reactive by example - at Reversim Summit 2015
Reactive by example - at Reversim Summit 2015Eran Harel
 
Javascript Promises
Javascript PromisesJavascript Promises
Javascript Promisesintive
 
Implementing STM in Java
Implementing STM in JavaImplementing STM in Java
Implementing STM in JavaMisha Kozik
 

What's hot (20)

Q Con Performance Testing At The Edge
Q Con   Performance Testing At The EdgeQ Con   Performance Testing At The Edge
Q Con Performance Testing At The Edge
 
Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2
 
Golang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyGolang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war story
 
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDevMake Your Own Developement Board @ 2014.4.21 JuluOSDev
Make Your Own Developement Board @ 2014.4.21 JuluOSDev
 
Global Interpreter Lock: Episode III - cat &lt; /dev/zero > GIL;
Global Interpreter Lock: Episode III - cat &lt; /dev/zero > GIL;Global Interpreter Lock: Episode III - cat &lt; /dev/zero > GIL;
Global Interpreter Lock: Episode III - cat &lt; /dev/zero > GIL;
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
 
Let's meet your expectations!
Let's meet your expectations!Let's meet your expectations!
Let's meet your expectations!
 
Quick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android DevQuick Introduction to Kotlin Coroutine for Android Dev
Quick Introduction to Kotlin Coroutine for Android Dev
 
Don't dump thread dumps
Don't dump thread dumpsDon't dump thread dumps
Don't dump thread dumps
 
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)
 
Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!Lock? We don't need no stinkin' locks!
Lock? We don't need no stinkin' locks!
 
Ob1k presentation at Java.IL
Ob1k presentation at Java.ILOb1k presentation at Java.IL
Ob1k presentation at Java.IL
 
Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.
 
Request process
Request processRequest process
Request process
 
[grcpp] Refactoring for testability c++
[grcpp] Refactoring for testability c++[grcpp] Refactoring for testability c++
[grcpp] Refactoring for testability c++
 
Asynchronní programování
Asynchronní programováníAsynchronní programování
Asynchronní programování
 
Deep dive - Concourse CI/CD and Pipelines
Deep dive  - Concourse CI/CD and PipelinesDeep dive  - Concourse CI/CD and Pipelines
Deep dive - Concourse CI/CD and Pipelines
 
Reactive by example - at Reversim Summit 2015
Reactive by example - at Reversim Summit 2015Reactive by example - at Reversim Summit 2015
Reactive by example - at Reversim Summit 2015
 
Javascript Promises
Javascript PromisesJavascript Promises
Javascript Promises
 
Implementing STM in Java
Implementing STM in JavaImplementing STM in Java
Implementing STM in Java
 

Similar to NYAN Conference: Debugging asynchronous scenarios in .net

Troubleshooting .net core on linux
Troubleshooting .net core on linuxTroubleshooting .net core on linux
Troubleshooting .net core on linuxPavel Klimiankou
 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesTatiana Al-Chueyr
 
Real Time Operating System Concepts
Real Time Operating System ConceptsReal Time Operating System Concepts
Real Time Operating System ConceptsSanjiv Malik
 
Lockless Programming GDC 09
Lockless Programming GDC 09Lockless Programming GDC 09
Lockless Programming GDC 09Lee Hanxue
 
Async and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NLAsync and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NLArie Leeuwesteijn
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVMSylvain Wallez
 
Handling Exceptions In C &amp; C++ [Part B] Ver 2
Handling Exceptions In C &amp; C++ [Part B] Ver 2Handling Exceptions In C &amp; C++ [Part B] Ver 2
Handling Exceptions In C &amp; C++ [Part B] Ver 2ppd1961
 
Adopting GraalVM - Scale by the Bay 2018
Adopting GraalVM - Scale by the Bay 2018Adopting GraalVM - Scale by the Bay 2018
Adopting GraalVM - Scale by the Bay 2018Petr Zapletal
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfOrtus Solutions, Corp
 
101 3.5 create, monitor and kill processes v2
101 3.5 create, monitor and kill processes v2101 3.5 create, monitor and kill processes v2
101 3.5 create, monitor and kill processes v2Acácio Oliveira
 
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio
 
3.5 create, monitor and kill processes v2
3.5 create, monitor and kill processes v23.5 create, monitor and kill processes v2
3.5 create, monitor and kill processes v2Acácio Oliveira
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxbobmcwhirter
 
Apache Flink internals
Apache Flink internalsApache Flink internals
Apache Flink internalsKostas Tzoumas
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded ProgrammingSri Prasanna
 
Deuce STM - CMP'09
Deuce STM - CMP'09Deuce STM - CMP'09
Deuce STM - CMP'09Guy Korland
 
Giorgio zoppi cpp11concurrency
Giorgio zoppi cpp11concurrencyGiorgio zoppi cpp11concurrency
Giorgio zoppi cpp11concurrencyGiorgio Zoppi
 

Similar to NYAN Conference: Debugging asynchronous scenarios in .net (20)

Troubleshooting .net core on linux
Troubleshooting .net core on linuxTroubleshooting .net core on linux
Troubleshooting .net core on linux
 
Nodejs Intro Part One
Nodejs Intro Part OneNodejs Intro Part One
Nodejs Intro Part One
 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummies
 
Real Time Operating System Concepts
Real Time Operating System ConceptsReal Time Operating System Concepts
Real Time Operating System Concepts
 
A Life of breakpoint
A Life of breakpointA Life of breakpoint
A Life of breakpoint
 
Lockless Programming GDC 09
Lockless Programming GDC 09Lockless Programming GDC 09
Lockless Programming GDC 09
 
Fork/Join for Fun and Profit!
Fork/Join for Fun and Profit!Fork/Join for Fun and Profit!
Fork/Join for Fun and Profit!
 
Async and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NLAsync and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NL
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
 
Handling Exceptions In C &amp; C++ [Part B] Ver 2
Handling Exceptions In C &amp; C++ [Part B] Ver 2Handling Exceptions In C &amp; C++ [Part B] Ver 2
Handling Exceptions In C &amp; C++ [Part B] Ver 2
 
Adopting GraalVM - Scale by the Bay 2018
Adopting GraalVM - Scale by the Bay 2018Adopting GraalVM - Scale by the Bay 2018
Adopting GraalVM - Scale by the Bay 2018
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
 
101 3.5 create, monitor and kill processes v2
101 3.5 create, monitor and kill processes v2101 3.5 create, monitor and kill processes v2
101 3.5 create, monitor and kill processes v2
 
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0
 
3.5 create, monitor and kill processes v2
3.5 create, monitor and kill processes v23.5 create, monitor and kill processes v2
3.5 create, monitor and kill processes v2
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
 
Apache Flink internals
Apache Flink internalsApache Flink internals
Apache Flink internals
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
 
Deuce STM - CMP'09
Deuce STM - CMP'09Deuce STM - CMP'09
Deuce STM - CMP'09
 
Giorgio zoppi cpp11concurrency
Giorgio zoppi cpp11concurrencyGiorgio zoppi cpp11concurrency
Giorgio zoppi cpp11concurrency
 

Recently uploaded

best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...kajalverma014
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoilmeghakumariji156
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfJOHNBEBONYAP1
 
PowerDirector Explination Process...pptx
PowerDirector Explination Process...pptxPowerDirector Explination Process...pptx
PowerDirector Explination Process...pptxgalaxypingy
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查ydyuyu
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Roommeghakumariji156
 
Power point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria IuzzolinoPower point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria Iuzzolinonuriaiuzzolino1
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdfMatthew Sinclair
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdfMatthew Sinclair
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftAanSulistiyo
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrHenryBriggs2
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsMonica Sydney
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasDigicorns Technologies
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.krishnachandrapal52
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...gajnagarg
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查ydyuyu
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样ayvbos
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"growthgrids
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge GraphsEleniIlkou
 

Recently uploaded (20)

best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 
PowerDirector Explination Process...pptx
PowerDirector Explination Process...pptxPowerDirector Explination Process...pptx
PowerDirector Explination Process...pptx
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
Power point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria IuzzolinoPower point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria Iuzzolino
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 

NYAN Conference: Debugging asynchronous scenarios in .net

  • 1. Organized by Donating to R&Devents@criteo.com criteo.com Medium.com/criteo-labs @CriteoEng #NYANconf Debugging asynchronous scenarios by Christophe Nasarre Kevin Gosse NYAN conference
  • 2. First case: a service refuses to stop • Still in running state in Windows Services panel
  • 3. In production → take a memory snaphot procdump -ma <pid>
  • 4. Parallel Stack in Visual Studio • Yes: VS is able to load a memory dump • This is a nice way to visually see what is going on → We are waiting for ClusterClient.Dispose() to end
  • 5. In production → take a memory snaphot procdump -ma <pid> Which foreground thread is still running? what ClusterClient.Dispose() is waiting for? Look at the Code Luke!
  • 7. In production → take a memory snaphot procdump -ma <pid> Which foreground thread is still running? what ClusterClient.Dispose() is waiting for? Look at the Code Luke! Look for _agent state
  • 8. Task ContinueWith(Action<Task> nextAction,…) { Task task = new ContinuationTaskFromTask<TResult> (this, nextAction,…); base.ContinueWithCore(task, …); return task; } ContinueWith internals (1|3)
  • 9. internal void ContinueWithCore(Task continuationTask, …) { TaskContinuation taskContinuation = new StandardTaskContinuation(continuationTask, …); … if (!continuationTask.IsCompleted) { // add task to m_continuationObject if (!AddTaskContinuation(taskContinuation, …)) { taskContinuation.Run(this, …); } } } ContinueWith internals (2|3)
  • 11. async Task<long> AAA(CancellationToken token) { Stopwatch tick = new Stopwatch(); tick.Start(); await BBB(token); tick.Stop(); return tick.ElapsedMillisecond; } async/await Internals (1|2)
  • 12. async/await Internals (2|2) async Task AAA() { await BBB(); ... } async Task BBB() { ... } AsyncMethodBuilderCore+MoveNextRunner Action TaskSchedulerAwaitTaskContinuation** Task (returned by BBB) AAA State machine Task (returned by AAA)
  • 13. In production → take a memory snaphot procdump -ma <pid> Which foreground thread is still running? what ClusterClient.Dispose() is waiting for? Look at the Code Luke! Look for _agent state → Exception broke the responses ActionBlock
  • 14. BONUS: more continuations • A few other continuation scenarios that you may encounter ✓ Task.Delay ✓ Task.WhenAny ✓ Special cases
  • 15. Why a List<object> as continuation? Task DoStuffAsync() { var task = SendAsync(); task.ContinueWith(t => LogStuff(t)); return task; } // user code await DoStuffAsync(); DoSomethingSynchronously() Task m_continuationObject nullStandardTaskContinuation List<object> StandardTaskContinuation *TaskContinuation
  • 16. Why a empty List<object> as continuation? async Task DoStuffAsync() { var T1 = Task.Run(…); var T2 = Task.Run(…); await Task.WhenAny(T1, T2); … // T2 ends first } T1 m_continuationObject null T2 m_continuationObject null CompleteOnInvokePromise CompleteOnInvokePromise empty List<object>object
  • 17. Investigation 1 - key takeaways 1. Thread call stacks do not give the full picture • Even Visual Studio parallel stacks is not enough 2. Require clear understanding of Task internals • m_continuationObject and state machines 3. Start from the blocked task and follow the reverse references chain • sosex!refs is your friend
  • 18. Symptoms: 0% CPU and thread count raises
  • 19. In production → take a memory snaphot procdump -ma <pid> look at call stacks in Visual Studio
  • 20. In production → take a memory snaphot procdump -ma <pid> look at call stacks in Visual Studio → what are those tasks (we are waiting for) doing?
  • 21. In production → take a memory snaphot procdump -ma <pid> look at call stacks in Visual Studio → what are those tasks (we are waiting for) doing? look at tasks in WinDBG → no deadlock but everything is blocked…
  • 22. ThreadPool internals static void ProcessRequest() { var task = CallbackAsync(); task.Wait(); } R C
  • 28. Thread 1 Thread 2 ThreadPool internals Global queue Local queue Local queue Task 1 Task 2 Task 5 Task 4 Task 6Task 3
  • 29. ThreadPool internals Global queue Local queue C Thread 1 Local queue C Thread 2 Local queue C Thread 3 R R R R
  • 30. In production → take a memory snaphot procdump -ma <pid> look at call stacks in Visual Studio → what are those tasks (we are waiting for) doing? look at tasks in WinDBG → no deadlock but everything is blocked… → ThreadPool is starved
  • 31. Investigation 2 - key takeaways 1. Waiting synchronously on a Task is dangerous 2. ThreadPool scheduling is unfair 3. 0% CPU + increasing thread count = sign of ThreadPool starvation
  • 32. Conclusion • Understand the underlying data structures • Think of causality chains instead of threads call stack • Visual Studio is your friend • Parallel Stacks to get the big picture • WinDBG is your true ally • Use and abuse of sosex !refs • You knew that waiting on tasks is bad • Now you know why
  • 33. Resources Criteo blog series • http://labs.criteo.com/ • https://medium.com/@kevingosse • https://medium.com/@chnasarre Debugging extensions • https://github.com/chrisnas/DebuggingExtensions (aka Grand Son Of Strike) Contacts • Kevin Gosse @kookiz • Christophe Nasarre @chnasarre