Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Performance Python runtime #1232 #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions stable/python/_kubeless.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import queue
import sys

import threading
import bottle
import prometheus_client as prom

Expand Down Expand Up @@ -67,13 +67,6 @@ def __setstate__(self, env):
setattr(self, 'environ', env)


def funcWrap(q, event, c):
try:
q.put(func(event, c))
except Exception as inst:
q.put(inst)


@app.get('/healthz')
def healthz():
return 'OK'
Expand All @@ -85,6 +78,11 @@ def metrics():
return prom.generate_latest(prom.REGISTRY)


@app.error(500)
def exception_handler():
return 'Internal server error'


@app.route('/<:re:.*>', method=['GET', 'POST', 'PATCH', 'DELETE'])
def handler():
req = bottle.request
Expand All @@ -104,21 +102,15 @@ def handler():
func_calls.labels(method).inc()
with func_errors.labels(method).count_exceptions():
with func_hist.labels(method).time():
q = ctx.Queue()
p = ctx.Process(target=funcWrap, args=(q, event, function_context))
p.start()

que = queue.Queue()
t = threading.Thread(target=lambda q, e: q.put(func(e,function_context)), args=(que,event))
t.start()
try:
res = q.get(block=True, timeout=timeout)
res = que.get(block=True, timeout=timeout)
except queue.Empty:
p.terminate()
p.join()
return bottle.HTTPError(408, "Timeout while processing the function")
else:
p.join()
if isinstance(res, Exception) and not isinstance(res, bottle.HTTPResponse):
logging.error("Function returned an exception: %s", res)
raise res
t.join()
return res


Expand Down