Skip to content

Commit

Permalink
avoid preload_content when checking quotas
Browse files Browse the repository at this point in the history
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
  • Loading branch information
minrk committed Mar 10, 2021
1 parent f028ffe commit 7fc6e48
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions binderhub/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7fc6e48

Please sign in to comment.