c++11 - Safe await on function in another process -
tl;dr
how safely await on function execution (takes str , int arguments , doesn't require other context) in separate process?
long story
i have aiohtto.web web api uses boost.python wrapper c++ extension, run under gunicorn (and plan deploy on heroku), tested locust.
about extension: have 1 function non-blocking operation - takes 1 string (and 1 integer timeout management), calculations , returns new string. , every input string, 1 possible output (except timeout, in case, c++ exception must raised , translated boost.python python-compatible one).
in short, handler specific url executes code below:
res = await loop.run_in_executor(executor, func, *args) where executor processpoolexecutor instance, , func -function c++ extension module. (in real project, code in coroutine method of class, , func - it's classmethod executes c++ function , returns result)
error catching
when new request arrives, extract it's post data request.post() , storing it's data instance of custom class named call (because have no idea how name in way). call object contains input data (string), request receiving time , unique id comes request.
then proceeds class named handler (not aiohttp request handler), passes it's input class' method loop.run_in_executor inside. handler has logging system works middleware - reads id , receiving time of every incoming call object , logging message tells either starting execute, executed or in trouble. also, handler have try/except , stores errors inside call object, logging middleware knows error occurred, or output extension had returned
testing
i have unit test creates 256 coroutines code inside , executor have 256 workers , works well.
but when testing locust here comes problem. use 4 gunicorn workers , 4 executor workers kind of testing. @ time application starts return wrong output.
my locust's taskset configured log every fault response available information: output string, error string, input string (that returned application too), id. simulated requests same, id unique every.
the situation better when setting gunicorn's max_requests option 100 requests, failures still come.
interesting thing is, can trigger "wrong output" period stopping , starting locust's test.
i need 100% guarantee web api works expect.
update & solution
just asked teammate review c++ code - problem in global variables. in way, wasn't problem 256 parallel coroutines, gunicorn was.
Comments
Post a Comment