-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlaunch.sh
executable file
·52 lines (44 loc) · 2.08 KB
/
launch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Currently so don't have to rebuild docker machines; see
# https://github.com/dask/dask-docker/pull/108
# TODO: _NPROCESSORS_ONLN==1 for github actions. Leads to index error on
# backend, not enough workers.
export NUM_PROCS=$(getconf _NPROCESSORS_ONLN)
export SALMON_NPROC=$(python -c "print(max(4, $NUM_PROCS))")
# chose nthreads=1 because best practice [1]
# [1]: https://docs.dask.org/en/latest/array-best-practices.html#avoid-oversubscribing-threads
export OMP_NUM_THREADS=1
export MKL_NUM_THREADS=1
export OPENBLAS_NUM_THREADS=1
dask-scheduler --host 127.0.0.2 --port 8786 --dashboard-address :8787 &
dask-worker --nprocs $SALMON_NPROC --nthreads 1 127.0.0.2:8786 &
if [ $SALMON_DEBUG ]
then
# export SALMON_DEBUG=1 or export SALMON_DEBUG=0
export LOG_LEVEL=INFO
echo "Launching uvicorn..."
uvicorn salmon:app_algs --reload --reload-dir salmon --port 8400 --host 0.0.0.0 &
sleep 1
uvicorn salmon:app --reload --reload-dir salmon --reload-dir templates --port 8421 --host 0.0.0.0
else
# unset SALMON_DEBUG if already set in enviroment
#
# Use shared memory for Gunicorn; apparelty can block on AWS
# [1]:https://pythonspeed.com/articles/gunicorn-in-docker/
#
# Set timeout=90 so Gunicorn checks less frequently.
# Use preload to reduce startup time
# Use 2 threads to heartbeat gets sent more often
echo "Launching gunicorn..."
export LOG_LEVEL=WARNING
## Use uvicorn instead of gunicorn because FastAPI's background tasks are threads
## in uvicorn, not processes.
##
## Only use one worker because some global state for sampler.get_query
# (not a huge issue because this server is mostly a proxy for Dask)
# (this breaks down if get_query is relied upon)
uvicorn salmon:app_algs --workers 1 --port 8400 --host 0.0.0.0 &
# gunicorn --preload --worker-tmp-dir /dev/shm --threads 2 --timeout 90 -w 1 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8400 salmon:app_algs &
sleep 1
gunicorn --worker-tmp-dir /dev/shm --threads 2 --timeout 90 -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8421 salmon:app
fi