<div class="gmail_quote">On Mon, Jan 25, 2010 at 12:21 PM, Michel Fortin <span dir="ltr"><<a href="mailto:michel.fortin@michelf.com">michel.fortin@michelf.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Le 2010-01-25 à 11:36, Kevin Bealer a écrit :<br>
<div class="im"><br>> Are you also considering multiple levels of priority? In the reader /<br>> processor / writer case, I can think of several priorities the processor<br>> might want:<br>><br>> 1. Normal -- here is another buffer to write.<br>
> 2. Medium -- the file read failed, stop with this file.<br>> 3. Medium#2 -- too much information too fast, please stop sending until<br>> further notice.<br>> 4. High -- The system is going down, pack up and get out of dodge<br>
><br>> I'm not sure if #2 and #3 need to be at different levels, but it seems like<br>> 1, (2 or 3), and 4 should be distinct. E.g. you don't care about either<br>> Medium if there is a High in the pipe and you want to process Normals after<br>
> any High or Medium is handled.<br>><br>> This argues for a many-level approach, which might as well be an integer or<br>> short.<br><br></div>I think only one queue where you can put messages directly on the front is enough. The more priorities you have, the more overhead it adds.<br>
<br>Seriously, why should 4 be distinct from 2? First, they both should be rare enough that it won't make a difference in which order you execute them. And second: what 2 makes the thread do (stopping writing a file) you must do it for 4 anyway, so it's not like you're really wasting time by handling 2 before 4.<br>
<br>And 3 should be handled by setting a maximum capacity for queues. Even if you needed a message for that, you could just make it a priority message too. Stopping sending messages should be pretty quick to handle.<br>
<div class="im"><br>--<br>Michel Fortin<br><a href="mailto:michel.fortin@michelf.com">michel.fortin@michelf.com</a><br><a href="http://michelf.com/" target="_blank">http://michelf.com/</a><br></div></blockquote>
<div> </div>
<div>Yes, as you point out, each of the non-lowest priority messages are easy to handle quickly in this particular example. But it's easy to construct examples where more than 2 are a good idea, you need only assume that a non-lowest-priority message could be a common case or take a longer time to handle.</div>
<div> </div>
<div>For example, certain deadlock patterns arise from using a query/response idioms. The deadlock can be avoided by making some kinds of messages act with higher priority than others.</div>
<div> </div>
<div>But it's fine with me to wait until more experience accrues before solving this -- maybe there is a better way to solve the query/response question than message priorities.</div>
<div> </div>
<div>Kevin</div>
<div> </div></div>