Skip to content

Commit

Permalink
add circuit breakers example
Browse files Browse the repository at this point in the history
  • Loading branch information
anggao authored and seldondev committed Apr 27, 2020
1 parent d322f47 commit df61cac
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 1 deletion.
22 changes: 22 additions & 0 deletions doc/source/ingress/ambassador.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ curl -v 0.0.0.0:8003/seldon/mymodel/api/v1.0/predictions -d '{"data":{"names":["
|`seldon.io/ambassador-shadow:true` | Activate shadowing for this deployment |
|`seldon.io/grpc-read-timeout: <gRPC read timeout (msecs)>` | gRPC read timeout |
|`seldon.io/rest-read-timeout:<REST read timeout (msecs)>` | REST read timeout |
|`seldon.io/ambassador-circuit-breakers-max-connections:<maximum number of connections>` | The maximum number of connections will make to the Seldon Deployment |
|`seldon.io/ambassador-circuit-breakers-max-pending-requests:<maximum number of queued requests>` | The maximum number of requests that will be queued while waiting for a connection |
|`seldon.io/ambassador-circuit-breakers-max-requests:<maximum number of parallel outstanding requests>` | The maximum number of parallel outstanding requests to the Seldon Deployment |
|`seldon.io/ambassador-circuit-breakers-max-retries:<maximum number of parallel retries>` | The maximum number of parallel retries allowed to the Seldon Deployment |

All annotations should be placed in `spec.annotations`.

Expand Down Expand Up @@ -119,6 +123,24 @@ A worked example for [header based routing](../examples/ambassador_headers.html)

