Skip to content

Commit 7fc6e48

Browse files
committed
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
1 parent f028ffe commit 7fc6e48

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

binderhub/builder.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Handlers for working with version control services (i.e. GitHub) for builds.
33
"""
44

5+
import asyncio
56
import hashlib
67
from http.client import responses
78
import json
@@ -10,7 +11,6 @@
1011
import escapism
1112

1213
import docker
13-
from tornado.concurrent import chain_future, Future
1414
from tornado import gen
1515
from tornado.httpclient import HTTPClientError
1616
from tornado.web import Finish, authenticated
@@ -485,19 +485,16 @@ async def launch(self, kube, provider):
485485
self.settings["build_namespace"],
486486
label_selector='app=jupyterhub,component=singleuser-server',
487487
_request_timeout=KUBE_REQUEST_TIMEOUT,
488+
_preload_content=False,
488489
)
489-
# concurrent.futures.Future isn't awaitable
490-
# wrap in tornado Future
491-
# tornado 5 will have `.run_in_executor`
492-
tf = Future()
493-
chain_future(f, tf)
494-
pods = await tf
495-
for pod in pods.items:
490+
resp = await asyncio.wrap_future(f)
491+
pods = json.loads(resp.read())
492+
for pod in pods["items"]:
496493
total_pods += 1
497-
for container in pod.spec.containers:
494+
for container in pod["spec"]["containers"]:
498495
# is the container running the same image as us?
499496
# if so, count one for the current repo.
500-
image = container.image.rsplit(':', 1)[0]
497+
image = container["image"].rsplit(":", 1)[0]
501498
if image == image_no_tag:
502499
matching_pods += 1
503500
break

0 commit comments

Comments
 (0)