一個快速超輕量級的HTTP/1.1 WSGI服務器:bjoern

jopen 10年前發布 | 29K 次閱讀 bjoern 應用服務器

簡介

bjoern是一個用C語言編寫的,快速超輕量級的 Python WSGI服務器。

為什么說它很酷

bjoern是最快速的,最小的并且是最輕量級的WSGI服務器。有以下特性:

  • 1000 行的C代碼
  • 占用內存 600KB
  • 單線程沒有其他協同程序
  • 可以綁定到TCP主機:端口地址和Unix套接字
  • 支持HTTP1.0/1.1,包含支持HTTP1.1的分塊響應

安裝

libev

Arch Linux

pacman -S libev

Ubuntu

apt-get install libev-dev

Fedora, CentOS

yum install libev-devel

Mac OS X (使用homebrew)

brew install libev

bjoern

對大多數用戶,最簡單的安裝bjoern的方式是使用pip。確定libev已經安裝后:

pip install bjoern

也可使用setup.py文件直接安裝bjoern:

python setup.py install

對于一些Linux系統(尤其是Fedora和CentOS),該libdev頭可能安裝到默認路徑以為。為了構建bjoern,當運行setup.py時,需要輸出CFLAGS,例如:

CFLAGS=-I/usr/include/libev python setup.py install

用法

# Bind to TCP host/port pair:
bjoern.run(wsgi_application, host, port)

# TCP host/port pair, enabling SO_REUSEPORT if available.
bjoern.run(wsgi_application, host, port, reuseport=True)

# Bind to Unix socket:
bjoern.run(wsgi_application, 'unix:/path/to/socket')

# Bind to abstract Unix socket: (Linux only)
bjoern.run(wsgi_application, 'unix:@socket_name')

另外, 主循環可以單獨運行:

bjoern.listen(wsgi_application, host, port)
bjoern.run()

你也可以簡單的傳遞一個Python socket對象。注意,這時你要負責初始化和清除該socket。

bjoern.server_run(socket_object, wsgi_application)
bjoern.server_run(filedescriptor_as_integer, wsgi_application)

項目主頁:http://www.baiduhome.net/lib/view/home/1402636380962

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!