Skip to content

Commit a4cd4d2

Browse files
authored
Update benchmarking.md
1 parent 612c897 commit a4cd4d2

1 file changed

Lines changed: 14 additions & 23 deletions

File tree

  • content/learning-paths/servers-and-cloud-computing/ruby-on-rails

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

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ layout: learningpathall
77
---
88

99

10-
## Ruby on Rails Benchmarking with built-in Benchmark
11-
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.
10+
## Ruby on Rails Benchmarking
11+
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

1313
### Go into your Rails app folder
14-
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.
14+
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 file inside the app
21-
We create a new Ruby file named `benchmark.rb` where we will write code to measure performance.
20+
### Create the benchmark
21+
Now create a new Ruby file named `benchmark.rb` where you will write code to measure performance.
2222

2323
```console
24-
nano benchmark.rb
24+
vi benchmark.rb
2525
```
2626

2727
### Benchmark code for measuring Rails app performance
@@ -62,21 +62,21 @@ end
6262
This code gives you a basic understanding of how your Rails app performs under different types of workloads.
6363

6464
### Run the benchmark inside Rails
65-
Now that your benchmark file is ready, run it **within the Rails environment** using the following command:
65+
Now that your benchmark file is ready, run it within the Rails environment using the following command:
6666

6767
```console
6868
rails runner benchmark.rb
6969
```
70-
- `rails runner` runs any Ruby script in the context of your Rails application.
70+
`rails runner` runs any Ruby script in the context of your Rails application.
7171

72-
- It automatically loads your **Rails environment**, including:
72+
It automatically loads your Rails environment, including:
7373
- All models (like `Task`)
7474
- Database connections
7575
- Configuration and dependencies
7676

77-
- This ensures that your benchmark can interact with the **PostgreSQL database** through ActiveRecord, rather than running as a plain Ruby script.
77+
This ensures that your benchmark can interact with the PostgreSQL database through ActiveRecord, rather than running as a plain Ruby script.
7878

79-
You should see an output similar to:
79+
You should see output similar to:
8080

8181
```output
8282
user system total real
@@ -92,17 +92,8 @@ Computation: 0.410907 0.000000 0.410907 ( 0.410919)
9292
- **total**`user + system` (sum of CPU processing time).
9393
- **real** → The **wall-clock time** (actual elapsed time, includes waiting for DB, I/O, etc).
9494

95-
### Benchmark summary on x86_64
96-
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:
97-
98-
| Task | user (sec) | system (sec) | total (sec) | real (sec) |
99-
|--------------|------------|--------------|-------------|------------|
100-
| DB Insert | 1.902564 | 0.061805 | 1.964369 | 2.606764 |
101-
| DB Query | 2.725923 | 0.009513 | 2.735436 | 2.735956 |
102-
| Computation | 0.331519 | 0.000083 | 0.331602 | 0.331610 |
103-
10495
### Benchmark summary on Arm64
105-
Results from the earlier run on the `c4a-standard-4` (4 vCPU, 16 GB memory) Arm64 VM in GCP (SUSE):
96+
Results summarized from the your run on the `c4a-standard-4` (4 vCPU, 16 GB memory) Arm64 VM in GCP (SUSE):
10697

10798

10899
| 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
112103
| Computation | 0.410907 | 0.000000 | 0.410907 | 0.410919 |
113104

114105

115-
### Ruby/Rails performance benchmarking comparison on Arm64 and x86_64
106+
### Analysis of Results
116107

117-
When you compare the benchmarking results, you will notice that on the Google Axion C4A Arm-based instances:
108+
When you look the benchmarking results, you will notice that on the Google Axion C4A Arm-based instances:
118109

119110
- **Database operations are the main bottleneck:** DB Insert and DB Query take the most time.
120111
- **DB Query has the highest latency:** It is the slowest operation at 3.39 seconds.

0 commit comments

Comments
 (0)