Skip to menu

服务器框架

Sphinx 介绍

热芋头工作室 2016.02.04 11:31 查看 : 982

Sphinx is a tool that makes it easy to create intelligent and beautiful documentation, written by Georg Brandl and licensed under the BSD license.

It was originally created for the new Python documentation, and it has excellent facilities for the documentation of Python projects, but C/C++ is already supported as well, and it is planned to add special support for other languages as well. Of course, this site is also created from reStructuredText sources using Sphinx! The following features should be highlighted:

  • Output formats: HTML (including Windows HTML Help), LaTeX (for printable PDF versions), ePub, Texinfo, manual pages, plain text
  • Extensive cross-references: semantic markup and automatic links for functions, classes, citations, glossary terms and similar pieces of information
  • Hierarchical structure: easy definition of a document tree, with automatic links to siblings, parents and children
  • Automatic indices: general index as well as a language-specific module indices
  • Code handling: automatic highlighting using the Pygments highlighter
  • Extensions: automatic testing of code snippets, inclusion of docstrings from Python modules (API docs), and more
  • Contributed extensions: more than 50 extensions contributed by users in a second repository; most of them installable from PyPI

Sphinx uses reStructuredText as its markup language, and many of its strengths come from the power and straightforwardness of reStructuredText and its parsing and translating suite, the Docutils.

Documentation

You can also download PDF/EPUB versions of the Sphinx documentation: a PDF version generated from the LaTeX Sphinx produces, and a EPUB version.

Examples

Links to documentation generated with Sphinx can be found on the Projects using Sphinx page.

For examples of how Sphinx source files look, use the “Show source” links on all pages of the documentation apart from this welcome page.

You may also be interested in the very nice tutorial on how to create a customized documentation using Sphinx written by the matplotlib developers.

There is a Japanese translation of this documentation, thanks to the Japanese Sphinx user group.

A Japanese book about Sphinx has been published by O'Reilly: Sphinxをはじめよう / Learning Sphinx.

Hosting

Need a place to host your Sphinx docs? readthedocs.org hosts a lot of Sphinx docs already, and integrates well with projects' source control. It also features a powerful built-in search that exceeds the possibilities of Sphinx' JavaScript-based offline search.

Contributor Guide

If you want to contribute to the project, this part of the documentation is for you.

 

sphinx是一个著名的开源搜索引擎,和lucence系的(solr,elastisearch) 齐名,sina微博,搜狐微博,神奇网站,discuz都用它

sphinx用c++代码开发,代码写很工整。一般认为sphinx性能好,而solr功能更完善.实际上从网络IO模型上来说,sphinx 性能其实不如solr

sphinx内置4种IO模型,可通过配置文件指定


 
  1. enum Mpm_e
  2. {
  3.     MPM_NONE,        ///< process queries in a loop one by one (eg. in --console)
  4.     MPM_FORK,        ///< fork a worker process for each query
  5.     MPM_PREFORK,    ///< keep a number of pre-forked processes
  6.     MPM_THREADS        ///< create a worker thread for each query
  7. };

注释写的很清楚,在windows下只能用thread模式,在linux默认是fork模式,可以通过修改sphinx.conf[workers]项指定其他模式

sphinx常用的thread/fork模式步骤如下

  1. 主进程 create/bind/accept 新连接
  2. fork或者thread来处理客户端请求,每次只处理一条query
  3. 处理完成一条query之后,马上close掉client连接
    这样设计,可以降低编程难度,不容易出错,有点大巧不工的意思

phinx代码会自动判断,如果系统支持epoll,用epoll,否则使用poll,如果poll都没有,那就用select,默认timeout时间是5秒

从它的IO模型看,epoll/poll/select只是用来控制socket 读写的timeout,并不是为了高效处理大量并发请求,所以用select还是epoll完全没有区别

sphinx的prefork是标准的prefoxk:fork出子进程之后,才调用accept

sphinx的代码质量相当高,工程化做的不错,会主动的监控thread/sub-process,一旦挂掉数量不够会自动补齐

sphinx全部使用阻塞socket

在阻塞socket上,一样可以使用select来轮询信号,当select完毕,认为该套接字可读时:

  1. 阻塞的套接字,会让read阻塞,直到读到所需要的所有字节;
  2. 非阻塞的套接字,会让read读完fd中的数据后就返回,但如果原本你要求读10个数据,这时只读了8个数据,如果你不再次使用select来判断它是否可读,而是直接read,很可能返回EAGAIN或=EWOULDBLOCK(BSD风格)
向上