Skip to content

Commit 10b9051

Browse files
authored
docs(nx-cloud): improve nx agents feature page (#27606)
1 parent e516fd1 commit 10b9051

File tree

3 files changed

+76
-46
lines changed

3 files changed

+76
-46
lines changed

docs/blog/2024-03-20-why-speed-matters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ With Nx Replay, you can see significant speed improvements in your CI pipelines
5454

5555
[Nx Agents](/ci/features/distribute-task-execution) represent the pinnacle of task distribution optimization, ensuring that tasks are executed as efficiently as possible based on the specific requirements of each change. Some features that make up this effort are:
5656

57-
- [Easy integration with existing providers](/ci/features/distribute-task-execution#cicd-guides)
57+
- [Easy integration with existing providers](/ci/recipes/set-up)
5858
- Distribution is handled on the Nx Cloud infrastructure and all you need is a single line. What’s more, all results are played back to your original CI provider script which triggers the Nx Cloud distribution, so that you can make use of the resulting artifacts
5959
- [Efficient task distribution](/ci/features/dynamic-agents)
6060
- Save compute resources and reduce costs, minimizing idle time and compute waste

docs/shared/features/distribute-task-execution.md

Lines changed: 75 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,95 @@
33
{% youtube
44
src="https://youtu.be/XS-exYYP_Gg"
55
title="Nx Agents Walkthrough"
6-
/%}
6+
/%}
77

8-
**Nx Agents** let you distribute your CI across many machines with minimal configuration. It also comes with the following features:
8+
Nx Agents is a **distributed task execution system that intelligently allocates tasks across multiple machines**, optimizing your CI pipeline for speed and efficiency. While using [Nx Affected](/ci/features/affected) and [remote caching (Nx Replay)](/ci/features/remote-cache) can significantly speed up your CI pipeline, you might still encounter bottlenecks as your codebase scales. Combining affected runs and remote caching with task distribution is key to maintaining low CI times. Nx Agents handles this distribution efficiently, avoiding the complexity and maintenance required if you were to set it up manually.
99

10-
- [Dynamically allocate the number and size of agents](/ci/features/dynamic-agents) based on the size of the PR
11-
- [Re-run flaky tasks](/ci/features/flaky-tasks) automatically whenever they fail in CI
12-
- Automatically [split large e2e tasks](/ci/features/split-e2e-tasks) into smaller tasks that can be distributed more efficiently
10+
![Nx Cloud visualization of how tasks are being distributed with Nx Agents](/shared/features/nx-agents-live-chart.avif)
1311

14-
## Making a Distributed CI Pipeline Is Hard
12+
Nx Agents offer several key advantages:
1513

16-
The only way to speed up your CI pipeline while still running all the necessary tasks is to distribute those tasks across multiple machines. Unfortunately, doing distribution right is hard to set up and hard to maintain. These are just some concerns you have to account for:
14+
- **Declarative Configuration:** No maintenance is required as your monorepo evolves, thanks to a declarative setup.
15+
- **Efficient Task Replay:** By leveraging [remote caching](/ci/features/remote-cache), tasks can be replayed efficiently across machines, enhancing distribution speed.
16+
- **Intelligent Task Distribution:** Tasks are distributed based on historical run times and dependencies, ensuring correct and optimal execution.
17+
- **Dynamic Resource Allocation:** Agents are [allocated dynamically based on the size of the PR](/ci/features/dynamic-agents), balancing cost and speed.
18+
- **Seamless CI Integration:** Easily adopt Nx Agents with your [existing CI provider](/ci/recipes/set-up), requiring minimal setup changes.
19+
- **Simple Activation:** Enable distribution with just a [single line of code](#enable-nx-agents) in your CI configuration.
1720

18-
- Choose how many machines to set up
19-
- Set up each machine so that it is ready to execute tasks
20-
- Ensure that tasks are run in the correct order
21-
- Copy the output of certain tasks to the machines where those outputs are needed
22-
- Shut down machines when there are no more tasks to run
23-
- Shut down all the machines when the whole pipeline hits an error
24-
- Make sure sensitive information is being handled securely on all machines
21+
## Enable Nx Agents
2522

26-
And each of these concerns will need to be reconsidered whenever the codebase changes. It would actually be best if they were reconsidered for every PR, because small PRs may not need as much distribution as large PRs.
23+
To enable task distribution with Nx Agents, make sure your Nx workspace is connected to Nx Cloud. If you haven't connected your workspace to Nx Cloud yet, run the following command:
2724

28-
## Nx Agents Make Distributing Tasks Simple
25+
```shell
26+
npx nx connect
27+
```
2928

30-
Nx Agents take care of all these concerns with a small initial configuration that does not need to be modified as your codebase changes. Your CI pipeline sends your tasks to be run on agent machines that Nx Cloud creates for you. All you need to do is specify how many agents and the type of agent. Then, when the pipeline is finished, your initial CI pipeline will contain all the logs and artifacts as if the tasks all ran on your main CI machine - but completed in a fraction of the time.
29+
Check out the [connect to Nx Cloud recipe](/ci/intro/connect-to-nx-cloud) for more details.
3130

32-
![Distribute Task Execution with Nx Agents](/shared/images/dte/nx-agents-orchestration-diagram.svg)
31+
Then, adjust your CI pipeline configuration to **enable task distribution**. If you don't have a CI config yet, you can generate a new one using the following command:
3332

34-
For a more thorough explanation of how Nx Agents optimizes your CI pipeline, read this [guide to parallelization and distribution in CI](/ci/concepts/parallelization-distribution).
33+
```shell
34+
npx nx g ci-workflow
35+
```
3536

36-
## Enable Nx Agents
37+
The key line in your CI config is the `start-ci-run` command:
3738

38-
To enable task distribution with Nx Agents, there are two requirements:
39+
```yaml {% fileName=".github/workflows/ci.yml" highlightLines=[13] %}
40+
name: CI
41+
...
3942

40-
1. Enable version control system integration. The integrations currently available are [GitHub](/ci/recipes/source-control-integration/github), [GitLab](/ci/recipes/source-control-integration/gitlab), [Bitbucket](/ci/recipes/source-control-integration/bitbucket) and [Azure DevOps](/ci/recipes/source-control-integration/azure-devops). These integrations can be enabled from your [Nx Cloud dashboard](https://nx.app).
41-
2. Add a single line to your CI pipeline configuration.
43+
jobs:
44+
main:
45+
runs-on: ubuntu-latest
46+
steps:
47+
...
48+
- uses: actions/checkout@v4
49+
with:
50+
fetch-depth: 0
4251

43-
Add the `start-ci-run` command to your CI pipeline configuration after checking out the repository and before installing `node_modules`:
52+
- run: pnpm dlx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="build"
4453

45-
```yaml {% fileName=".github/workflows/main.yaml" %}
46-
# After checkout repository
47-
- name: Start CI run
48-
run: 'npx nx-cloud start-ci-run --distribute-on="8 linux-medium-js"'
49-
# Before install node_modules
50-
# Run any nx commands as if running on a single machine
54+
# Cache node_modules
55+
- uses: actions/setup-node@v4
56+
with:
57+
node-version: 20
58+
cache: 'pnpm'
59+
...
60+
61+
# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
62+
- run: pnpm exec nx affected -t lint test build
5163
```
5264
53-
The `--distribute-on` flag instructs Nx Cloud to distribute tasks across 8 agents of type `linux-medium-js`. `linux-medium-js` is the name of the launch template that will be used to provision the agent. Use on of the [default launch templates](https://github.com/nrwl/nx-cloud-workflows/blob/main/launch-templates/linux.yaml) or create your own [custom launch template](/ci/reference/launch-templates).
65+
This command tells Nx Cloud to:
66+
67+
- Start a CI run (`npx nx-cloud start-ci-run`)
68+
- Collect all Nx commands that are being issued (e.g., `pnpm exec nx affected -t lint test build`) and
69+
- Distribute them across 3 agents (`3 linux-medium-js`) where `linux-medium-js` is a predefined agent [launch template](/ci/reference/launch-templates).
70+
71+
### Configure Nx Agents on your CI Provider
72+
73+
Every organization manages their CI/CD pipelines differently, so the guides don't cover org-specific aspects of CI/CD (e.g., deployment). They mainly focus on configuring Nx correctly using Nx Agents and [Nx Replay](/ci/features/remote-cache).
74+
75+
- [Azure Pipelines](/ci/recipes/set-up/monorepo-ci-azure)
76+
- [Circle CI](/ci/recipes/set-up/monorepo-ci-circle-ci)
77+
- [GitHub Actions](/ci/recipes/set-up/monorepo-ci-github-actions)
78+
- [Jenkins](/ci/recipes/set-up/monorepo-ci-jenkins)
79+
- [GitLab](/ci/recipes/set-up/monorepo-ci-gitlab)
80+
- [Bitbucket Pipelines](/ci/recipes/set-up/monorepo-ci-bitbucket-pipelines)
81+
82+
## How Nx Agents Work
83+
84+
![Distribute Task Execution with Nx Agents](/shared/images/dte/nx-agents-orchestration-diagram.svg)
85+
86+
_**Nx Agents are declarative**_ in that you only specify the number of agents and the type of agent you want to use. Nx Cloud then picks up the Nx commands that are being issued on your CI and distributes them automatically. This results in **low maintenance and a much more efficient distribution strategy**. A non-declarative approach would be one where you define which tasks or projects get executed on which machine, requiring you to adjust the configuration as your codebase changes.
87+
88+
_**Nx Agents use a task-centric approach**_ to distribution. Current CI systems use VM-centric approaches, where tasks must be predefined for specific machines, often leading to inefficiencies as your codebase grows. Instead of defining which tasks run on which machine upfront, Nx Agents dynamically process tasks based on availability and task dependencies/ordering. Tasks are picked up by agents based on the task's required processing time (from historical data) and task dependency/ordering (from the Nx graph). This results in a faster and resource efficient processing, and is also more resilient to failures since any other agent can pick up work if one agent fails during bootup. Read more [on our blog post](/blog/reliable-ci-a-new-execution-model-fixing-both-flakiness-and-slowness).
89+
90+
_**Nx Agents are cost and resource-efficient**_ as the tasks are automatically distributed - **optimizing for speed while also ensuring resource utilization is high** and idle time is low. You can also [dynamically adjust the number of agents](/ci/features/dynamic-agents) based on the size of the PR, and we're working on [some more AI-powered features](/ci/concepts/nx-cloud-ai) to optimize this even further. In addition, [remote caching](/ci/features/remote-cache) guarantees tasks are not run twice, and artifacts are shared efficiently among agents.
91+
92+
_**Nx Agents are non-invasive**_ in that you don't need to completely overhaul your existing CI configuration or your Nx workspace to use them. You can start using Nx Agents with your existing CI provider by adding the `nx-cloud start-ci-run...` command mentioned previously. In addition, all artifacts and logs are played back to the main job so you can keep processing them as if they were run on the main job. Hence, your existing post-processing steps should still keep working as before.
93+
94+
For a more thorough explanation of how Nx Agents optimize your CI pipeline, read this [guide to parallelization and distribution in CI](/ci/concepts/parallelization-distribution).
5495

5596
## Nx Agents Features
5697

@@ -66,21 +107,10 @@ The `--distribute-on` flag instructs Nx Cloud to distribute tasks across 8 agent
66107

67108
{% /cards %}
68109

69-
## CI/CD Guides
70-
71-
Every organization manages their CI/CD pipelines differently, so the guides don't cover org-specific aspects of
72-
CI/CD (e.g., deployment). They mainly focus on configuring Nx correctly using Nx Agents and [Nx Replay](/ci/features/remote-cache).
73-
74-
- [Azure Pipelines](/ci/recipes/set-up/monorepo-ci-azure)
75-
- [Circle CI](/ci/recipes/set-up/monorepo-ci-circle-ci)
76-
- [GitHub Actions](/ci/recipes/set-up/monorepo-ci-github-actions)
77-
- [Jenkins](/ci/recipes/set-up/monorepo-ci-jenkins)
78-
- [GitLab](/ci/recipes/set-up/monorepo-ci-gitlab)
79-
- [Bitbucket Pipelines](/ci/recipes/set-up/monorepo-ci-bitbucket-pipelines)
80-
81-
Note that only cacheable operations can be distributed because they have to be replayed on the main job.
82-
83110
## Relevant Repositories and Examples
84111

112+
By integrating Nx Agents into your CI pipeline, you can significantly reduce build times, optimize resource use, and maintain a scalable, efficient development workflow.
113+
114+
- [Reliable CI: A New Execution Model Fixing Both Flakiness and Slowness](/blog/reliable-ci-a-new-execution-model-fixing-both-flakiness-and-slowness)
85115
- [Nx: On how to make your CI 16 times faster with a small config change](https://github.com/vsavkin/interstellar)
86116
- ["Lerna & Distributed Task Execution" Example](https://github.com/vsavkin/lerna-dte)
36.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)