Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

python - Slow Requests on Local Flask Server

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.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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.

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...