|
| 1 | +# Speed up your Coder templates and workspaces |
| 2 | + |
| 3 | +October 31, 2024 |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +If it takes your workspace a long time to start, find out why and make some |
| 8 | +changes to your Coder templates to help speed things up. |
| 9 | + |
| 10 | +## Monitoring |
| 11 | + |
| 12 | +You can monitor [Coder logs](../../admin/monitoring/logs.md) through the |
| 13 | +system-native tools on your deployment platform, or stream logs to tools like |
| 14 | +Splunk, Datadog, Grafana Loki, and others. |
| 15 | + |
| 16 | +### Workspace build timeline |
| 17 | + |
| 18 | +Use the **Build timeline** to monitor the time it takes to start specific |
| 19 | +workspaces. Identify long scripts, resources, and other things you can |
| 20 | +potentially optimize within the template. |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +Adjust this request to match your Coder access URL and workspace: |
| 25 | + |
| 26 | +```shell |
| 27 | +curl -X GET https://coder.example.com/api/v2/workspacebuilds/{workspacebuild}/timings \ |
| 28 | + -H 'Accept: application/json' \ |
| 29 | + -H 'Coder-Session-Token: API_KEY' |
| 30 | +``` |
| 31 | + |
| 32 | +Visit the |
| 33 | +[API documentation](../../reference/api/builds.md#get-workspace-build-timings-by-id) |
| 34 | +for more information. |
| 35 | + |
| 36 | +### Coder Observability Chart |
| 37 | + |
| 38 | +Use the [Observability Helm chart](https://github.com/coder/observability) for a |
| 39 | +pre-built set of dashboards to monitor your control plane over time. It includes |
| 40 | +Grafana, Prometheus, Loki, and Alert Manager out-of-the-box, and can be deployed |
| 41 | +on your existing Grafana instance. |
| 42 | + |
| 43 | +We recommend that all administrators deploying on Kubernetes or on an existing |
| 44 | +Prometheus or Grafana stack set the observability bundle up with the control |
| 45 | +plane from the start. For installation instructions, visit the |
| 46 | +[observability repository](https://github.com/coder/observability?tab=readme-ov-file#installation), |
| 47 | +or our [Kubernetes installation guide](../../install/kubernetes.md). |
| 48 | + |
| 49 | +### Enable Prometheus metrics for Coder |
| 50 | + |
| 51 | +[Prometheus.io](https://prometheus.io/docs/introduction/overview/#what-is-prometheus) |
| 52 | +is included as part of the [observability chart](#coder-observability-chart). It |
| 53 | +offers a variety of |
| 54 | +[available metrics](../../admin/integrations/prometheus.md#available-metrics), |
| 55 | +such as `coderd_provisionerd_job_timings_seconds` and |
| 56 | +`coderd_agentstats_startup_script_seconds`, which measure how long the workspace |
| 57 | +takes to provision and how long the startup script takes. |
| 58 | + |
| 59 | +You can |
| 60 | +[install it separately](https://prometheus.io/docs/prometheus/latest/getting_started/) |
| 61 | +if you prefer. |
| 62 | + |
| 63 | +## Provisioners |
| 64 | + |
| 65 | +`coder server` defaults to three provisioner daemons. Each provisioner daemon |
| 66 | +can handle one single job, such as start, stop, or delete at a time and can be |
| 67 | +resource intensive. When all provisioners are busy, workspaces enter a "pending" |
| 68 | +state until a provisioner becomes available. |
| 69 | + |
| 70 | +### Increase provisioner daemons |
| 71 | + |
| 72 | +Provisioners are queue-based to reduce unpredictable load to the Coder server. |
| 73 | +However, they can be scaled up to allow more concurrent provisioners. You risk |
| 74 | +overloading the central Coder server if you use too many built-in provisioners, |
| 75 | +so we recommend a maximum of five provisioners. For more than five provisioners, |
| 76 | +we recommend that you move to |
| 77 | +[external provisioners](../../admin/provisioners.md). |
| 78 | + |
| 79 | +If you can’t move to external provisioners, use the `provisioner-daemons` flag |
| 80 | +to increase the number of provisioner daemons to five: |
| 81 | + |
| 82 | +```shell |
| 83 | +coder server --provisioner-daemons=5 |
| 84 | +``` |
| 85 | + |
| 86 | +Visit the |
| 87 | +[CLI documentation](../../reference/cli/server.md#--provisioner-daemons) for |
| 88 | +more information about increasing provisioner daemons, configuring external |
| 89 | +provisioners, and other options. |
| 90 | + |
| 91 | +### Adjust provisioner CPU/memory |
| 92 | + |
| 93 | +We recommend that you deploy Coder to its own respective Kubernetes cluster, |
| 94 | +separate from production applications. Keep in mind that Coder runs development |
| 95 | +workloads, so the cluster should be deployed as such, without production-level |
| 96 | +configurations. |
| 97 | + |
| 98 | +Adjust the CPU and memory values as shown in |
| 99 | +[Helm provisioner values.yaml](https://github.com/coder/coder/blob/main/helm/provisioner/values.yaml#L134-L141): |
| 100 | + |
| 101 | +```yaml |
| 102 | +… |
| 103 | + resources: |
| 104 | + limits: |
| 105 | + cpu: "0.25" |
| 106 | + memory: "1Gi" |
| 107 | + requests: |
| 108 | + cpu: "0.25" |
| 109 | + memory: "1Gi" |
| 110 | +… |
| 111 | +``` |
| 112 | + |
| 113 | +Visit the |
| 114 | +[validated architecture documentation](../../admin/infrastructure/validated-architectures/index.md#workspace-nodes) |
| 115 | +for more information. |
| 116 | + |
| 117 | +## Set up Terraform provider caching |
| 118 | + |
| 119 | +By default, Coder downloads each Terraform provider when a workspace starts. |
| 120 | +This can create unnecessary network and disk I/O. |
| 121 | + |
| 122 | +`terraform init` generates a `.terraform.lock.hcl` which instructs Coder |
| 123 | +provisioners to cache specific versions of your providers. |
| 124 | + |
| 125 | +To use `terraform init` to cache providers: |
| 126 | + |
| 127 | +1. Pull the templates to your local device: |
| 128 | + |
| 129 | + ```shell |
| 130 | + coder templates pull |
| 131 | + ``` |
| 132 | + |
| 133 | +1. Run `terraform init` to initialize the directory: |
| 134 | + |
| 135 | + ```shell |
| 136 | + terraform init |
| 137 | + ``` |
| 138 | + |
| 139 | +1. Push the templates back to your Coder deployment: |
| 140 | + |
| 141 | + ```shell |
| 142 | + coder templates push |
| 143 | + ``` |
0 commit comments