To understand more about the Ambassador configuration for this see [their docs on header based routing](https://www.getambassador.io/reference/headers).

### Circuit Breakers
By preventing additional connections or requests to an overloaded Seldon Deployment, circuit breakers help improve resilience of your system.

You simply need to add some annotations to your Seldon Deployment resource.

* `seldon.io/ambassador-circuit-breakers-max-connections:<maximum number of connections>` : The maximum number of connections will make to the Seldon Deployment
* Example: `"seldon.io/ambassador-circuit-breakers-max-connections":"200"`
* `seldon.io/ambassador-circuit-breakers-max-pending-requests:<maximum number of queued requests>` : The maximum number of requests that will be queued while waiting for a connection
* Example: `"seldon.io/ambassador-circuit-breakers-max-pending-requests":"100"`
* `seldon.io/ambassador-circuit-breakers-max-requests:<maximum number of parallel outstanding requests>` : The maximum number of parallel outstanding requests to the Seldon Deployment
* Example: `"seldon.io/ambassador-circuit-breakers-max-requests":"200"`
* `seldon.io/ambassador-circuit-breakers-max-retries:<maximum number of parallel retries>` : The maximum number of parallel retries allowed to the Seldon Deployment
* Example: `"seldon.io/ambassador-circuit-breakers-max-retries":"3"`

A worked example for [circuit breakers](../examples/ambassador_circuit_breakers.html) is provided.

To understand more about the Ambassador configuration for this see [their docs on circuit breakers](https://www.getambassador.io/docs/latest/topics/using/circuit-breakers/).

## Multiple Ambassadors in the same cluster

To avoid conflicts in a cluster with multiple ambassadors running, you can add the following annotation to your Seldon Deployment resource.
Expand Down
1 change: 1 addition & 0 deletions examples/ambassador/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
* [Canary deployments](./canary)
* [Shadow deployments](./shadow)
* [Header based routing](./headers)
* [Circuit Breakers](./circuit_breakers)
* [Custom configuration](./custom)
4 changes: 4 additions & 0 deletions examples/ambassador/circuit_breakers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Circuit Breakers with Seldon and Ambassador

Follow the [notebook](ambassador_circuit_breakers.ipynb) to show how you can deploy Seldon Deployments with circuit breakers.

193 changes: 193 additions & 0 deletions examples/ambassador/circuit_breakers/ambassador_circuit_breakers.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Circuit Breakers with Seldon and Ambassador\n",
"\n",
"This notebook shows how you can deploy Seldon Deployments which can have circuit breakers via Ambassador's circuit breakers configuration.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup Seldon Core\n",
"\n",
"Use the setup notebook to [Setup Cluster](../../seldon_core_setup.ipynb#Setup-Cluster) with [Ambassador Ingress](../../seldon_core_setup.ipynb#Ambassador) and [Install Seldon Core](../../seldon_core_setup.ipynb#Install-Seldon-Core). Instructions [also online](./seldon_core_setup.html)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!kubectl create namespace seldon"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!kubectl config set-context $(kubectl config current-context) --namespace=seldon"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Launch main model\n",
"\n",
"We will create a very simple Seldon Deployment with a dummy model image `seldonio/mock_classifier:1.0`. This deployment is named `example`. We will add following circuit breakers configurations.\n",
"\n",
"```\n",
" \"seldon.io/ambassador-circuit-breakers-max-connections\":\"200\",\n",
" \"seldon.io/ambassador-circuit-breakers-max-pending-requests\":\"100\",\n",
" \"seldon.io/ambassador-circuit-breakers-max-requests\":\"200\",\n",
" \"seldon.io/ambassador-circuit-breakers-max-retries\":\"3\"\n",
"```\n",
"\n",
"Where\n",
"\n",
" * `\"seldon.io/ambassador-circuit-breakers-max-connections\":\"200\"` is the maximum number of connections will make to the Seldon Deployment\n",
" * `\"seldon.io/ambassador-circuit-breakers-max-pending-requests\":\"100\"` is the maximum number of requests that will be queued while waiting for a connection\n",
" * `\"seldon.io/ambassador-circuit-breakers-max-requests\":\"200\"` is the maximum number of parallel outstanding requests to the Seldon Deployment\n",
" * `\"seldon.io/ambassador-circuit-breakers-max-retries\":\"3\"` the maximum number of parallel retries allowed to the Seldon Deployment\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pygmentize model_circuit_breakers_ambassador.json"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!kubectl create -f model_circuit_breakers_ambassador.json"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!kubectl rollout status deploy/$(kubectl get deploy -l seldon-deployment-id=production-model-example -o jsonpath='{.items[0].metadata.name}')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Get predictions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from seldon_core.seldon_client import SeldonClient\n",
"sc = SeldonClient(deployment_name=\"example\",namespace=\"seldon\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### REST Request"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"r = sc.predict(gateway=\"ambassador\",transport=\"rest\")\n",
"assert(r.success==True)\n",
"print(r)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!kubectl delete -f model_circuit_breakers_ambassador.json"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"apiVersion": "machinelearning.seldon.io/v1alpha2",
"kind": "SeldonDeployment",
"metadata": {
"labels": {
"app": "seldon"
},
"name": "example"
},
"spec": {
"name": "production-model",
"annotations": {
"seldon.io/ambassador-circuit-breakers-max-connections":"200",
"seldon.io/ambassador-circuit-breakers-max-pending-requests":"100",
"seldon.io/ambassador-circuit-breakers-max-requests":"200",
"seldon.io/ambassador-circuit-breakers-max-retries":"3"
},
"predictors": [
{
"componentSpecs": [{
"spec": {
"containers": [
{
"image": "seldonio/mock_classifier_rest:1.4",
"imagePullPolicy": "IfNotPresent",
"name": "classifier"
}
],
"terminationGracePeriodSeconds": 1
}}
],
"graph":
{
"children": [],
"name": "classifier",
"type": "MODEL",
"endpoint": {
"type": "REST"
}},
"name": "single",
"replicas": 1
}
]
}
}

2 changes: 1 addition & 1 deletion examples/ambassador/custom/ambassador_custom.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"metadata": {},
"outputs": [],
"source": [
"!kubectl rollout status deploy/$(kubectl get deploy -l seldon-deployment-id=example -o jsonpath='{.items[0].metadata.name}')"
"!kubectl rollout status deploy/$(kubectl get deploy -l seldon-deployment-id=production-model-example -o jsonpath='{.items[0].metadata.name}')"
]
},
{
Expand Down

0 comments on commit df61cac

Please sign in to comment.