I / O完成端口的优缺点 [英] I/O completion port's advantages and disadvantages

查看:198
本文介绍了I / O完成端口的优缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么很多人说I / O完成端口是快速而漂亮的模型?

什么是I / O完成端口的优点和缺点?

Why do many people say I/O completion port is fast and nice model?
What is the I/O completion port's advantages and disadvantages?

我想了解一些比其他型号更快的IOCP点。

I want to know some points which make faster IOCP than other model.

如果你可以比较其他模型(选择,epoll,传统的多线程/进程)来解释它,那就更好了。

If you can explain it comparing other models(select, epoll, traditional multi thread/process), it would be better.

推荐答案

I / O完成端口非常棒。描述它们没有更好的词汇。如果Windows中的任何内容都正确完成,那就是完成端口。

I/O completion ports are awesome. There's no better word to describe them. If anything in Windows was done right, it's completion ports.

你可以创建一些线程数(实际上并不重要)并在一次完成时将它们全部阻塞端口直到事件(您手动发布的一个事件,或来自 计时器异步的事件I / O,或其他)到达。然后,完成端口将唤醒一个线程来处理事件,直到您指定的限制。如果你没有指定任何东西,它将假设最多CPU核心数,这非常好。

You can create some number of threads (does not really matter how many) and make them all block on one completion port until an event (either one you post manually, or an event from a timer or asynchronous I/O, or whatever) arrives. Then the completion port will wake one thread to handle the event, up to the limit that you specified. If you didn't specify anything, it will assume "up to number of CPU cores", which is really nice.

如果已经有更多的线程活动超过最大值限制,它将等待其中一个完成,然后一旦进入等待状态就将事件交给线程。此外,它总是以LIFO顺序唤醒线程,因此缓存仍然很热。

If there are already more threads active than the maximum limit, it will wait until one of them is done and then hand the event to the thread as soon as it goes to wait state. Also, it will always wake threads in a LIFO order, so chances are that caches are still warm.

换句话说,完成端口是一个毫不费力的民意调查事件以及尽可能多地填充CPU解决方案。

In other words, completion ports are a no-fuss "poll for events" as well as "fill CPU as much as you can" solution.

您可以在完成端口,套接字或任何其他可等待的文件中抛出文件读取和写入。而且,如果您愿意,您可以发布自己的活动。每个自定义事件至少有一个整数和一个指针值的数据(如果你使用默认结构),但你并不仅限于此,因为系统也会很乐意接受任何其他结构。

You can throw file reads and writes at a completion port, sockets, or anything else that's waitable. And, you can post your own events if you want. Each custom event has at least one integer and one pointer worth of data (if you use the default structure), but you are not really limited to that as the system will happily accept any other structure too.

此外,完成端口速度快,非常快。曾几何时,我需要从另一个线程通知一个线程。碰巧的是,该线程已经有一个文件I / O的完成端口,但它没有泵送消息。所以,我想知道我是否应该咬紧牙关并使用完成端口以简化,即使发布一个线程消息显然会更有效率。我还没有决定,所以我进行了基准测试。令人惊讶的是,事实证明,完成端口的速度提高了约3倍。所以...更快,更灵活,决定并不难。

Also, completion ports are fast, really really fast. Once upon a time, I needed to notify one thread from another. As it happened, that thread already had a completion port for file I/O, but it didn't pump messages. So, I wondered if I should just bite the bullet and use the completion port for simplicity, even though posting a thread message would obviously be much more efficient. I was undecided, so I benchmarked. Surprise, it turned out completion ports were about 3 times faster. So... faster and more flexible, the decision was not hard.

这篇关于I / O完成端口的优缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