Skip to content

Commit f275dcb

Browse files
committed
Deploy Rust on Google Cloud C4A (Arm-based Axion VMs)
Signed-off-by: odidev <[email protected]>
1 parent c7cf14a commit f275dcb

File tree

8 files changed

+344
-0
lines changed

8 files changed

+344
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: Deploy Rust on Google Cloud C4A (Arm-based Axion VMs)
3+
4+
minutes_to_complete: 30
5+
6+
who_is_this_for: This learning path is intended for software developers deploying and optimizing Rust workloads on Linux/Arm64 environments, specifically using Google Cloud C4A virtual machines powered by Axion processors.
7+
8+
learning_objectives:
9+
- Provision an Arm-based SUSE SLES virtual machine on Google Cloud (C4A with Axion processors)
10+
- Install Rust and configure the development environment on a SUSE Arm64 (C4A) instance
11+
- Verify Rust setup by compiling and running a sample program to ensure toolchain functionality
12+
- Benchmark Rust using cargo bench with Criterion to measure execution speed, stability, and performance on Arm64 systems
13+
14+
prerequisites:
15+
- A [Google Cloud Platform (GCP)](https://cloud.google.com/free) account with billing enabled
16+
- Basic familiarity with [Rust](https://www.rust-lang.org/)
17+
18+
author: Pareena Verma
19+
20+
##### Tags
21+
skilllevels: Introductory
22+
subjects: Performance and Architecture
23+
cloud_service_providers: Google Cloud
24+
25+
armips:
26+
- Neoverse
27+
28+
tools_software_languages:
29+
- Rust
30+
- Cargo
31+
- Criterion
32+
33+
operatingsystems:
34+
- Linux
35+
36+
# ================================================================================
37+
# FIXED, DO NOT MODIFY
38+
# ================================================================================
39+
further_reading:
40+
- resource:
41+
title: Google Cloud documentation
42+
link: https://cloud.google.com/docs
43+
type: documentation
44+
45+
- resource:
46+
title: Rust documentation
47+
link: https://doc.rust-lang.org/stable/
48+
type: documentation
49+
50+
- resource:
51+
title: Cargo bench documentation
52+
link: https://doc.rust-lang.org/cargo/commands/cargo-bench.html
53+
type: documentation
54+
55+
weight: 1
56+
layout: "learningpathall"
57+
learning_path_main_page: "yes"
58+
---
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# ================================================================================
3+
# FIXED, DO NOT MODIFY THIS FILE
4+
# ================================================================================
5+
weight: 21 # Set to always be larger than the content in this path to be at the end of the navigation.
6+
title: "Next Steps" # Always the same, html page title.
7+
layout: "learningpathall" # All files under learning paths have this same wrapper for Hugo processing.
8+
---
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: Getting started with Rust on Google Axion C4A (Arm Neoverse-V2)
3+
4+
weight: 2
5+
6+
layout: "learningpathall"
7+
---
8+
9+
## Google Axion C4A Arm instances in Google Cloud
10+
11+
Google Axion C4A is a family of Arm-based virtual machines built on Google’s custom Axion CPU, which is based on Arm Neoverse-V2 cores. Designed for high-performance and energy-efficient computing, these virtual machines offer strong performance for modern cloud workloads such as CI/CD pipelines, microservices, media processing, and general-purpose applications.
12+
13+
The C4A series provides a cost-effective alternative to x86 virtual machines while leveraging the scalability and performance benefits of the Arm architecture in Google Cloud.
14+
15+
To learn more about Google Axion, refer to the [Introducing Google Axion Processors, our new Arm-based CPUs](https://cloud.google.com/blog/products/compute/introducing-googles-new-arm-based-cpu) blog.
16+
17+
## Rust
18+
19+
[Rust](https://www.rust-lang.org/) is a modern, high-performance systems programming language designed for safety, speed, and concurrency. It provides memory safety without garbage collection, making it ideal for building reliable and efficient software.
20+
21+
Developed by Mozilla, Rust is widely used in system-level programming, web assembly, embedded systems, and performance-critical applications.
22+
Its strong type system and ownership model help prevent common bugs like data races and memory leaks.
23+
24+
To learn more, visit the [official Rust website](https://www.rust-lang.org/).
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: Rust Baseline Testing on Google Axion C4A Arm Virtual Machine
3+
weight: 5
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Rust Baseline Testing on GCP SUSE VMs
10+
This guide demonstrates how to perform baseline testing of Rust on GCP SUSE Arm64 VMs, verifying installation, build functionality, and compilation performance on the Arm-based Axion C4A platform.
11+
12+
### Verify Installation
13+
Check the Rust version and toolchain setup:
14+
15+
```console
16+
rustc --version
17+
cargo --version
18+
```
19+
20+
### Create a Sample Rust Program
21+
Create and build a simple “Hello, World” application to ensure everything is functioning properly:
22+
23+
```console
24+
mkdir rust-baseline
25+
cd rust-baseline
26+
cargo new hello
27+
cd hello
28+
cargo run
29+
```
30+
- **`mkdir rust-baseline`** – Creates a new directory named `rust-baseline`.
31+
- **`cd rust-baseline`** – Enters the `rust-baseline` directory.
32+
- **`cargo new hello`** – Creates a new Rust project named `hello` with default files (`main.rs`, `Cargo.toml`).
33+
- **`cd hello`** – Moves into the newly created `hello` project directory.
34+
- **`cargo run`** – Compiles and runs the Rust program, printing **“Hello, world!”**, confirming that Rust and Cargo are properly set up.
35+
36+
You should see an output similar to:
37+
```output
38+
Compiling hello v0.1.0 (/home/gcpuser/rust-baseline/hello)
39+
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.19s
40+
Running `target/debug/hello`
41+
Hello, world!
42+
```
43+
44+
### Measure Compilation Speed
45+
Use the time command to measure how long Rust takes to compile a small program:
46+
47+
```console
48+
cargo clean
49+
time cargo build
50+
```
51+
This gives a rough idea of compilation performance on the Arm64 CPU.
52+
53+
You should see an output similar to:
54+
```output
55+
Removed 21 files, 7.7MiB total
56+
Compiling hello v0.1.0 (/home/gcpuser/rust-baseline/hello)
57+
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
58+
59+
real 0m0.186s
60+
user 0m0.118s
61+
sys 0m0.071s
62+
```
63+
This confirms that Rust is working properly on your Arm64 VM.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
title: Rust Benchmarking
3+
weight: 6
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
10+
## Rust Benchmarking by cargo bench
11+
This section demonstrates how to benchmark Rust performance using **official Rust benchmarking tools**`cargo bench` and the **Criterion** library — to measure code execution speed, stability, and performance consistency on Arm64 hardware.
12+
13+
### Verify Rust and Cargo
14+
Ensure that Rust and Cargo are properly installed before running benchmarks
15+
16+
### Create a New Rust Project
17+
Create a new Rust project for benchmarking:
18+
19+
```console
20+
cargo new rust-benchmark
21+
cd rust-benchmark
22+
```
23+
### Add Criterion Benchmarking Dependency
24+
**Criterion** is the officially recommended benchmarking crate for Rust.Add it to your project by editing the `Cargo.toml` file:
25+
26+
```toml
27+
[dependencies]
28+
criterion = "0.5"
29+
30+
[[bench]]
31+
name = "my_benchmark"
32+
harness = false
33+
```
34+
This enables Criterion for high-precision benchmarking.
35+
36+
### Create the Benchmark File
37+
Create a new benchmark file inside the `benches/` directory:
38+
39+
```console
40+
mkdir benches
41+
vi benches/my_benchmark.rs
42+
```
43+
Benchmark files in this directory are automatically detected by Cargo.
44+
45+
**Add the Benchmark Code**
46+
Paste the following benchmark code:
47+
48+
```rust
49+
use criterion::{black_box, Criterion, criterion_group, criterion_main};
50+
51+
// Example benchmark function
52+
fn fibonacci(n: u64) -> u64 {
53+
match n {
54+
0 => 0,
55+
1 => 1,
56+
n => fibonacci(n - 1) + fibonacci(n - 2),
57+
}
58+
}
59+
60+
fn benchmark_fibonacci(c: &mut Criterion) {
61+
c.bench_function("fibonacci 20", |b| b.iter(|| fibonacci(black_box(20))));
62+
}
63+
64+
criterion_group!(benches, benchmark_fibonacci);
65+
criterion_main!(benches);
66+
```
67+
This code measures how efficiently Rust computes the 20th Fibonacci number.
68+
69+
### Run the Benchmark
70+
Now run the benchmark using Cargo:
71+
72+
```console
73+
cargo bench
74+
```
75+
Cargo compiles your code in optimized mode and runs the Criterion benchmarks, showing execution time, performance deviation, and stability metrics for your Rust functions.
76+
77+
You should see an output similar to:
78+
```output
79+
Running benches/my_benchmark.rs (target/release/deps/my_benchmark-f40a307ef9cad515)
80+
Gnuplot not found, using plotters backend
81+
fibonacci 20 time: [12.026 µs 12.028 µs 12.030 µs]
82+
Found 1 outliers among 100 measurements (1.00%)
83+
1 (1.00%) low mild
84+
```
85+
86+
### Benchmark Metrics Explanation
87+
88+
- **Average Time:** Mean execution time across benchmark runs.
89+
- **Outliers:** Represent runs significantly slower or faster than average.
90+
- **Plotting Backend:** Used `plotters` since Gnuplot was not found.
91+
- The results show **consistent performance** with only slight variation across 100 measurements.
92+
93+
### Benchmark summary on x86_64
94+
To compare the benchmark results, the following results were collected by running the same benchmark on a `x86 - c4-standard-4` (4 vCPUs, 15 GB Memory) x86_64 VM in GCP, running SUSE:
95+
96+
| **Benchmark** | **Average Time (µs)** | **Min (µs)** | **Max (µs)** | **Outliers (%)** | **Remarks** |
97+
|--------------------|----------------------:|--------------:|--------------:|-----------------:|----------------------------------|
98+
| **fibonacci 20** | 19.152 | 19.100 | 19.205 | 6.00% | Minor outliers, stable overall. |
99+
100+
### Benchmark summary on Arm64
101+
Results from the earlier run on the `c4a-standard-4` (4 vCPU, 16 GB memory) Arm64 VM in GCP (SUSE):
102+
103+
| **Benchmark** | **Average Time (µs)** | **Min (µs)** | **Max (µs)** | **Outliers (%)** | **Remarks** |
104+
|--------------------|----------------------:|--------------:|--------------:|-----------------:|----------------------------------|
105+
| **fibonacci 20** | 12.028 | 12.026 | 12.030 | 1.00% | Very stable performance, minimal variation. |
106+
107+
### Rust benchmarking comparison on Arm64 and x86_64
108+
109+
- The **Fibonacci (n=20)** benchmark demonstrated **consistent performance** with minimal deviation.
110+
- **Average execution time** was around **12.028 µs**, indicating efficient CPU computation on **Arm64**.
111+
- Only **1% outliers** were detected, showing **high stability** and **repeatability** of results.
112+
- Overall, the test confirms **Rust’s reliable execution speed** and **low variance** on the Arm64 platform.
261 KB
Loading
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Install Rust
3+
weight: 4
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Rust Installation on GCP SUSE VM
10+
This guide explains how to install and configure Rust on a GCP SUSE Arm64 VM, ensuring the environment is ready for building and benchmarking Rust applications.
11+
12+
### System Preparation
13+
Updates the system and installs essential build tools for compiling Rust programs.
14+
15+
```console
16+
sudo zypper refresh
17+
sudo zypper update -y
18+
sudo zypper install -y curl gcc make
19+
```
20+
### Install Rust Using rustup
21+
Rust provides an official installer script via `rustup`, which handles the setup automatically:
22+
23+
```console
24+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
25+
```
26+
When prompted, you can choose **option 1** (default installation).
27+
28+
### Configure Rust Environment
29+
Activates Rust’s environment variables for the current shell session.
30+
31+
```console
32+
source $HOME/.cargo/env
33+
```
34+
35+
### Verify Rust Installation
36+
Confirms successful installation of Rust and Cargo by checking their versions.
37+
38+
```console
39+
rustc --version
40+
cargo --version
41+
```
42+
43+
You should see an output similar to:
44+
```output
45+
rustc 1.91.0 (f8297e351 2025-10-28)
46+
cargo 1.91.0 (ea2d97820 2025-10-10)
47+
```
48+
Rust installation is complete. You can now go ahead with the baseline testing of Rust in the next section.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: Create a Google Axion C4A Arm virtual machine on GCP
3+
weight: 3
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Overview
10+
11+
In this section, you will learn how to provision a Google Axion C4A Arm virtual machine on Google Cloud Platform (GCP) using the `c4a-standard-4` (4 vCPUs, 16 GB memory) machine type in the Google Cloud Console.
12+
13+
{{% notice Note %}}
14+
For support on GCP setup, see the Learning Path [Getting started with Google Cloud Platform](https://learn.arm.com/learning-paths/servers-and-cloud-computing/csp/google/).
15+
{{% /notice %}}
16+
17+
## Provision a Google Axion C4A Arm VM in Google Cloud Console
18+
19+
To create a virtual machine based on the C4A instance type:
20+
- Navigate to the [Google Cloud Console](https://console.cloud.google.com/).
21+
- Go to **Compute Engine > VM Instances** and select **Create Instance**.
22+
- Under **Machine configuration**:
23+
- Populate fields such as **Instance name**, **Region**, and **Zone**.
24+
- Set **Series** to `C4A`.
25+
- Select `c4a-standard-4` for machine type.
26+
27+
![Create a Google Axion C4A Arm virtual machine in the Google Cloud Console with c4a-standard-4 selected alt-text#center](images/gcp-vm.png "Creating a Google Axion C4A Arm virtual machine in Google Cloud Console")
28+
29+
- Under **OS and Storage**, select **Change**, then choose an Arm64-based OS image. For this Learning Path, use **SUSE Linux Enterprise Server**. Pick the preferred version for your Operating System. Ensure you select the **Arm image** variant. Click **Select**.
30+
- Under **Networking**, enable **Allow HTTP traffic**.
31+
- Click **Create** to launch the instance.

0 commit comments

Comments
 (0)