I wrote a flask application. I found it very slow when I deployed it in a remote server. So, I did some profiling practices with it. Please take a look at the pictures below:
The code I use to profiling is:
#coding: utf-8
from werkzeug.contrib.profiler import ProfilerMiddleware
from app import app
app.config['PROFILE'] = True
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions = [30])
app.run(debug = True)
Picture 1
profiling in the remote server.
Maybe the bottleneck is _socket.getaddrinfo
Picture 2
profiling in the local machine. Nothing found bottleneck.
Picture 3
Sometimes, even in the remote server, there are no bottleneck found. No _socket.getaddrinfo
found. Weird!
I did profiling in remote server python shell, too, with cProfile
.
Take a look at this:
In [10]: cProfile.run("socket.getaddrinfo('easylib.gdufslib.org', 80, 0, 0, socket.SOL_TCP)")
3 function calls in 8.014 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 8.014 8.014 :1()
1 8.014 8.014 8.014 8.014 {_socket.getaddrinfo}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
In [11]: cProfile.run("socket.getaddrinfo('easylib.gdufslib.org', 80, 0, 0, socket.SOL_TCP)")
3 function calls in 8.009 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 8.009 8.009 :1()
1 8.009 8.009 8.009 8.009 {_socket.getaddrinfo}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
Maybe there is a fact that it takes much time to do some dns resolve
job, and I can't change this myself.
Can any one tell me: why _socket.getaddrinfo
is called and why sometimes not called?
How to prevent the _socket.getaddrinfo
being called? Because it slow down my website which let me down saddly.