22. Resources
Thread is a very important and heavyweight
resource:
- Keeps memory (from 1 MB)
- Consumes CPU time
- .NET Garbage Collector travers all
threads’ roots
- …
28. I/O Completion Ports
- Work on OS level
- Appeared in Windows NT 3.5
- Link with I/O op: network socket, file
29. I/O Completion Ports
- Work on OS level
- Appeared in Windows NT 3.5
- Link with I/O op: network socket, file
- Once I/O completed, notification is sent to
the port
46. API
BeginX/EndX code is often too complex to maintain
asyncResult = fStream.BeginRead(
tempState.ReadArray, 0 , tempState.ReadArray.Length,
new AsyncCallback(EndReadCallback), tempState);
void EndReadCallback(IAsyncResult result){
...
}
47. API
XAsync is much easier using C# 5
async void ReadFile(FileStream file){
result=new byte[fileLength];
await file.ReadAsync(result, 0, result.Length);
}
48. API
XAsync is much easier using C# 5
async void ReadFile(FileStream file){
result=new byte[fileLength];
await file.ReadAsync(result, 0, result.Length);
}
Note: Mind the overhead!
49. API
Available .NET API:
- FileI/O – yes
- Network I/O – yes
- ADO.NET: SqlClient - yes
- EF6 in RC with Async support – yes
- EF5 – no
50. API
Available 3dparty API (just a few):
- Redis client BookSleeve – Yes
- Solr.Net – No
- NHibernate – No
- …
53. Practice
1. Simple ASP.NET MVC application
https://github.com/timba/async-web
2. Self-hosted WCF services application, uses a bit of
outdated stuff
https://github.com/timba/async-ef-performance-test