From dfdfc04b1a531afb560559b9b9ed0d1428b0f01b Mon Sep 17 00:00:00 2001 From: pareenaverma Date: Tue, 4 Nov 2025 16:27:53 -0500 Subject: [PATCH 01/11] Update baseline.md --- .../ruby-on-rails/baseline.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md index 74686121e2..489b6c405b 100644 --- a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md +++ b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md @@ -24,6 +24,23 @@ Verify that the PostgreSQL service is active and running: ```console systemctl status postgresql ``` +The output should look like: +```output +● postgresql.service - PostgreSQL database server + Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled) + Active: active (running) since Tue 2025-11-04 21:25:59 UTC; 18s ago + Main PID: 26997 (postgres) + Tasks: 7 + CPU: 372ms + CGroup: /system.slice/postgresql.service + ├─ 26997 /usr/lib/postgresql15/bin/postgres -D /var/lib/pgsql/data + ├─ 26998 "postgres: logger " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""> + ├─ 26999 "postgres: checkpointer " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""> + ├─ 27000 "postgres: background writer " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" > + ├─ 27002 "postgres: walwriter " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""> + ├─ 27003 "postgres: autovacuum launcher " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "> + └─ 27004 "postgres: logical replication launcher " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "> +``` This command creates a new PostgreSQL role (user) named `gcpuser` with **superuser privileges**. From 5d03a12f7f7b1494c81df3ad34c445510e9e29dc Mon Sep 17 00:00:00 2001 From: pareenaverma Date: Tue, 4 Nov 2025 16:29:53 -0500 Subject: [PATCH 02/11] Update baseline.md --- .../servers-and-cloud-computing/ruby-on-rails/baseline.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md index 489b6c405b..af22bded37 100644 --- a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md +++ b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md @@ -75,7 +75,7 @@ Check `config/database.yml` to ensure the `username` and `password` match your P Open the Rails database configuration file: ```console -nano config/database.yml +vi config/database.yml ``` Find the `default`: and `development`: sections. Ensure the username matches the PostgreSQL user you created (gcpuser): From 82c7de29f1c136ff678bec534a91d298a581de4a Mon Sep 17 00:00:00 2001 From: pareenaverma Date: Tue, 4 Nov 2025 17:51:16 -0500 Subject: [PATCH 03/11] Update baseline.md --- .../ruby-on-rails/baseline.md | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md index af22bded37..f1eb10035f 100644 --- a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md +++ b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md @@ -45,7 +45,7 @@ The output should look like: This command creates a new PostgreSQL role (user) named `gcpuser` with **superuser privileges**. ```console -sudo -u postgres createuser --superuser gcpuser +sudo -u postgres psql -c "CREATE USER gcpuser WITH SUPERUSER PASSWORD 'your_password';" ``` - `sudo -u postgres` → Runs the command as the `postgres` user (default PostgreSQL superuser). - `createuser --superuser gcpuser` → Creates a PostgreSQL role named `gcpuser` with full admin privileges. @@ -55,6 +55,15 @@ sudo -u postgres createuser --superuser gcpuser This role will be used by Rails to connect to the PostgreSQL database. +### Set Environment variables + +Before you create your Rails app, set the following environment variables: + +```console +export PGUSER=gcpuser +export PGPASSWORD=your_password +export PGHOST=localhost +``` ### Create a Rails App with PostgreSQL Creates a new Rails application configured to use PostgreSQL as its database. @@ -72,10 +81,10 @@ Check `config/database.yml` to ensure the `username` and `password` match your P {{% /notice %}} ### Verify and Update Database Configuration -Open the Rails database configuration file: +Open and modify your Rails database configuration file: ```console -vi config/database.yml +sudo vi config/database.yml ``` Find the `default`: and `development`: sections. Ensure the username matches the PostgreSQL user you created (gcpuser): @@ -86,13 +95,40 @@ default: &default adapter: postgresql encoding: unicode username: gcpuser - password: + password: your_password host: localhost pool: 5 development: <<: *default ``` + +### Change the Authentication Method +Change the authentication method in the PostgreSQL configuration file `pg_hba.conf` from `ident` to `md5`. + +Open your configuration file +```console +sudo vi /var/lib/pgsql/data/pg_hba.conf +``` +Find lines that look like this: +```output +# IPv4 local connections: +host all all 127.0.0.1/32 ident +# IPv6 local connections: +host all all ::1/128 ident +``` +Change the method on these lines to look like: +```output +# IPv4 local connections: +host all all 127.0.0.1/32 md5 +# IPv6 local connections: +host all all ::1/128 md5 +``` +Save the file. Restart PostgreSQL: + +```console +sudo systemctl restart postgresql +``` ### Create and Initialize the Database Initializes and creates the development and test databases for your Rails app using PostgreSQL. From c4908ba897dec2a1931eff8704157898fdbf0fbf Mon Sep 17 00:00:00 2001 From: pareenaverma Date: Tue, 4 Nov 2025 18:19:52 -0500 Subject: [PATCH 04/11] Update baseline.md --- .../ruby-on-rails/baseline.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md index f1eb10035f..e5e12fe1f0 100644 --- a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md +++ b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md @@ -178,13 +178,19 @@ Now, verify that the table exists and has the correct structure following the st ```console sudo -u postgres psql +``` +In the PostgreSQL shell, run the following commands: + +```console \c db_test_rubyapp_development \d tasks +\q ``` - `sudo -u postgres psql` → Launches the PostgreSQL shell as the superuser `postgres`. - `\c db_test_rubyapp_development` → Connects to the Rails app’s development database. - `\d tasks` → Displays the schema (columns and types) of the `tasks` table. - +- `\q → Exit from the PostgreSQL shell + You should see output similar to: ```output psql (15.10) @@ -236,9 +242,16 @@ Click on **"Create"**. The Firewall rule will be created successfully and can be ![ Create Firewall rule alt-text#center](images/firewall5.png "Figure 5: Create Firewall rule") -Once done, go back to the VM, and execute the below commands to allow port 3000: +Once done, go back to the VM, install FirewallD +```console +sudo zypper install firewalld +``` + +Now start FirewallD and execute the below commands to allow port 3000: ```console +sudo systemctl start firewalld +sudo systemctl enable firewalld sudo firewall-cmd --permanent --add-port=3000/tcp sudo firewall-cmd --reload ``` From b909a4ed93bd763caa0a433473d43544bb98601e Mon Sep 17 00:00:00 2001 From: pareenaverma Date: Wed, 5 Nov 2025 11:07:38 -0500 Subject: [PATCH 05/11] Update _index.md --- .../servers-and-cloud-computing/ruby-on-rails/_index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/_index.md b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/_index.md index 8f1eda67f6..36181df157 100644 --- a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/_index.md +++ b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/_index.md @@ -7,7 +7,7 @@ cascade: minutes_to_complete: 40 -who_is_this_for: This learning path is intended for software developers deploying and optimizing Ruby on Rails workloads on Linux/Arm64 environments, specifically using Google Cloud C4A virtual machines powered by Axion processors. +who_is_this_for: This is an introductory topic intended for software developers deploying and optimizing Ruby on Rails workloads on Linux Arm64 environments, specifically using Google Cloud C4A virtual machines powered by Axion processors. learning_objectives: - Provision an Arm-based SUSE SLES virtual machine on Google Cloud (C4A with Axion processors) From 52b975d2b4b08d5ba0b247cfb319999373541bc7 Mon Sep 17 00:00:00 2001 From: pareenaverma Date: Wed, 5 Nov 2025 11:36:26 -0500 Subject: [PATCH 06/11] Update installation.md --- .../ruby-on-rails/installation.md | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/installation.md b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/installation.md index a7bedb2e6f..46fc2d27be 100644 --- a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/installation.md +++ b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/installation.md @@ -7,25 +7,24 @@ layout: learningpathall --- ## Install Ruby on Rails -In this section, you will learn how to install Ruby, Rails, and related tools (like rbenv and Bundler) on a SUSE Arm-based virtual machine. This guide will also cover installing the necessary dependencies to compile Ruby and run Rails applications smoothly. - +In this section, you’ll install Ruby, Rails, and essential supporting tools on a SUSE Arm64 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. ### Update System Packages -Updates all system packages to the latest versions to ensure stability and security. +Before installation, update all existing system packages. This ensures you have the latest security patches, compiler toolchains, and library versions compatible with Ruby. ```console sudo zypper update ``` ### Install Required Dependencies -These packages are essential for compiling Ruby and its native extensions. +Before installing Ruby, you need to install several core development libraries and tools. These packages ensure that Ruby and its native extensions compile and run correctly on your SUSE Arm64 environment. ```console sudo zypper install git curl gcc make patch libyaml-devel libffi-devel libopenssl-devel readline-devel zlib-devel gdbm-devel bzip2 bzip2-devel ``` ### Install rbenv -**rbenv** is a lightweight Ruby version manager that allows multiple Ruby versions on the same system. +`rbenv` is a lightweight Ruby version manager that enables you to install and manage multiple Ruby versions on the same system. This is particularly useful for developers running different Rails applications that require specific Ruby versions. ```console git clone https://github.com/rbenv/rbenv.git ~/.rbenv @@ -33,26 +32,25 @@ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc source ~/.bashrc ``` -- Clones the rbenv repository to manage Ruby versions -- Updates `PATH` so your shell can find rbenv -- Initializes rbenv in your shell session +With these steps you have cloned the `rbenv` repository to manage Ruby versions. Your `PATH` is updated so your shell can find rbenv. It then initializes rbenv in your shell session. ### Install ruby-build Plugin -**ruby-build** is an rbenv plugin that provides the `rbenv install` command to compile and install different Ruby versions from source. +`ruby-build` is an rbenv plugin that adds the `rbenv` install command, allowing you to compile and install specific Ruby versions from source. ```console git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build ``` ### Install Ruby -Installs Ruby and sets it as the default version for your environment. +Now that `rbenv` and `ruby-build` are set up, you can install Ruby and configure it as your system’s default version. This step compiles Ruby from source: ```console rbenv install 3.4.6 rbenv global 3.4.6 ruby -v ``` -- Installs Ruby 3.4.6 from source +With these commands you have: +- Installed Ruby 3.4.6 from source - Sets it as the default Ruby version for your user - `ruby -v` verifies the installed Ruby version @@ -61,29 +59,36 @@ You should see output similar to: ruby 3.4.6 (2025-09-16 revision dbd83256b1) +PRISM [aarch64-linux] ``` {{% notice Note %}} -Ruby 3.4.0 introduced significant performance enhancements, notably improvements to YJIT (Yet Another Ruby JIT), a Ruby just-in-time compiler. These enhancements are particularly beneficial for Arm architectures, as YJIT has been optimized to deliver better performance on such platforms. To leverage these improvements, it is recommended that you upgrade to Ruby 3.4.0 or later. +Ruby 3.4.0 and later introduced major performance enhancements, especially in YJIT (Yet Another Ruby JIT), Ruby’s Just-In-Time compiler. These enhancements are particularly beneficial for Arm architectures, as YJIT has been optimized to deliver better performance on such platforms. To leverage these improvements, it is recommended that you upgrade to Ruby 3.4.0 or later. You can view [this release note](https://www.ruby-lang.org/en/news/2024/12/25/ruby-3-4-0-released/) The [Arm Ecosystem Dashboard](https://developer.arm.com/ecosystem-dashboard/) recommends Ruby version 3.4.0, the minimum recommended on the Arm platforms. {{% /notice %}} ### Install Bundler -**Bundler** manages Ruby project dependencies and ensures consistent gem versions across environments. +Bundler is Ruby’s dependency management tool. It ensures that all required gems (libraries) for your Rails application are installed and consistent across development, test, and production environments. + +Install Bundler globally: ```console gem install bundler ``` +This command installs Bundler for the active Ruby version managed by rbenv. ### Install Rails -Rails is a full-stack web application framework for Ruby that simplifies building database-backed web applications with convention over configuration. +Rails is a full-stack web framework built in Ruby, designed for rapid development using convention over configuration principles. +Installing Rails on your SUSE Arm64 VM enables you to build and deploy web applications natively on Google Cloud Axion (C4A) processors. ```console gem install rails -rails -v ``` -- Installs the Rails framework -- `rails -v` verifies the installed Rails version +### Verify Rails version +Confirms that Rails is installed and accessible from your environment: + +```console +rails -v +``` You should see output similar to: ```output Rails 8.0.3 From 7a9a38c3f7fc3829c6e0e73f07fb2398147655b7 Mon Sep 17 00:00:00 2001 From: pareenaverma Date: Wed, 5 Nov 2025 11:39:22 -0500 Subject: [PATCH 07/11] Update installation.md --- .../servers-and-cloud-computing/ruby-on-rails/installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/installation.md b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/installation.md index 46fc2d27be..2f3ad38c1b 100644 --- a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/installation.md +++ b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/installation.md @@ -94,4 +94,4 @@ You should see output similar to: Rails 8.0.3 ``` -Ruby/Rails installation is complete. You can now proceed with the baseline testing. +You have now installed Ruby and Rails on your Google Cloud C4A Arm-based VM. You can now proceed with the baseline testing. From 612c8976541d7a000bcf5118036a9925c97473c1 Mon Sep 17 00:00:00 2001 From: pareenaverma Date: Wed, 5 Nov 2025 12:23:42 -0500 Subject: [PATCH 08/11] Update baseline.md --- .../ruby-on-rails/baseline.md | 123 +++++++++++------- 1 file changed, 77 insertions(+), 46 deletions(-) diff --git a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md index e5e12fe1f0..f03a8b6d73 100644 --- a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md +++ b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/baseline.md @@ -7,21 +7,23 @@ layout: learningpathall --- ## Baseline Setup for Ruby on Rails with PostgreSQL -This section covers the installation and configuration of **PostgreSQL** and a **Rails application** on a SUSE Arm-based GCP VM. It includes setting up PostgreSQL, creating a Rails app, configuring the database, and starting the Rails server. +This section sets up PostgreSQL and connects it with a Ruby on Rails application on a SUSE Arm64 Google Cloud C4A virtual machine. You’ll install PostgreSQL, configure it for Rails, create a database user, and verify that Rails can connect and serve requests successfully. ### Install and Configure PostgreSQL -PostgreSQL is used with Ruby on Rails as a robust, production-ready relational database that reliably stores and manages application data. +PostgreSQL is a robust, production-grade relational database that integrates seamlessly with Ruby on Rails. + +Install PostgreSQL and its development headers: ```console sudo zypper install postgresql-devel postgresql-server -sudo systemctl start postgresql -sudo systemctl enable postgresql ``` - `postgresql-devel` is required to compile the pg gem for Rails. -Verify that the PostgreSQL service is active and running: +After installation, ensure that PostgreSQL is running and configured to start automatically at boot: ```console +sudo systemctl start postgresql +sudo systemctl enable postgresql systemctl status postgresql ``` The output should look like: @@ -41,55 +43,64 @@ The output should look like: ├─ 27003 "postgres: autovacuum launcher " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "> └─ 27004 "postgres: logical replication launcher " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "> ``` +If the Active state reads running, your PostgreSQL service is operational and ready for configuration. -This command creates a new PostgreSQL role (user) named `gcpuser` with **superuser privileges**. +### Create a Database Role for Rails +Next, create a dedicated PostgreSQL role (user) that Rails will use to connect to the database. ```console sudo -u postgres psql -c "CREATE USER gcpuser WITH SUPERUSER PASSWORD 'your_password';" ``` -- `sudo -u postgres` → Runs the command as the `postgres` user (default PostgreSQL superuser). -- `createuser --superuser gcpuser` → Creates a PostgreSQL role named `gcpuser` with full admin privileges. - - Can create databases - - Can create other roles/users - - Can grant privileges +This command: + +Executes under the default PostgreSQL superuser account (postgres). +Creates a new PostgreSQL role called gcpuser. +Assigns superuser privileges, allowing the user to create databases, manage roles, and execute administrative tasks. -This role will be used by Rails to connect to the PostgreSQL database. +This user will serve as the Rails database owner and be referenced in the Rails configuration file (config/database.yml) later. ### Set Environment variables -Before you create your Rails app, set the following environment variables: +Before creating your Rails application, export environment variables so Rails and the `pg gem` can authenticate automatically with PostgreSQL. ```console export PGUSER=gcpuser export PGPASSWORD=your_password export PGHOST=localhost ``` + +PGUSER → Specifies the PostgreSQL user that Rails will connect as. +PGPASSWORD → Stores the password for that user in memory (temporary for this session). +PGHOST → Points to the PostgreSQL host (in this case, the local VM). + ### Create a Rails App with PostgreSQL -Creates a new Rails application configured to use PostgreSQL as its database. +Now, generate a new Rails application configured to use PostgreSQL as its default database adapter: ```console rails new db_test_rubyapp -d postgresql cd db_test_rubyapp bundle install ``` -- Creates a new Rails application called `db_test_app`. -- `d postgresql` → Tells Rails to use PostgreSQL as the database instead of the default SQLite. -- `bundle install` ensures all required gems are installed. +- rails new db_test_rubyapp → Creates a new Rails application named db_test_rubyapp. +- `d postgresql` → Instructs Rails to use PostgreSQL instead of the default SQLite database. +- bundle install → Installs all gem dependencies defined in the Gemfile, including the pg gem that connects Rails to PostgreSQL. {{% notice Note %}} Check `config/database.yml` to ensure the `username` and `password` match your PostgreSQL role `(gcpuser)`. {{% /notice %}} ### Verify and Update Database Configuration -Open and modify your Rails database configuration file: +Rails uses the `config/database.yml` file to define how it connects to databases in different environments (development, test, and production). +It's important to verify that these credentials align with the PostgreSQL role you created earlier. + +Open the file with your preferred text editor: ```console sudo vi config/database.yml ``` -Find the `default`: and `development`: sections. -Ensure the username matches the PostgreSQL user you created (gcpuser): +Locate the default and development sections, and make sure they match the PostgreSQL user and password you configured. -You should see output similar to: +Your configuration file should have the following fields set: ```output default: &default adapter: postgresql @@ -104,34 +115,49 @@ development: ``` ### Change the Authentication Method -Change the authentication method in the PostgreSQL configuration file `pg_hba.conf` from `ident` to `md5`. +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. + +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. Open your configuration file ```console sudo vi /var/lib/pgsql/data/pg_hba.conf ``` -Find lines that look like this: +The file location `/var/lib/pgsql/data/pg_hba.conf` is the default data directory path for PostgreSQL on SUSE Linux. + +Find lines like the following in the file: + ```output # IPv4 local connections: host all all 127.0.0.1/32 ident # IPv6 local connections: host all all ::1/128 ident ``` -Change the method on these lines to look like: +Modify both lines to use md5, which enables password-based authentication: + ```output # IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 md5 ``` -Save the file. Restart PostgreSQL: +After saving the file, restart the PostgreSQL service to apply the new authentication settings: ```console sudo systemctl restart postgresql ``` + +Verify the change: +```console +sudo systemctl status postgresql +``` +The service should show as active (running). + ### Create and Initialize the Database -Initializes and creates the development and test databases for your Rails app using PostgreSQL. +Once PostgreSQL is configured and Rails can authenticate, you can create your application’s development and test databases. +This step verifies that Rails is correctly connected to PostgreSQL and that the pg gem is working on your Arm64 environment. +Run the following command from inside your Rails app directory: ```console rails db:create ``` @@ -140,22 +166,26 @@ You should see output similar to: Created database 'db_test_rubyapp_development' Created database 'db_test_rubyapp_test' ``` -This means Rails successfully connected to PostgreSQL and created both dev and test databases. +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. ### Generate a Scaffold for Testing -A database and Scaffold are required to create the actual PostgreSQL database for your Rails app and quickly generate the model, controller, views, and migrations for your data. -Let’s create a small test model and table — for example, a simple Task tracker: +To verify your Ruby on Rails and PostgreSQL integration, you’ll create a small scaffold application. +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. + +For this example, you’ll create a simple Task Tracker app that manages tasks with titles and due dates. +Run the following command inside your Rails project directory: ```console rails generate scaffold task title:string due_date:date ``` -This command automatically generates: -- Database migration for the tasks table -- A model (task.rb) -- A controller and views for CRUD operations -- **Scaffold** → Automatically generates boilerplate code for CRUD operations, saving time and ensuring your app has working forms and routes. +This single command automatically generates: +A database migration to create the tasks table in PostgreSQL. +A model file (app/models/task.rb) that maps to the tasks table. +A controller (app/controllers/tasks_controller.rb) with full CRUD actions (index, show, new, create, edit, update, destroy). +Corresponding views in app/views/tasks/ with ready-to-use HTML + embedded Ruby templates. +Route entries in config/routes.rb to make the new resource accessible via /tasks. -Then apply the migration: +Now apply the migration to create the tasks table in your PostgreSQL database: ```console rails db:migrate @@ -169,17 +199,16 @@ You should see output similar to: == 20251006101717 CreateTasks: migrated (0.0128s) ============================= ``` -Database schema successfully updated. +This confirms that Rails connected successfully to PostgreSQL and the database schema was updated. +The new tasks table was created inside your db_test_rubyapp_development database. ### Verify Table and Database Connectivity -The previous command `rails generate scaffold task title:string due_date:date` created a `tasks` table in your PostgreSQL database. - -Now, verify that the table exists and has the correct structure following the steps below: +TThe scaffold created a tasks table in your PostgreSQL database. Verify it exists and has the expected schema: ```console sudo -u postgres psql ``` -In the PostgreSQL shell, run the following commands: +Inside the PostgreSQL shell, run: ```console \c db_test_rubyapp_development @@ -211,7 +240,7 @@ Indexes: "tasks_pkey" PRIMARY KEY, btree (id) ``` -### Run Rails Server +### Open port 3000 in Google Cloud (VPC firewall) Before proceeding to run the Rails server, you need to allow port 3000 from your GCP console. Below are the steps to do that: a. On the GCP console, navigate to **Firewall** -> **Create Firewall Rule** @@ -241,13 +270,13 @@ In the **"Protocols and Ports"**, click on **"TCP"**, and mention the port numbe Click on **"Create"**. The Firewall rule will be created successfully and can be viewed in the Firewall Policies Page: ![ Create Firewall rule alt-text#center](images/firewall5.png "Figure 5: Create Firewall rule") - -Once done, go back to the VM, install FirewallD + + ### OS firewall (firewalld) on SUSE +Once done, go back to your VM, install FirewallD: ```console sudo zypper install firewalld ``` - -Now start FirewallD and execute the below commands to allow port 3000: +Now start FirewallD and execute the commands to allow port 3000: ```console sudo systemctl start firewalld @@ -255,6 +284,8 @@ sudo systemctl enable firewalld sudo firewall-cmd --permanent --add-port=3000/tcp sudo firewall-cmd --reload ``` + +## Start Rails Now that port 3000 is allowed in your VM’s ingress firewall rules, you can start the Rails server using the following command: ```console @@ -276,4 +307,4 @@ You will see a Rails welcome page in your browser if everything is set up correc ![Rails-info page alt-text#center](images/rails-web.png "Figure 6: Ruby/Rails Welcome Page") -This verifies the basic functionality of the Ruby/Rails installation before proceeding to the benchmarking. +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. From a4cd4d2c0ee98ff44f1d197debfcea7355be1387 Mon Sep 17 00:00:00 2001 From: pareenaverma Date: Wed, 5 Nov 2025 12:32:06 -0500 Subject: [PATCH 09/11] Update benchmarking.md --- .../ruby-on-rails/benchmarking.md | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/benchmarking.md b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/benchmarking.md index bb96e05e79..16eb6c45a2 100644 --- a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/benchmarking.md +++ b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/benchmarking.md @@ -7,21 +7,21 @@ layout: learningpathall --- -## Ruby on Rails Benchmarking with built-in Benchmark -This section benchmarks 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. +## Ruby on Rails Benchmarking +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. ### Go into your Rails app folder -You need to 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. +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. ```console cd ~/db_test_rubyapp ```` -### Create the benchmark file inside the app -We create a new Ruby file named `benchmark.rb` where we will write code to measure performance. +### Create the benchmark +Now create a new Ruby file named `benchmark.rb` where you will write code to measure performance. ```console -nano benchmark.rb +vi benchmark.rb ``` ### Benchmark code for measuring Rails app performance @@ -62,21 +62,21 @@ end This code gives you a basic understanding of how your Rails app performs under different types of workloads. ### Run the benchmark inside Rails -Now that your benchmark file is ready, run it **within the Rails environment** using the following command: +Now that your benchmark file is ready, run it within the Rails environment using the following command: ```console rails runner benchmark.rb ``` -- `rails runner` runs any Ruby script in the context of your Rails application. +`rails runner` runs any Ruby script in the context of your Rails application. -- It automatically loads your **Rails environment**, including: +It automatically loads your Rails environment, including: - All models (like `Task`) - Database connections - Configuration and dependencies -- This ensures that your benchmark can interact with the **PostgreSQL database** through ActiveRecord, rather than running as a plain Ruby script. +This ensures that your benchmark can interact with the PostgreSQL database through ActiveRecord, rather than running as a plain Ruby script. -You should see an output similar to: +You should see output similar to: ```output user system total real @@ -92,17 +92,8 @@ Computation: 0.410907 0.000000 0.410907 ( 0.410919) - **total** → `user + system` (sum of CPU processing time). - **real** → The **wall-clock time** (actual elapsed time, includes waiting for DB, I/O, etc). -### Benchmark summary on x86_64 -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: - -| Task | user (sec) | system (sec) | total (sec) | real (sec) | -|--------------|------------|--------------|-------------|------------| -| DB Insert | 1.902564 | 0.061805 | 1.964369 | 2.606764 | -| DB Query | 2.725923 | 0.009513 | 2.735436 | 2.735956 | -| Computation | 0.331519 | 0.000083 | 0.331602 | 0.331610 | - ### Benchmark summary on Arm64 -Results from the earlier run on the `c4a-standard-4` (4 vCPU, 16 GB memory) Arm64 VM in GCP (SUSE): +Results summarized from the your run on the `c4a-standard-4` (4 vCPU, 16 GB memory) Arm64 VM in GCP (SUSE): | Task | user (sec) | system (sec) | total (sec) | real (sec) | @@ -112,9 +103,9 @@ Results from the earlier run on the `c4a-standard-4` (4 vCPU, 16 GB memory) Arm6 | Computation | 0.410907 | 0.000000 | 0.410907 | 0.410919 | -### Ruby/Rails performance benchmarking comparison on Arm64 and x86_64 +### Analysis of Results -When you compare the benchmarking results, you will notice that on the Google Axion C4A Arm-based instances: +When you look the benchmarking results, you will notice that on the Google Axion C4A Arm-based instances: - **Database operations are the main bottleneck:** DB Insert and DB Query take the most time. - **DB Query has the highest latency:** It is the slowest operation at 3.39 seconds. From b5b0052cb4ba127ca7bba3f0091d8f85d97a8939 Mon Sep 17 00:00:00 2001 From: pareenaverma Date: Wed, 5 Nov 2025 12:39:43 -0500 Subject: [PATCH 10/11] Update benchmarking.md --- .../ruby-on-rails/benchmarking.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/benchmarking.md b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/benchmarking.md index 16eb6c45a2..9790e7cc2e 100644 --- a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/benchmarking.md +++ b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/benchmarking.md @@ -103,10 +103,12 @@ Results summarized from the your run on the `c4a-standard-4` (4 vCPU, 16 GB memo | Computation | 0.410907 | 0.000000 | 0.410907 | 0.410919 | -### Analysis of Results +### Key Takeaways When you look the benchmarking results, you will notice that on the Google Axion C4A Arm-based instances: -- **Database operations are the main bottleneck:** DB Insert and DB Query take the most time. -- **DB Query has the highest latency:** It is the slowest operation at 3.39 seconds. -- **Core computation is fast:** Pure Ruby/Rails calculations complete quickly at 0.41 seconds. +Rails on Arm64 performs consistently: Ruby and PostgreSQL are both natively optimized for Arm, providing stable, predictable latency. +Database I/O remains the main optimization target: Techniques such as query caching, connection pooling, and async queries can improve DB-heavy performance. +Compute-bound tasks scale well: Axion’s Arm cores and Ruby’s YJIT show excellent CPU utilization for non-I/O workloads. + +Ruby on Rails runs efficiently on Google Cloud’s Axion-based C4A Arm64 instances. From 9e451997a2372b31a8cfddc1f31ad71c6c458bbd Mon Sep 17 00:00:00 2001 From: pareenaverma Date: Wed, 5 Nov 2025 12:42:16 -0500 Subject: [PATCH 11/11] Update benchmarking.md --- .../servers-and-cloud-computing/ruby-on-rails/benchmarking.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/benchmarking.md b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/benchmarking.md index 9790e7cc2e..defa70159d 100644 --- a/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/benchmarking.md +++ b/content/learning-paths/servers-and-cloud-computing/ruby-on-rails/benchmarking.md @@ -25,7 +25,7 @@ vi benchmark.rb ``` ### Benchmark code for measuring Rails app performance -Below mentioned code (`benchmark.rb` file) measures database inserts, queries, and CPU computations in your Rails application using Ruby’s Benchmark library. +Copy the code below into `benchmark.rb`. It measures database inserts, queries, and CPU computations in your Rails application using Ruby’s Benchmark library. ```ruby require 'benchmark'