Skip to content

Commit 57fcffe

Browse files
Refine Ruby on Rails documentation: update titles for clarity, enhance installation and benchmarking sections, and improve overall readability.
1 parent 3125c8d commit 57fcffe

6 files changed

Lines changed: 114 additions & 71 deletions

File tree

content/learning-paths/servers-and-cloud-computing/ruby-on-rails/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Deploy Ruby on Rails on Google Cloud C4A (Arm-based Axion VMs)
2+
title: Deploy Ruby on Rails on Arm-based Google Cloud C4A virtual machines
33

44
minutes_to_complete: 40
55

content/learning-paths/servers-and-cloud-computing/ruby-on-rails/background.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ weight: 2
66
layout: "learningpathall"
77
---
88

9-
## Google Axion C4A Arm instances in Google Cloud
9+
## Learn about Google Axion C4A Arm instances in Google Cloud
1010

1111
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.
1212

1313
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.
1414

1515
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.
1616

17-
## Ruby on Rails
17+
## Learn about Ruby on Rails
1818

1919
Ruby on Rails (Rails) is an open-source, server-side web application framework written in Ruby.
2020

content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
---
2-
title: Set up Ruby on Rails baseline testing on Google Axion C4A Arm virtual machine
2+
title: Set up Ruby on Rails baseline testing
33
weight: 5
44

55
### FIXED, DO NOT MODIFY
66
layout: learningpathall
77
---
88

9-
## Set up Ruby on Rails with PostgreSQL on SUSE Arm64 (Google Cloud C4A)
9+
## Set up Ruby on Rails with PostgreSQL on SUSE Arm64
1010

1111
Follow these steps to install PostgreSQL, connect it to a Ruby on Rails app, and verify everything works on a SUSE Arm64 Google Cloud C4A VM.
1212

13-
### Install PostgreSQL and development headers
13+
## Install PostgreSQL and development headers
1414

15-
Install PostgreSQL and its development headers so Rails can use the `pg` gem:
15+
Install PostgreSQL and its development headers on your SUSE system:
1616

1717
```console
1818
sudo zypper install postgresql-devel postgresql-server
1919
```
20-
- `postgresql-devel` lets you compile the `pg` gem for Rails.
20+
21+
This installs two packages:
22+
- `postgresql-server` - the PostgreSQL database service
23+
- `postgresql-devel` - development headers needed to compile the `pg` gem that connects Rails to PostgreSQL
24+
25+
The development headers are essential because Rails uses the `pg` gem to communicate with PostgreSQL, and this gem needs to be compiled during installation.
2126

2227
Start PostgreSQL and enable it to run at boot:
2328

