{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ca45b3d6",
   "metadata": {},
   "source": [
    "# Autoscaling\n",
    "\n",
    "Autoscaling allows the user to define how many engines a pipeline starts with, the minimum amount of engines a pipeline can be using, and the maximum amount of engines a pipeline can scale up to. The pipeline scales up and down based on the average CPU utilization across the engines in a given pipeline as the user's workload increases and decreases."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "731e0efb",
   "metadata": {},
   "source": [
    "## Example\n",
    "\n",
    "Autoscaling is configured through the deployment configuration for a pipeline.\n",
    "\n",
    "`replica_count` sets the initial amount of engines for the pipeline. This defaults to `1`\n",
    "\n",
    "`replica_autoscale_min_max` sets the minimum number of engines and the maximum amount of engines. The lowest minimum is current `1`. This is also the default. The `maximum` parameter must be set by the user.\n",
    "\n",
    "`autoscale_cpu_utilization` is set as an integer representing the average CPU utilization. The default value is `50`, which represents an average of 50% CPU utilization for the engines in a pipeline."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20634e67",
   "metadata": {},
   "outputs": [],
   "source": [
    "import wallaroo\n",
    "\n",
    "wl = wallaroo.Client(auth_type=\"sso\")\n",
    "\n",
    "dc = (wallaroo.DeploymentConfigBuilder()\n",
    "    .replica_count(1)\n",
    "    .replica_autoscale_min_max(minimum=2, maximum=5)\n",
    "    .autoscale_cpu_utilization(60)\n",
    "    .build())\n",
    "\n",
    "model = wl.upload_model(\"cc-fraud\", \"keras_ccfraud.onnx\").deploy(\"fraud\", deployment_config=dc)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.8.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
