本地 Flask 服务器上的慢请求 [英] Slow Requests on Local Flask Server

查看:38
本文介绍了本地 Flask 服务器上的慢请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚开始在本地服务器上使用 Flask,我注意到请求/响应时间比我认为的要慢.

Just starting to play around with Flask on a local server and I'm noticing the request/response times are way slower than I feel they should be.

像下面这样的简单服务器需要接近 5 秒的响应时间.

Just a simple server like the following takes close to 5 seconds to respond.

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return "index"

if __name__ == "__main__":
    app.run()

有什么想法吗?还是本地服务器就是这样?

Any ideas? Or is this just how the local server is?

推荐答案

好的,我想通了.支持 ipv6 的 Werkzeug 和 os 似乎存在问题.

Ok I figured it out. It appears to be an issue with Werkzeug and os's that support ipv6.

来自 Werkzeug 网站 http://werkzeug.pocoo.org/docs/serving/:

From the Werkzeug site http://werkzeug.pocoo.org/docs/serving/:

在支持 ipv6 并配置了 ipv6 的操作系统上,例如现代 Linux 系统、OS X 10.4 或更高版本以及 Windows Vista,如果访问本地服务器,某些浏览器可能会非常缓慢.这样做的原因是有时localhost"被配置为在 ipv4 和 ipv6 socktes 上都可用,一些浏览器会尝试先访问 ipv6,然后再访问 ivp4.

On operating systems that support ipv6 and have it configured such as modern Linux systems, OS X 10.4 or higher as well as Windows Vista some browsers can be painfully slow if accessing your local server. The reason for this is that sometimes "localhost" is configured to be available on both ipv4 and ipv6 socktes and some browsers will try to access ipv6 first and then ivp4.

所以解决方法是通过从我的主机文件中注释掉以下行来禁用来自本地主机的 ipv6:

So the fix is to disable ipv6 from the localhost by commenting out the following line from my hosts file:

::1             localhost 

一旦我这样做,延迟问题就会消失.

Once I do this the latency problems go away.

我真的在研究 Flask,我很高兴这不是框架的问题.我知道这不可能.

I'm really digging Flask and I'm glad that it's not a problem with the framework. I knew it couldn't be.

这篇关于本地 Flask 服务器上的慢请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