异步、非阻塞、基于事件的架构之间有什么区别? [英] What's the difference between: Asynchronous, Non-Blocking, Event-Base architectures?

查看:18
本文介绍了异步、非阻塞、基于事件的架构之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 有什么区别:

  1. What's the difference between:

  • 异步
  • 非阻塞
  • 基于事件的架构?

可以同时异步非阻塞(和基于事件)?

编程中最重要的是什么:异步、非阻塞和/或基于事件的(或所有 3 个)?

What's most important in programming, to have something: asynchronous, non-blocking and/or event-base (or all 3)?

如果您能提供示例,那就太好了.

If you could provide examples, that would be great.

问这个问题是因为我正在阅读这篇关于类似主题的很棒的StackOverflow文章但它没有回答我上面的问题.

This question is being asked because I was reading this great StackOverflow article on a similar topic but it doesn't answer my questions above.

推荐答案

异步异步字面意思是不同步.电子邮件是异步的.您发送邮件,您不希望现在得到回复.但它不是非阻塞的.本质上,它意味着一种架构,其中组件"在不期望立即响应的情况下相互发送消息.HTTP 请求是同步的.发送请求并获得响应.

Asynchronous Asynchronous literally means not synchronous. Email is asynchronous. You send a mail, you don't expect to get a response NOW. But it is not non-blocking. Essentially what it means is an architecture where "components" send messages to each other without expecting a response immediately. HTTP requests are synchronous. Send a request and get a response.

非阻塞该术语主要与 IO 一起使用.这意味着当您进行系统调用时,它会立即返回它所产生的任何结果,而不会让您的线程进入睡眠状态(很有可能).例如,非阻塞读/写调用返回他们可以做的任何事情,并期望调用者再次执行调用.例如,try_lock 是非阻塞调用.只有在可以获取锁的情况下才会锁定.系统调用的通常语义是阻塞.read 将等待直到它有一些数据并使调用线程进入睡眠状态.

Non-Blocking This term is mostly used with IO. What this means is that when you make a system call, it will return immediately with whatever result it has without putting your thread to sleep (with high probability). For example non-blocking read/write calls return with whatever they can do and expect caller to execute the call again. try_lock for example is non-blocking call. It will lock only if lock can be acquired. Usual semantics for systems calls is blocking. read will wait until it has some data and put calling thread to sleep.

基于事件这个术语来自 libevent.非阻塞读/写调用本身是无用的,因为它们不会告诉您何时"应该回叫它们(重试).select/epoll/IOCompletionPort 等是不同的机制,用于从操作系统何时"找出这些调用应该返回有趣"的数据.libevent 和其他此类库为各种操作系统提供的这些事件监视工具提供包装器,并提供一致的 API 以供跨操作系统运行.非阻塞 IO 与 Event-base 密切相关.

Event-base This term comes from libevent. non-blocking read/write calls in themselves are useless because they don't tell you "when" should you call them back (retry). select/epoll/IOCompletionPort etc are different mechanisms for finding out from OS "when" these calls are expected to return "interesting" data. libevent and other such libraries provide wrappers over these event monitoring facilities provided by various OSes and give a consistent API to work with which runs across operating systems. Non-blocking IO goes hand in hand with Event-base.

我认为这些术语是重叠的.例如 HTTP 协议是同步的,但使用非阻塞 IO 的 HTTP 实现可以是异步的.同样,像 read/write/try_lock 这样的非阻塞 API 调用是同步的(它立即给出响应),但数据处理"是异步的.

I think these terms overlap. For example HTTP protocol is synchronous but HTTP implementation using non-blocking IO can be asynchronous. Again a non-blocking API call like read/write/try_lock is synchronous (it immediately gives a response) but "data handling" is asynchronous.

这篇关于异步、非阻塞、基于事件的架构之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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