@@ -41,47 +46,63 @@ The output is similar to:
4146
```
4247
If the Active state is running, PostgreSQL is ready.
4348

44-
### Create a PostgreSQL user for Rails
49+
## Create a PostgreSQL user for Rails
4550

4651
Create a dedicated PostgreSQL user for your Rails app:
4752

4853
```console
4954
sudo -u postgres psql -c "CREATE USER gcpuser WITH SUPERUSER PASSWORD 'your_password';"
5055
```
51-
- This command creates a user named `gcpuser` with superuser privileges.
52-
53-
You’ll use this user in your Rails configuration.
56+
This command creates a user named `gcpuser` with superuser privileges. You’ll use this user in your Rails configuration.
5457

55-
### Set environment variables
58+
## Set environment variables
5659

57-
Export environment variables so Rails and the `pg` gem can connect to PostgreSQL:
60+
Set environment variables for Rails to connect to PostgreSQL:
5861

5962
```console
6063
export PGUSER=gcpuser
6164
export PGPASSWORD=your_password
6265
export PGHOST=localhost
6366
```
64-
- `PGUSER` sets the PostgreSQL user.
65-
- `PGPASSWORD` stores the password for this session.
66-
- `PGHOST` points to the local VM.
6767

68-
### Create a new Rails app with PostgreSQL
68+
These variables tell Rails how to connect to your PostgreSQL database:
69+
- `PGUSER` - the PostgreSQL username you created
70+
- `PGPASSWORD` - the password for that user
71+
- `PGHOST` - tells Rails to connect to the local database server
72+
73+
## Create a new Rails app with PostgreSQL
74+
75+
Now you'll create a Rails application configured to use PostgreSQL as its database.
6976

70-
Generate a new Rails app that uses PostgreSQL:
77+
Generate a new Rails app:
7178

7279
```console
7380
rails new db_test_rubyapp -d postgresql
81+
```
82+
83+
This command creates a new Rails application named `db_test_rubyapp` with PostgreSQL as the default database adapter.
84+
85+
Navigate to your new app directory:
86+
87+
```console
7488
cd db_test_rubyapp
89+
```
90+
91+
Install the required gems:
92+
93+
```console
7594
bundle install
7695
```
77-
- `rails new db_test_rubyapp -d postgresql` creates a Rails app using PostgreSQL.
78-
- `bundle install` installs gem dependencies, including the `pg` gem.
96+
97+
The `bundle install` command downloads and installs all the gem dependencies listed in your `Gemfile`, including the `pg` gem that allows Rails to communicate with PostgreSQL.
98+
99+
You now have a Rails application ready to connect to your PostgreSQL database.
79100

80101
{{% notice Note %}}
81102
Check `config/database.yml` and make sure `username` and `password` match your PostgreSQL user (`gcpuser`).
82103
{{% /notice %}}
83104

84-
### Update Rails database configuration
105+
## Update Rails database configuration
85106

86107
Open `config/database.yml` and confirm the credentials:
87108

@@ -103,7 +124,7 @@ development:
103124
<<: *default
104125
```
105126

106-
### Change the Authentication Method
127+
## Change the Authentication Method
107128
By default, PostgreSQL on many Linux distributions (including SUSE) uses the ident authentication method for local connections. This method maps Linux system usernames directly to PostgreSQL roles. While convenient for local access, it prevents password-based authentication, which is necessary for Rails and most application connections.
108129

109130
To allow Rails to connect using a username and password, change the authentication method in PostgreSQL’s configuration file `pg_hba.conf` from ident to md5.
@@ -142,7 +163,7 @@ sudo systemctl status postgresql
142163
```
143164
The service should show as active (running).
144165

145-
### Create and Initialize the Database
166+
## Create and Initialize the Database
146167
Once PostgreSQL is configured and Rails can authenticate, you can create your application’s development and test databases.
147168
This step verifies that Rails is correctly connected to PostgreSQL and that the pg gem is working on your Arm64 environment.
148169

@@ -158,24 +179,25 @@ Created database 'db_test_rubyapp_test'
158179
```
159180
This output confirms that Rails successfully. It connected to the PostgreSQL service using the credentials from `config/database.yml` and created two new databases — one for development and one for testing.
160181

161-
### Generate a Scaffold for Testing
182+
## Generate a Scaffold for Testing
162183
To verify your Ruby on Rails and PostgreSQL integration, you’ll create a small scaffold application.
163184
A scaffold is a Rails generator that automatically builds a model, controller, views, and database migration, allowing you to test CRUD (Create, Read, Update, Delete) operations quickly.
164185

165186
For this example, you’ll create a simple Task Tracker app that manages tasks with titles and due dates.
187+
166188
Run the following command inside your Rails project directory:
167189

168190
```console
169191
rails generate scaffold task title:string due_date:date
170192
```
171-
- This command generates a model, controller, views, and migration for tasks.
193+
This command generates a model, controller, views, and migration for tasks.
172194

173195
Apply the migration:
174196

175197
```console
176198
rails db:migrate
177199
```
178-
You’ll see output like:
200+
You’ll see output similar to:
179201

180202
```output
181203
== 20251006101717 CreateTasks: migrating ======================================
@@ -184,7 +206,7 @@ You’ll see output like:
184206
== 20251006101717 CreateTasks: migrated (0.0128s) =============================
185207
```
186208

187-
### Verify the tasks table in PostgreSQL
209+
## Verify the tasks table in PostgreSQL
188210

189211
Check that the `tasks` table exists:
190212

