• tornado : 异步、非阻塞


    The terms asynchronous and non-blocking are closely related and are often used interchangeably, but they are not quite the

    same thing.

    Blocking

    A function blocks when it waits for something to happen before returning. A function may block for many reasons: network I/O,

    disk I/O, mutexes, etc. In fact, every function blocks, at least a little bit, while it is running and using the CPU (for an extreme

    example that demonstrates why CPU blocking must be taken as seriously as other kinds of blocking, consider password hashing

    functions like bcrypt, which by design use hundreds of milliseconds of CPU time, far more than a typical network or disk access).

    A function can be blocking in some respects and non-blocking in others. For example,tornado.httpclient in the default

    configuration blocks on DNS resolution but not on other network access (to mitigate this use ThreadedResolver or a 

    tornado.curl_httpclient with a properly-configured build of libcurl). In the context of Tornado we generally talk about

    blocking in the context of network I/O, although all kinds of blocking are to be minimized.

    Asynchronous

    An asynchronous function returns before it is finished, and generally causes some work to happen in the background before triggering

    some future action in the application (as opposed to normal synchronous functions, which do everything they are going to do before

    returning). There are many styles of asynchronous interfaces:

    • Callback argument
    • Return a placeholder (FuturePromiseDeferred)
    • Deliver to a queue
    • Callback registry (e.g. POSIX signals)

    Regardless of which type of interface is used, asynchronous functions by definition interact differently with their callers; there is no free

    way to make a synchronous function asynchronous in a way that is transparent to its callers (systems like gevent use lightweight threads

    to offer performance comparable to asynchronous systems, but they do not actually make things asynchronous).

    参考:

    同步、异步、阻塞、非阻塞

  • 相关阅读:
    如何为基于windows验证的站点的某个页面、文件或文件夹单独设置匿名访问
    JMeter基础
    selenium select操作及其他补充
    HTML面试
    第一天
    AspNetPager 7.4.2版发布
    java移位运算copy来的。为了备忘
    android 开发中的错误
    启动android模拟器报错
    最省内存的方式加载图片资源
  • 原文地址:https://www.cnblogs.com/yuyutianxia/p/3991913.html
Copyright © 2020-2023  润新知