Created
August 21, 2023 14:25
-
-
Save minrk/97835eb282bc243ffd37ad68373e0d86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:22.04 | |
RUN apt-get update && apt-get -y install python3-pip nodejs npm | |
RUN python3 -m pip install jupyterhub jupyter-server | |
RUN npm install --global configurable-http-proxy | |
WORKDIR /tmp | |
ENV HOME=/tmp | |
USER 1000 | |
RUN dd if=/dev/random of=10mb.bin bs=1024 count=10240 | |
COPY jupyter_server_config.py /etc/jupyter/jupyter_server_config.py | |
COPY launch.sh /usr/local/bin/ | |
CMD ["/usr/bin/bash", "/usr/local/bin/launch.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
download a 10mb file from | |
Default: assumes container built and run with: | |
``` | |
docker build -t test . | |
docker run --rm -it -p9000:9000 -p8000:8000 test | |
``` | |
""" | |
import time | |
import sys | |
import requests | |
token = "abcxyz" | |
def download_file(base_url, filename): | |
base_url = base_url.rstrip("/") | |
tic = time.perf_counter() | |
r = requests.get(base_url + f"/files/{filename}?download=1", headers={"Authorization": f"Bearer {token}"}, allow_redirects=False, stream=True) | |
assert r.status_code == 200 | |
r.raise_for_status() | |
print(r.url) | |
nbytes = 0 | |
for chunk in r.iter_content(65535): | |
nbytes += len(chunk) | |
toc = time.perf_counter() | |
MB = nbytes * 1e-6 | |
MBps = MB / (toc - tic) | |
print(f"{MBps:6.1f} MB/s ({MB:.0f}MB) - {base_url}: {filename}") | |
if __name__ == "__main__": | |
if len(sys.argv) > 1: | |
host = sys.argv[1] | |
else: | |
host = "http://127.0.0.1" | |
# port 8000 is CHP, 9000 is direct to jupyter-server | |
for port in (8000, 9000): | |
base_url = f"{host}:{port}" | |
for filename in ["10mb.bin"]: | |
download_file(base_url, filename) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c.ServerApp.token = 'abcxyz' | |
c.ServerApp.port = 9000 | |
c.ServerApp.ip = "0.0.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
jupyter-server & | |
exec configurable-http-proxy --default-target http://127.0.0.1:9000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment