Skip to content

Commit ae92a05

Browse files
committed
[GR-19691] Add documentation about benchmarking TruffleRuby
PullRequest: truffleruby/3704
2 parents 8d6a531 + 57c3e31 commit ae92a05

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

doc/user/benchmarking.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
layout: docs-experimental
3+
toc_group: ruby
4+
link_title: Benchmarking TruffleRuby
5+
permalink: /reference-manual/ruby/Benchmarking/
6+
---
7+
# Benchmarking TruffleRuby
8+
9+
This document lists the most important points to consider when benchmarking TruffleRuby.
10+
11+
## Guidelines for Benchmarking TruffleRuby
12+
13+
We expect anyone publishing benchmark numbers about TruffleRuby to follow these guidelines.
14+
15+
### Use TruffleRuby EE
16+
17+
Use TruffleRuby EE, it is faster than CE overall and represents what TruffleRuby is capable of.
18+
19+
### Use the Latest Release
20+
21+
Always use the latest release at the time of benchmarking (so it does not misrepresent TruffleRuby by using an old release which may have known performance issues).
22+
23+
### Use the Correct Runtime Configuration
24+
25+
TruffleRuby has two Runtime Configurations, Native and JVM, see [this comparison](../../README.md#truffleruby-runtime-configurations).
26+
27+
If you want to benchmark peak performance, you should use the JVM configuration.
28+
To do so, set the environment variable `TRUFFLERUBYOPT=--jvm` so it affects all TruffleRuby processes.
29+
You can also pass `--jvm` as an argument to TruffleRuby if you are sure there are no subprocesses.
30+
31+
The Native configuration provides better startup and warmup but has slower peak performance.
32+
33+
Of course you can also benchmark both configurations and see which one is better for what you are benchmarking.
34+
35+
### Consider Disabling the Global C-Extension Lock
36+
37+
On TruffleRuby, C extensions by default use a global lock for maximum compatibility with CRuby.
38+
If you are benchmarking a multi-threaded Ruby program (e.g. Rails on a multi-threaded server), it is worth trying
39+
`TRUFFLERUBYOPT="--experimental-options --cexts-lock=false"`.
40+
[This issue](https://github.com/oracle/truffleruby/issues/2136) tracks a way to automatically not use the lock for extensions which do not need it.
41+
42+
## Recommendations
43+
44+
These are more general recommendations about benchmarking.
45+
46+
### Avoid Benchmarking on a Laptop
47+
48+
Performance on laptops is very sensitive to heat, and so overall quite unstable.
49+
As an example, if the CPU gets too warm the operating system will throttle it, making the benchmark results unfair and unstable.
50+
So benchmarking should be done on on a desktop computer or server.
51+
52+
### Avoid Other Running Processes
53+
54+
As those would cause extra noise in benchmarking results.
55+
Definitely no browser, slack, IDE, etc as those use a lot of CPU.
56+
57+
### Disable Frequency Scaling
58+
59+
CPU frequency scaling and boost generally just increases noise in benchmarking results,
60+
so it is recommended to disable them when benchmarking for more stable results.
61+
62+
For Intel CPUs use:
63+
64+
```bash
65+
sudo sh -c 'echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo'
66+
```
67+
68+
For AMD CPUs use:
69+
70+
```bash
71+
sudo sh -c 'echo 0 > /sys/devices/system/cpu/cpufreq/boost'
72+
```
73+
74+
Also make sure the performance governor is used on Linux:
75+
76+
```bash
77+
sudo cpupower frequency-set -g performance
78+
cpupower frequency-info
79+
```
80+
81+
### Do not pin TruffleRuby to a Single Core
82+
83+
TruffleRuby uses multiple threads for the JIT Compiler, the GC, etc.
84+
Restricting it to a single core for benchmarking does not make sense, it would cause a lot of contention.
85+
86+
### Avoid Benchmarking on macOS
87+
88+
macOS's memory management is sub-par and can cause unnecessary memory swapping even when there is enough memory.
89+
90+
macOS's TCP stack is also sub-par, see the [Passenger docs](https://www.phusionpassenger.com/library/config/apache/optimization/#operating-system-recommendations) on this subject.

0 commit comments

Comments
 (0)