I have a simple flask server defined like so:
import sys
import flask
from flask import request
app = flask.Flask(__name__)
port = 4057
@app.route('/search', methods=['POST'])
def search():
request.json['query']
results = ['fake', 'data']
return flask.jsonify(results)
if __name__ == '__main__':
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.run(host='0.0.0.0', port=port, debug=(port != 80))
I have a simple client defined like this:
import json
import requests
headers = {'content-type': 'application/json'}
resp = requests.post('http://localhost:4057/search', json.dumps({'query': 'foo'}), headers=headers)
print resp.content
The client works, but it takes like 3 seconds to complete the request.
curl completes in like half a second:
curl 'http://localhost:4057/search' -H 'Content-Type: application/json' -d '{"query": "foo"}'
threaded=True
in theapp.run()
? – Tollimport requests
and Python's start up. – Unifoliolateimport requests
andprint "foo"
it's < .5 seconds. – Laagerrequests
import takes considerable amount of time. – Telegramcurl
would also be slow, no? – Laager127.0.0.1
? maybe some odd resolution. – Catharinecatharsislocalhost
), for me it took on average ~110 MS
– Fussell'0.0.0.0'
connects server to all network cards in computer, not only127.0.0.1
but alsoWi-Fi
and wired connection. – Heisenberg