Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

Commit a58583d

Browse files
matheritmseth10
andauthored
Add gunicorn timeout (#220)
* Add env var that will manage GUnicorn setup timeout. * Ensure env var is treated as innt. * Update readme to include new env var section and update TOC. * Add SAGEMAKER_GUNICORN_LOGLEVEL description to readme. * expose gunicorn logging (#219) * Add in SAGEMAKER_GUNICORN_TIMEOUT_SECONDS. * Update readme with PR feedback. * Remove extra argument in format. * Remove setup timeout. * Make readme links clickable. * Remove boiler plate statements and instead link in descriptive comment of var. * Update capitalization of Gunicorn. Co-authored-by: Manu Seth <[email protected]>
1 parent 387ae61 commit a58583d

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ For notebook examples, see: [Amazon SageMaker Examples](https://github.com/awsla
4242
3. [Running the tests](#running-the-tests)
4343
4. [Pre/Post-Processing](#pre/post-processing)
4444
5. [Deploying a TensorFlow Serving Model](#deploying-a-tensorflow-serving-model)
45-
6. [Deploying to Multi-Model Endpoint](#deploying-to-multi-model-endpoint)
45+
6. [Enable Batching](#enabling-batching)
46+
7. [Configurable SageMaker Environment Variables](#configurable-sagemaker-environment-variables)
47+
8. [Deploying to Multi-Model Endpoint](#deploying-to-multi-model-endpoint)
4648

4749
## Getting Started
4850

@@ -612,6 +614,22 @@ SAGEMAKER_TFS_NUM_BATCH_THREADS="16"
612614
SAGEMAKER_TFS_MAX_ENQUEUED_BATCHES="10000"
613615
```
614616

617+
## Configurable SageMaker Environment Variables
618+
The following environment variables can be set on a SageMaker Model or Transform Job if further configuration is required:
619+
620+
[Configures](https://docs.gunicorn.org/en/stable/settings.html#loglevel)
621+
the logging level for Gunicorn.
622+
```bash
623+
# Defaults to "info"
624+
SAGEMAKER_GUNICORN_LOGLEVEL="debug"
625+
```
626+
[Configures](https://docs.gunicorn.org/en/stable/settings.html#timeout)
627+
how long a Gunicorn worker may be silent before it is killed and restarted.
628+
```bash
629+
# Defaults to 30.
630+
SAGEMAKER_GUNICORN_TIMEOUT_SECONDS="60"
631+
```
632+
615633
## Deploying to Multi-Model Endpoint
616634

617635
SageMaker TensorFlow Serving container (version 1.5.0 and 2.1.0, CPU) now supports Multi-Model Endpoint. With this feature, you can deploy different models (not just different versions of a model) to a single endpoint.

docker/build_artifacts/sagemaker/serve.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def __init__(self):
6464
self._tfs_inter_op_parallelism = os.environ.get("SAGEMAKER_TFS_INTER_OP_PARALLELISM", 0)
6565
self._tfs_intra_op_parallelism = os.environ.get("SAGEMAKER_TFS_INTRA_OP_PARALLELISM", 0)
6666
self._gunicorn_worker_class = os.environ.get("SAGEMAKER_GUNICORN_WORKER_CLASS", "gevent")
67+
self._gunicorn_timeout_seconds = int(
68+
os.environ.get("SAGEMAKER_GUNICORN_TIMEOUT_SECONDS", 30)
69+
)
6770

6871
if os.environ.get("OMP_NUM_THREADS") is None:
6972
os.environ["OMP_NUM_THREADS"] = "1"
@@ -202,7 +205,7 @@ def _setup_gunicorn(self):
202205

203206
gunicorn_command = (
204207
"gunicorn -b unix:/tmp/gunicorn.sock -k {} --chdir /sagemaker "
205-
"--workers {} --threads {} --log-level {} "
208+
"--workers {} --threads {} --log-level {} --timeout {} "
206209
"{}{} -e TFS_GRPC_PORTS={} -e TFS_REST_PORTS={} "
207210
"-e SAGEMAKER_MULTI_MODEL={} -e SAGEMAKER_SAFE_PORT_RANGE={} "
208211
"-e SAGEMAKER_TFS_WAIT_TIME_SECONDS={} "
@@ -212,6 +215,7 @@ def _setup_gunicorn(self):
212215
self._gunicorn_workers,
213216
self._gunicorn_threads,
214217
self._gunicorn_loglevel,
218+
self._gunicorn_timeout_seconds,
215219
python_path_option,
216220
",".join(python_path_content),
217221
self._tfs_grpc_concat_ports,
@@ -451,7 +455,7 @@ def start(self):
451455
self._setup_gunicorn()
452456
self._start_gunicorn()
453457
# make sure gunicorn is up
454-
with self._timeout(seconds=30):
458+
with self._timeout(seconds=self._gunicorn_timeout_seconds):
455459
self._wait_for_gunicorn()
456460

457461
self._start_nginx()

0 commit comments

Comments
 (0)