From 7fc6e4842cf23c9d699a99791b8b0e0fa3893534 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 10 Mar 2021 08:44:41 +0100 Subject: [PATCH] avoid preload_content when checking quotas this request lists all user pods and can take a long time when there are a lot of users this should dramatically reduce cpu load with lots of user pods --- binderhub/builder.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/binderhub/builder.py b/binderhub/builder.py index 7f99708cb..8998aad95 100644 --- a/binderhub/builder.py +++ b/binderhub/builder.py @@ -2,6 +2,7 @@ Handlers for working with version control services (i.e. GitHub) for builds. """ +import asyncio import hashlib from http.client import responses import json @@ -10,7 +11,6 @@ import escapism import docker -from tornado.concurrent import chain_future, Future from tornado import gen from tornado.httpclient import HTTPClientError from tornado.web import Finish, authenticated @@ -485,19 +485,16 @@ async def launch(self, kube, provider): self.settings["build_namespace"], label_selector='app=jupyterhub,component=singleuser-server', _request_timeout=KUBE_REQUEST_TIMEOUT, + _preload_content=False, ) - # concurrent.futures.Future isn't awaitable - # wrap in tornado Future - # tornado 5 will have `.run_in_executor` - tf = Future() - chain_future(f, tf) - pods = await tf - for pod in pods.items: + resp = await asyncio.wrap_future(f) + pods = json.loads(resp.read()) + for pod in pods["items"]: total_pods += 1 - for container in pod.spec.containers: + for container in pod["spec"]["containers"]: # is the container running the same image as us? # if so, count one for the current repo. - image = container.image.rsplit(':', 1)[0] + image = container["image"].rsplit(":", 1)[0] if image == image_no_tag: matching_pods += 1 break