@@ -223,7 +245,7 @@ Indexes:
223245
"tasks_pkey" PRIMARY KEY, btree (id)
224246
```
225247

226-
### Open port 3000 in Google Cloud (VPC firewall)
248+
## Open port 3000 in Google Cloud (VPC firewall)
227249
Before proceeding to run the Rails server, you need to allow port 3000 from your GCP console. Below are the steps to do that:
228250

229251
a. On the GCP console, navigate to **Firewall** -> **Create Firewall Rule**
@@ -254,7 +276,7 @@ Click on **"Create"**. The Firewall rule will be created successfully and can be
254276

255277
![ Create Firewall rule alt-text#center](images/firewall5.png "Figure 5: Create Firewall rule")
256278

257-
### OS firewall (firewalld) on SUSE
279+
## OS firewall (firewalld) on SUSE
258280
Once done, go back to your VM, install FirewallD:
259281
```console
260282
sudo zypper install firewalld
@@ -276,9 +298,8 @@ rails server -b 0.0.0.0
276298
```
277299
- This command lets you access Rails from your browser using the VM’s external IP.
278300

279-
### Access your Rails app
280301

281-
### Access the Application:
302+
## Access the Rails application:
282303
Open a web browser on your local machine (Chrome, Firefox, Edge, etc.) and enter the following URL in the address bar:
283304

284305
```
@@ -288,7 +309,7 @@ http://[YOUR_VM_EXTERNAL_IP]:3000
288309

289310
You will see a Rails welcome page in your browser if everything is set up correctly. It looks like this:
290311

