阻止IO与非阻塞IO;寻找好的文章 [英] Blocking IO vs non-blocking IO; looking for good articles

查看:147
本文介绍了阻止IO与非阻塞IO;寻找好的文章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

曾经有一次,我碰到了 Indy的简介文章和从那时起,不能停止思考阻止与非阻塞IO的关系。

Once upon a time I bumped into Introduction to Indy article and can't stop thinking about blocking vs non-blocking IO ever since then.

寻找一些很好的文章,描述阻止IO和非阻塞IO的优缺点和如何在每种情况下设计您的应用程序以获得自然,易于理解和易于维护的代码。

想了解BIG图片...

Looking for some good articles describing what are pros and cons of blocking IO and non-blocking IO and how to design your application in each case to get natural, easy to understand and easy to maintain code.
Would like to understand BIG picture...

推荐答案

好的阻止IO意味着给定的线程在完全收到IO之前不能再做任何事情(在套接字的情况下,这个等待可能是一个长的时间)。

Well blocking IO means that a given thread cannot do anything more until the IO is fully received (in the case of sockets this wait could be a long time).

非阻塞IO表示IO请求立即排队,函数返回。实际的IO然后由内核稍后的指针处理。

Non-blocking IO means an IO request is queued straight away and the function returns. The actual IO is then processed at some later pointer by the kernel.

对于阻止IO,您需要接受您要等待每个IO请求或您每个请求需要启动一个线程(这将非常复杂得非常快)。

For blocking IO you either need to accept that you are going to wait for every IO request or you are going to need to fire off a thread per request (Which will get very complicated very quickly).

对于非阻塞IO,您可以发送多个请求,但是您需要请记住,在稍后一点之前,数据将不可用。这个检查数据实际到达可能是最复杂的部分。

For non-blocking IO you can send off multiple requests but you need to bear in mind that the data will not be available until some "later" point. This checking that the data has actually arrived is probably the most complicated part.

在99%的应用程序中,您不需要关心您的IO块。有时候,您需要额外的表现,允许您启动IO请求,然后再回来执行其他操作,并希望找到IO请求已完成。

In 99% of applications you will not need to care that your IO blocks. Sometimes however you need the extra performance of allowing yourself to initiate an IO request and then do something else before coming back and, hopefully, finding that the IO request has completed.

无论如何,只是我的tuppence。

Anyway, just my tuppence.

这篇关于阻止IO与非阻塞IO;寻找好的文章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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