用Tornado request_time 给页面添加响应时间

在PHP 程序里面经常在页脚看到这些服务器响应时间,在Tornado 下也好实现,效果参见本站页脚,本站已启用Memcache 来保存html ,所看到的响应时间是首次响应时间。

Tornado.web request_time 源码:

def request_time(self):
    """Returns the amount of time it took for this request to execute."""
    if self._finish_time is None:
        return time.time() - self._start_time
    else:
        return self._finish_time - self._start_time

更详细参见 https://github.com/facebook/tornado/blob/master/tornado/wsgi.py

Relative Articles