gregoriusxu / booksleeve

Automatically exported from code.google.com/p/booksleeve
Other
0 stars 0 forks source link

Blocked connect within thread pool #40

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. If you open enough many number connection, Windows thread pool may not 
consume your job immediately. This is caused if you use TaskFactory.StartNew or 
another thread pool based .NET feature for intensive workload.

What is the expected output? What do you see instead?
I expect to execute RedisConnecionBase.Open as immediate as possible. To fix, 
you may change the code with ConnectAsync()

What version of the product are you using? On what operating system?
1.3.27, on Windows 7

Please provide any additional information below.
https://code.google.com/r/tcaesvk-booksleeve-20130417/source/detail?r=fb8106d360
0cbd616c684d336cb5e1d880ef7c38

Original issue reported on code.google.com by tcae...@gmail.com on 18 Apr 2013 at 5:48

GoogleCodeExporter commented 8 years ago
Good spot; I think I was at one point using BeginConnect, which annoyingly does 
the DNS resolution on the caller's thread, so it was impossible to guarantee 
any timeliness when using that - but it looks like this is fixed in 
ConnectAsync.

Minor note: these were very intentional:

- var state = (Tuple<RedisConnectionBase, 
TaskCompletionSource<bool>>)task.AsyncState;
+ var state = task.AsyncState as Tuple<RedisConnectionBase, 
TaskCompletionSource<bool>>;

If I have the type of state mismatched, I absolutely **don't** want that 
becoming a null-ref error: I want a very clear and obvious 
invalid-cast-exception

Original comment by marc.gravell on 18 Apr 2013 at 7:18

GoogleCodeExporter commented 8 years ago
For info, if you are working on a system with lots of Tasks, you might also 
want to play with the CompletionMode on the connection; there are 3 options:

- always async (Concurrent); callbacks are performed as tasks (except for some 
inbuilt commands)
- always sync (PreserveOrder); callbacks are performed by the reader thread
- mixed (ConcurrentIfContinuation); it attempts to see whether a task has a 
continuation; if it does, it performs it async; if it does not, it performs it 
sync

Original comment by marc.gravell on 18 Apr 2013 at 7:30