291-
![Rails-info page alt-text#center](images/rails-web.png "Figure 6: Ruby/Rails Welcome Page")
312+
![Rails default welcome page displaying Ruby on Rails framework logo with green and red styling, welcome message, and navigation links for About your application environment, getting started guide, and Rails documentation on a clean white background alt-text#center](images/rails-web.png "Ruby/Rails welcome page")
292313

293314
With port 3000 reachable and the welcome page loading, your Rails stack on SUSE Arm64 (C4A Axion) is verified end-to-end and you can proceed to benchmarking.
294315

content/learning-paths/servers-and-cloud-computing/ruby-on-rails/benchmarking.md

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,27 @@ layout: learningpathall
77
---
88

99

10-
## Ruby on Rails Benchmarking
10+
## Overview
1111
In this section you will benchmark Ruby on Rails using Ruby’s built-in `Benchmark` library to measure execution time for database inserts, queries, and CPU computations on GCP SUSE VMs, providing insights into performance metrics and bottlenecks.
1212

13-
### Go into your Rails app folder
13+
## Locate the Rails app folder
1414
Navigate into the folder of your Rails application. This is where Rails expects your application code, models, and database configurations to be located. All commands related to your app should be run from this folder.
1515

1616
```console
1717
cd ~/db_test_rubyapp
1818
````
1919

20-
### Create the benchmark
21-
Now create a new Ruby file named `benchmark.rb` where you will write code to measure performance.
20+
## Create the benchmark file
21+
22+
Create a new Ruby file called `benchmark.rb` to measure your Rails application's performance:
2223

2324
```console
2425
vi benchmark.rb
2526
```
2627

27-
### Benchmark code for measuring Rails app performance
28-
Copy the code below into `benchmark.rb`. It measures database inserts, queries, and CPU computations in your Rails application using Ruby’s Benchmark library.
28+
This file will contain the benchmarking code that tests different aspects of your application's performance.
29+
Copy the following code into `benchmark.rb`. This code measures three different aspects of your Rails application's performance:
30+
2931

3032
```ruby
3133
require 'benchmark'
@@ -52,12 +54,17 @@ Benchmark.bm do |x|
5254
end
5355
end
5456
```
55-
- `require 'benchmark'` → Loads Ruby’s built-in benchmarking library.
56-
- `n = 1000` → Sets the number of iterations for each task. You can increase or decrease this number to simulate heavier or lighter workloads.
57-
- `Benchmark.bm` → Starts a block to measure performance of different tasks.
58-
- **DB Insert** → Creates 1,000 new `Task` records in the database. Measures how long it takes to insert data.
59-
- **DB Query** → Retrieves the 1,000 `Task` records from the database. Measures how long it takes to query data.
60-
- **Computation** → Performs a simple calculation 1,000 times. Measures pure CPU performance (without database interactions).
57+
This benchmarking script tests three key areas of your Rails application's performance:
58+
59+
- The `require 'benchmark'` statement loads Ruby's built-in benchmarking library, which provides precise timing measurements for code execution.
60+
- The variable `n = 1000` sets how many times each test runs - you can adjust this number to simulate lighter or heavier workloads depending on your testing needs.
61+
- The `Benchmark.bm` method creates a benchmarking block that measures and reports the performance of different tasks. Within this block, three different tests run to evaluate your application:
62+
63+
- The DB Insert test creates 1,000 new `Task` records in your PostgreSQL database. This measures how efficiently your application can write data, which is crucial for understanding performance during high-volume data entry operations.
64+
65+
- The DB Query test retrieves those same `Task` records from the database. This measurement shows how quickly your application can read data, helping you understand performance during data-heavy read operations like report generation or search functionality.
66+
67+
- The Computation test performs a mathematical calculation (summing numbers 1 through 10,000) repeatedly without any database interaction. This gives you a baseline for pure CPU performance, showing how your application handles processing-intensive tasks that don't involve external resources.
6168

6269
This code gives you a basic understanding of how your Rails app performs under different types of workloads.
6370

@@ -84,34 +91,49 @@ DB Insert: 2.271645 0.050236 2.321881 ( 2.721631)
8491
DB Query: 3.379849 0.009345 3.389194 ( 3.389613)
8592
Computation: 0.410907 0.000000 0.410907 ( 0.410919)
8693
```
94+
## Interpet your benchmark results
95+
96+
The output shows four different timing measurements that help you understand where your application spends its time.
97+
98+
- The user time measures how long your Ruby code actually ran on the CPU. This represents the pure processing time for your application logic, calculations, and Ruby operations.
99+
100+
- The system time tracks how long your application spent waiting for system-level operations like database queries, file I/O, and network requests. Higher system time usually indicates bottlenecks in external resources.
101+
102+
- The total time simply adds user and system time together, giving you the complete CPU processing time your application consumed.
103+
104+
- The real time shows the actual wall-clock time that passed from start to finish. This includes everything: CPU processing, waiting for the database to respond, network delays, and any other factors that made your application pause. Real time is often higher than total time because your application might wait for resources that are busy with other tasks.
87105

88-
### Benchmark Metrics Explained
106+
When real time significantly exceeds total time, it typically indicates that your application is spending considerable time waiting for external resources rather than actively processing data.
89107

90-
- **user** → Time spent executing your Ruby code (**CPU time in user mode**).
91-
- **system** → Time spent in **system calls** (I/O, database, kernel interactions).
92-
- **total**`user + system` (sum of CPU processing time).
93-
- **real** → The **wall-clock time** (actual elapsed time, includes waiting for DB, I/O, etc).
108+
## Benchmark summary on Arm64
94109

95-
### Benchmark summary on Arm64
96-
Results summarized from the your run on the `c4a-standard-4` (4 vCPU, 16 GB memory) Arm64 VM in GCP (SUSE):
110+
Here are the performance results from running the benchmark on a `c4a-standard-4` (4 vCPU, 16 GB memory) Arm64 VM in GCP with SUSE:
97111

112+
| Task | User Time | System Time | Total Time | Real Time |
113+
|------|-----------|-------------|------------|-----------|
114+
| DB Insert | 2.27 sec | 0.05 sec | 2.32 sec | 2.72 sec |
115+
| DB Query | 3.38 sec | 0.01 sec | 3.39 sec | 3.39 sec |
116+
| Computation | 0.41 sec | 0.00 sec | 0.41 sec | 0.41 sec |
98117

99-
| Task | user (sec) | system (sec) | total (sec) | real (sec) |
100-
|--------------|----------|----------|----------|----------|
101-
| DB Insert | 2.271645 | 0.050236 | 2.321881 | 2.721631 |
102-
| DB Query | 3.379849 | 0.009345 | 3.389194 | 3.389613 |
103-
| Computation | 0.410907 | 0.000000 | 0.410907 | 0.410919 |
118+
### What these results tell you
104119

120+
- Database operations (insert and query) take significantly longer than pure computation, with queries being the slowest operation.
121+
- System time is minimal across all tasks, indicating efficient system resource usage on Arm64.
122+
- Real time closely matches total time for most operations, showing minimal waiting for external resources.
123+
- Computation tasks run very efficiently, demonstrating strong CPU performance on Axion processors.
105124

106-
### Key Takeaways
125+
## Key takeaways
107126

108-
When you look the benchmarking results, you will notice that on the Google Axion C4A Arm-based instances:
127+
When you analyze the benchmarking results, you'll notice several important patterns on Google Cloud Axion C4A Arm-based instances:
109128

110-
Rails on Arm64 performs consistently: Ruby and PostgreSQL are both natively optimized for Arm, providing stable, predictable latency.
111-
Database I/O remains the main optimization target: Techniques such as query caching, connection pooling, and async queries can improve DB-heavy performance.
112-
Compute-bound tasks scale well: Axion’s Arm cores and Ruby’s YJIT show excellent CPU utilization for non-I/O workloads.
129+
- Consistent performance - Ruby and PostgreSQL are both natively optimized for Arm, which provides stable and predictable latency across different workloads.
130+
- Database optimization opportunities - the results show that database I/O remains the primary bottleneck. You can improve database-heavy performance using techniques such as:
131+
- Query caching
132+
- Connection pooling
133+
- Asynchronous queries
134+
- Strong compute performance - Axion's Arm cores combined with Ruby's YJIT compiler demonstrate excellent CPU utilization for compute-intensive tasks that don't rely heavily on I/O operations.
113135

114-
Ruby on Rails runs efficiently on Google Clouds Axion-based C4A Arm64 instances.
136+
Ruby on Rails runs efficiently on Google Cloud's Axion-based C4A Arm64 instances, making them a solid choice for Rails applications.
115137

116138
## What you've accomplished
117139

content/learning-paths/servers-and-cloud-computing/ruby-on-rails/installation.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: Install Ruby on Rails
2+
title: Install Ruby on Rails on SUSE Linux
33
weight: 4
44

55
### FIXED, DO NOT MODIFY
66
layout: learningpathall
77
---
88

9-
## Install Ruby on Rails on SUSE Linux
9+
## Overview
1010

1111
In this section, you'll install Ruby, Rails, and essential supporting tools on your Google Cloud C4A instance running SUSE Enterprise Linux. The steps ensure your environment is ready to build, deploy, and optimize Ruby on Rails applications on Arm-based infrastructure.
1212

@@ -17,7 +17,7 @@ Start by updating your system packages to ensure you have the latest security pa
1717
sudo zypper update
1818
```
1919
## Install required dependencies
20-
Before installing Ruby, install essential development libraries and tools that ensure Ruby compiles and runs correctly on your SUSE Arm64 environment:
20+
Install essential development libraries and tools that Ruby needs to compile and run properly on your SUSE Arm64 system:
2121

2222
```console
2323
sudo zypper install git curl gcc make patch libyaml-devel libffi-devel libopenssl-devel readline-devel zlib-devel gdbm-devel bzip2 bzip2-devel
@@ -34,10 +34,10 @@ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
3434
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
3535
source ~/.bashrc
3636
```
37-
These commands accomplish the following:
38-
- Clone the rbenv repository to your home directory
39-
- Add rbenv to your PATH so the shell can find it
40-
- Configure rbenv to initialize automatically in new shell sessions
37+
These commands configure rbenv for your environment by doing the following:
38+
- Cloning the rbenv repository to your home directory
39+
- Adding rbenv to your PATH so the shell can find it
40+
- Configuring rbenv to initialize automatically in new shell sessions
4141
## Install ruby-build plugin
4242
Install the `ruby-build` plugin to enable rbenv to compile and install Ruby versions from source:
4343

0 commit comments

Comments
 (0)