From 65b469ed9ed61ec5f6ef1a6f0b02534160a421a1 Mon Sep 17 00:00:00 2001 From: RamanjaneyuluIdavalapati Date: Fri, 11 May 2018 12:25:42 +0530 Subject: [PATCH] multiprocessing removed and concurrent futures is used to support bulk queries --- .travis.yml | 4 ++-- kwikapi/tornado/kwikapi_tornado.py | 32 +++++++++++++++++++++++++----- setup.py | 5 +++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2a61938..a36901d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,8 @@ deploy: skip_cleanup: true api_key: secure: 3wIm6vrNmdIP50NIUtig33S34FonRqxGnRRY55oiMN4BD5xeo2iQb8TmWMswwqVTuO09C3Cd7kBxP5JxBR+dCuVZZRqpL/8E6JUTaGyZcQ/9HgB8FwYXRCj2ASPDHfmjmZ8F3GIX19akJLKiTThB1WU3XidcZ9tZgwvOmf10Jy7IXiddRKwucVVVy608H9hUXPpIVMzqcFfeU2KeXcotU0J2eZyqso/RCPNw4qDZKFvkiKT2MM4B6FgY7WYorNUW1JXdh8dcAV7vb0oNB0iUNLMCpNHFqoyfOHcxKUgP81wMS8TY5wWLuQxUESg1eyo7Q9gwegOseySU1NBjlPyltVVWtulltM2sge0KgVoLgQRia/LeKnCynSi2r8aic1VoMUDEH5ZfWuJJrFHOJyKCNapp3MKK42UXDo28NpdjjUUgJOOukWpXsaVmPhPXpWWQlZM9YMeMPxTUpm3ZACs2WmHssVwO7EaTaJ45ctAf4m0csb7Ri5IyR5iLy9YEX6fuNMoNVCI6lE7ax38pf1mkgamZTJtvEFr+ekKMXq3heVk598rA2P7hzI5Z6Zx7S8GyQz4vveSTk/pY3StX1ScU3ULnLQaEjP1LVI3pu6R5w7PdQ+Ew6fPmU7RpD8rZPKfFoBcby1mf2Mb/HNk8jXPTHTmyTKBB+othHHg4BWM3Kuw= - name: kwikapi.tornado-0.2.1 - tag_name: 0.2.1 + name: kwikapi.tornado-0.2.2 + tag_name: 0.2.2 on: repo: deep-compute/kwikapi.tornado - provider: pypi diff --git a/kwikapi/tornado/kwikapi_tornado.py b/kwikapi/tornado/kwikapi_tornado.py index 93013cf..6d2d00f 100644 --- a/kwikapi/tornado/kwikapi_tornado.py +++ b/kwikapi/tornado/kwikapi_tornado.py @@ -1,8 +1,13 @@ # -*- coding: utf-8 -* from tornado.web import RequestHandler as TornadoRequestHandler +from tornado.web import asynchronous from kwikapi import BaseRequest, BaseResponse, BaseRequestHandler +from deeputil import Dummy + +DUMMY_LOG = Dummy() + class TornadoRequest(BaseRequest): def __init__(self, req_hdlr): @@ -33,7 +38,7 @@ def __init__(self, req_hdlr): self.headers = {} def write(self, data, proto, stream=False): - super().write(data, proto, stream=stream) + n, t = super().write(data, proto, stream=stream) for k, v in self.headers.items(): self._req_hdlr.set_header(k, v) @@ -42,11 +47,13 @@ def write(self, data, proto, stream=False): if not stream: self._req_hdlr.write(d) - return + return n, t for x in d: self._req_hdlr.write(x) + return n, t + def flush(self): self._req_hdlr.flush() @@ -54,14 +61,29 @@ def close(self): self._req_hdlr.finish() class RequestHandler(TornadoRequestHandler): + PROTOCOL = BaseRequestHandler.DEFAULT_PROTOCOL + def __init__(self, *args, **kwargs): - api = kwargs.pop('api') + self.api = kwargs.pop('api') + self.log = kwargs.pop('log', DUMMY_LOG) default_version = kwargs.pop('default_version', None) - self.kwik_req_hdlr = BaseRequestHandler(api, default_version) + default_protocol = kwargs.pop('default_protocol', self.PROTOCOL) + self.kwik_req_hdlr = BaseRequestHandler(self.api, + default_version, default_protocol, log=self.log) super().__init__(*args, **kwargs) + @asynchronous def _handle(self): - self.kwik_req_hdlr.handle_request(TornadoRequest(self)) + threadpool = self.api.threadpool + + def fn(): + self.kwik_req_hdlr.handle_request(TornadoRequest(self)) + self.finish() + + if threadpool: + threadpool.submit(fn) + else: + fn() get = post = _handle diff --git a/setup.py b/setup.py index 3501361..8c6a38e 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages # https://docs.djangoproject.com/en/1.11/intro/reusable-apps/ -version = '0.2.1' +version = '0.2.2' setup( name="kwikapi-tornado", version=version, @@ -14,7 +14,8 @@ author='Deep Compute, LLC', author_email='contact@deepcompute.com', install_requires=[ - 'tornado==4.5.3', + 'tornado==4.5.3', + 'deeputil==0.2.5', ], classifiers=[ 'Environment :: Web Environment',