|
20 | 20 |
|
21 | 21 | DEBUG_LEVEL = ["Critical", "Error"]
|
22 | 22 |
|
23 |
| - |
24 | 23 | storage = threading.local()
|
25 | 24 | servers = dict()
|
26 | 25 | server_lock = threading.Lock()
|
| 26 | +requests_lock = threading.Lock() |
| 27 | +request = None |
| 28 | + |
| 29 | +def init_requests(): |
| 30 | + global request |
| 31 | + with requests_lock: |
| 32 | + if request == None: |
| 33 | + request = requests.Session() |
| 34 | + adapter = requests.adapters.HTTPAdapter( |
| 35 | + pool_connections=1000, |
| 36 | + pool_maxsize=1000, |
| 37 | + max_retries=10, |
| 38 | + pool_block=True) |
| 39 | + request.mount('http://', adapter) |
| 40 | + |
| 41 | +init_requests() |
| 42 | + |
27 | 43 |
|
28 | 44 | def del_instance():
|
29 | 45 | instance = getattr(storage, 'instance', None)
|
@@ -282,20 +298,21 @@ def __exit__(self):
|
282 | 298 | self.server.terminate()
|
283 | 299 | self.temp.close()
|
284 | 300 |
|
285 |
| - def call(self, data): |
286 |
| - def dumps(dic): |
287 |
| - self.last_id += 1 |
288 |
| - dic['id'] = Id(self.last_id) |
289 |
| - return json.dumps(dic, default=str) |
| 301 | + def dumps(self,dic): |
| 302 | + self.last_id += 1 |
| 303 | + dic['id'] = Id(self.last_id) |
| 304 | + return json.dumps(dic, default=str) |
290 | 305 |
|
| 306 | + def call(self, data): |
291 | 307 | if isinstance(data, dict):
|
292 |
| - method = requests.post |
| 308 | + method = request.post |
293 | 309 | if 'get_insns' or 'get_resource' in data:
|
294 |
| - method = requests.get |
295 |
| - return jsons(method(self.url, data=dumps(data))) |
| 310 | + method = request.get |
| 311 | + return jsons(method(self.url, data=self.dumps(data))) |
296 | 312 | else:
|
297 |
| - gen = (dumps(msg) for msg in data) |
298 |
| - return jsons(requests.post(self.uri, data=gen)) |
| 313 | + gen = (self.dumps(msg) for msg in data) |
| 314 | + return jsons(request.post(self.uri, data=gen)) |
| 315 | + |
299 | 316 |
|
300 | 317 | def mmap(self, data):
|
301 | 318 | url = "mmap://{0}?offset=0&length={1}".format(
|
|
0 commit comments