0
我正在使用python發送多個HTTP請求..> 1000個請求在同一時間被異步觸發。但我得到的錯誤:max_clients限制達到,請求排隊龍捲風和過了一段時間我越來越超時錯誤。已達到max_clients限制,請求排隊龍捲風
如何解決這類問題,發送多個http post請求並避免超時?
這裏是我使用的代碼:
class AjaxBatchHandler(basehandler.BaseHandler):
@tornado.gen.coroutine
def post(self):
# just respond with a status, no redirect to login
if not self.get_current_user:
self.set_status(403)
batch = json.loads(self.get_argument("actions").encode('utf-8'))
client = tornado.httpclient.AsyncHTTPClient()
batch_requests = []
for item in batch['actions']:
request = utils.build_request(
self,
action=item['action'].replace("{API}", utils.get_api_baseurl()),
values=item['values'])
batch_requests.append(client.fetch(request))
try:
batch_responses = yield batch_requests
batch_result = dict(results=[])
for result in batch_responses:
batch_result['results'].append(json.loads(result.body))
except tornado.httpclient.HTTPError as e:
batch_result = dict(results=[])
batch_result['results'].append({"Status": 500,
"StatusMsg": e.message,
"Error": e.code
})
self.write(batch_result)
通過發送大量的異步調用一次,很多我的意思是10.000例如,比增加max_clients ist沒有解決問題。 但我會仔細看看隊列。但是我現在解決了這個問題。我使用ajax調用將每個調用異步發送,並收集響應,當所有響應都在那裏時,我顯示結果。我注意到這是一個較慢的過程,但沒有超時工作。 – Monicka