From 76e96f978e474d3c37fb15be9d7e6bf98e38d2cc Mon Sep 17 00:00:00 2001 From: Ciro Date: Sun, 6 Nov 2022 07:06:00 -0300 Subject: [PATCH] relax performance cpu test --- examples/docker/pypy3/requirements.txt | 2 +- examples/docker/python3-alpine/requirements.txt | 2 +- examples/docker/python3/requirements.txt | 2 +- src/socketify/loop.py | 8 ++++++-- src/socketify/socketify.py | 3 --- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/docker/pypy3/requirements.txt b/examples/docker/pypy3/requirements.txt index 9ea1426..7a22543 100644 --- a/examples/docker/pypy3/requirements.txt +++ b/examples/docker/pypy3/requirements.txt @@ -1 +1 @@ -git+https://github.com/cirospaciari/socketify.py.git@main#socketify --global-option="build_ext" \ No newline at end of file +git+https://github.com/cirospaciari/socketify.py.git@main#socketify \ No newline at end of file diff --git a/examples/docker/python3-alpine/requirements.txt b/examples/docker/python3-alpine/requirements.txt index 9ea1426..7a22543 100644 --- a/examples/docker/python3-alpine/requirements.txt +++ b/examples/docker/python3-alpine/requirements.txt @@ -1 +1 @@ -git+https://github.com/cirospaciari/socketify.py.git@main#socketify --global-option="build_ext" \ No newline at end of file +git+https://github.com/cirospaciari/socketify.py.git@main#socketify \ No newline at end of file diff --git a/examples/docker/python3/requirements.txt b/examples/docker/python3/requirements.txt index 9ea1426..7a22543 100644 --- a/examples/docker/python3/requirements.txt +++ b/examples/docker/python3/requirements.txt @@ -1 +1 @@ -git+https://github.com/cirospaciari/socketify.py.git@main#socketify --global-option="build_ext" \ No newline at end of file +git+https://github.com/cirospaciari/socketify.py.git@main#socketify \ No newline at end of file diff --git a/src/socketify/loop.py b/src/socketify/loop.py index ba51780..c45d4f9 100644 --- a/src/socketify/loop.py +++ b/src/socketify/loop.py @@ -39,6 +39,7 @@ class Loop: asyncio.set_event_loop(self.loop) self.started = False self.last_defer = False + self.last_run = 0 def set_timeout(self, timeout, callback, user_data): return self.uv_loop.create_timer(timeout, 0, callback, user_data) @@ -58,8 +59,11 @@ class Loop: (callback, user_data) = loop.queue.get(False) callback(user_data) loop.queue.task_done() - #run once asyncio - loop.run_once_asyncio() + #run once asyncio if has some current task running or relax CPU + if not asyncio.current_task(loop.loop) is None or self.last_run >= 100: + loop.run_once_asyncio() + self.last_run = 0 + self.last_run = self.last_run + 1 #use check for calling asyncio once per tick self.timer = self.uv_loop.create_timer(0, 1, tick, self) # self.timer = self.uv_loop.create_check(tick, self) diff --git a/src/socketify/socketify.py b/src/socketify/socketify.py index e2f9c41..96839ba 100644 --- a/src/socketify/socketify.py +++ b/src/socketify/socketify.py @@ -595,8 +595,6 @@ class AppResponse: return None #invalid json - - def send_chunk(self, buffer, total_size): self._chunkFuture = self.loop.create_future() self._lastChunkOffset = 0 @@ -604,7 +602,6 @@ class AppResponse: def is_aborted(self): self.aborted = True try: - print("aborted!", self._chunkFuture.done()) if not self._chunkFuture.done(): self._chunkFuture.set_result((False, True)) #if aborted set to done True and ok False except: