`
Zhongwei_leg
  • 浏览: 546974 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
社区版块
存档分类
最新评论

Tornado 源码阅读笔记(一)

 
阅读更多

先看一下 Tornado 的 ioloop.py

 

import select
# Choose a poll implementation. Use epoll if it is available, fall back to
# select() for non-Linux platforms
if hasattr(select, "epoll"):
    # Python 2.6+ on Linux
    _poll = select.epoll
elif hasattr(select, "kqueue"):
    # Python 2.6+ on BSD or Mac
    _poll = _KQueue
else:
    try:
        # Linux systems with our C module installed
        import epoll
        _poll = _EPoll
    except:
        # All other systems
        import sys
        if "linux" in sys.platform:
            logging.warning("epoll module not found; using select()")
        _poll = _Select

 

可以看到,在 Mac 下,使用的是 kqueue.

 

什么是 kqueue 呢?

 

kqueue 是 FreeBSD 上的一种的多路复用机制。它是针对传统的 select/poll 处理大量的文件描述符性能较低效而开发出来的。注册一批描述符到 kqueue 以后,当其中的描述符状态发生变化时,kqueue 将一次性通知应用程序哪些描述符可读、可写或出错了。
kqueue 支持多种类型的文件描述符,包括 socket、信号、定时器、AIO、VNODE、PIPE。

 

详细介绍可以 Google 一下 “Kqueue: A generic and scalable event notification facility” (Kqueue: 一种通用且可扩展的事件通知机制) 这个 PDF 文档。

 

 

 

 

参考列表:

1。使用 kqueue 在 FreeBSD 上开发高性能应用服务器

http://www.ibm.com/developerworks/cn/aix/library/1105_huangrg_kqueue/

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics