You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/ruby-on-rails/benchmarking.md
+14-23Lines changed: 14 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,21 +7,21 @@ layout: learningpathall
7
7
---
8
8
9
9
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.
12
12
13
13
### 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.
15
15
16
16
```console
17
17
cd ~/db_test_rubyapp
18
18
````
19
19
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.
22
22
23
23
```console
24
-
nano benchmark.rb
24
+
vi benchmark.rb
25
25
```
26
26
27
27
### Benchmark code for measuring Rails app performance
@@ -62,21 +62,21 @@ end
62
62
This code gives you a basic understanding of how your Rails app performs under different types of workloads.
63
63
64
64
### 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:
66
66
67
67
```console
68
68
rails runner benchmark.rb
69
69
```
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.
71
71
72
-
-It automatically loads your **Rails environment**, including:
72
+
It automatically loads your Rails environment, including:
73
73
- All models (like `Task`)
74
74
- Database connections
75
75
- Configuration and dependencies
76
76
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.
-**total** → `user + system` (sum of CPU processing time).
93
93
-**real** → The **wall-clock time** (actual elapsed time, includes waiting for DB, I/O, etc).
94
94
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) |
0 commit comments