Difference between asynchronous and non-blocking (difference between asynchronous and non-blocking)

Source: Internet
Author: User

When looking at some frameworks, such as tornado, We will sometimes mention non-blocking at the implementation level. Some frameworks use async technology. So what is the difference between non-blocking and async?

Below is my understanding:

1. There is no difference in many cases. When we talk about Asynchronization and non-blocking, we usually refer to how long an API call will take, so will it affect performance and let the caller wait. For example, when we program windows, if our UI thread does some time-consuming work, our application will get stuck, resulting in poor user experience. In this case, whether asynchronous or non-blocking, this problem can be solved-that is, the call can be quickly returned. When we talk about the API call return speed, async and non-blocking are no different.

2. async and non-blocking are different when we discuss the control of two thread calls. When thread a, call API function B. If thread a calls a, the result is returned if the result is ready-made, and the result needs to be calculated to return the unavailable status. This is non-blocking, that is, the control is still in the main thread (no block main thread ). If it is an async call, when thread a calls function B, control has been transferred from A to B. B has the right to decide when to return the result (that is, to call the callback function), or even not to return the result.

The main reason tornado claims that it is non-blocking is determined during tornado design. browser accesses tornado server and then returns the result. So that other browsers can continue to request tornado resources.

Since this is the design decision, it is not the technical implementation. That is to say, when you implement the function, for example, if you make the tornado call take a long time to return, all callers will be stuck there (Tornado is a single-thread server ). As the implementer, you cannot allow the caller to spend too much time. If you really need it, you still need to use async.

This is different from the way we use IIS. in IIS, it takes too long for one web access to affect the other client. IIS will use different threads for processing. In tornado, If you block a thread, the entire server is unavailable. The problem arises. What if a web access may take too long?

Tornado's official wiki says this:

1. Make the access not time-consuming (this is basically nonsense ).

2. Use an asynchronous library, such as asynchttpclient.

3. Create a message queue for a process to process it separately.

4. submit it to another thread for processing.

 

 

Reference:

Https://github.com/facebook/tornado/wiki/Threading-and-concurrency

Http://stackoverflow.com/questions/2625493/asynchronous-vs-non-blocking

Http://my.oschina.net/digerl/blog/30456

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.