I/O completion port是微软号称目前为止最好(performance,scalability,throughput,etc.)的I/O处理机制。MSDN关于它的运行机制、performance等写道:
“The most efficient scenariooccurs when there are completion packets waiting in the queue, but no waits canbe satisfied because the port has reached itsconcurrency limit.
“No thread context switches will occur, becausethe running thread is continually picking up completion packets and the otherthreads are unable to run.
“The best overall maximumvalue to pick for the concurrencyvalue is the number of CPUs on the computer.
“Threads that block theirexecution on an I/O completion port are released inlast-in-first-out (LIFO) order, and the next completion packet ispulled from the I/O completion port's FIFO queue for that thread.”
I/OCompletion Port的显著特点有:
l 尽量减少thread context switches。
l 尽量只让一个thread去工作,而宁愿让一些completion消息等待处理,宁愿让其他的threads去休息。
l 理论上只要CPU个数的worker threads即可:这种情况下,如果有成千上万的completion消息在等待处理,I/O CompletionPort仍然不会生成更过的threads去服务他们,相反的,I/O Completion Port认为:这时,CPU个数的threads已经全力以赴,马不停蹄,没有任何的context switches,占用了所有的CPU资源,已经达到了系统的最大处理能力。如果再增加threads,则会增多contextswitches,反而降低了系统处理实际任务的能力和效率。