-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
224 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
# RUNVM Specification | ||
Currently there is no way for code in TVM to call external untrusted code "in sandbox". In other words, external code always can irreversibly update code, data of contract, or set actions (such as sending all money). | ||
|
||
`RUNVM` instruction allows to spawn an independent VM instance, run desired code and get needed data (stack, registers, gas consumption etc) without risks of polluting caller's state. Running arbitrary code in a safe way may be useful for [v4-style plugins](/v3/documentation/smart-contracts/contracts-specs/wallet-contracts#wallet-v4), Tact's `init` style subcontract calculation etc. | ||
|
||
| xxxxxxxxxxxxx<br/>Fift syntax | xxxxxxxxxxxxxxxxx<br/>Stack | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<br/>Description | | ||
|:-|:-|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| `flags RUNVM` | _`x_1 ... x_n n code [r] [c4] [c7] [g_l] [g_m] - x'_1 ... x'_m exitcode [data'] [c4'] [c5] [g_c]`_ | Runs child VM with code `code` and stack `x_1...x_n`. Returns the resulting stack `x'_1...x'_m` and exitcode.<br/>Other arguments and return values are enabled by flags, see below. | | ||
| `RUNVMX` | _`x_1 ... x_n n code [r] [c4] [c7] [g_l] [g_m] flags - x'_1 ... x'_m exitcode [data'] [c4'] [c5] [g_c]`_ | Same thing, but pops flags from stack. | | ||
|
||
Flags are similar to `runvmx` in fift: | ||
- `+1`: set c3 to code | ||
- `+2`: push an implicit 0 before running the code | ||
- `+4`: take `c4` from stack (persistent data), return its final value | ||
- `+8`: take gas limit `g_l` from stack, return consumed gas `g_c` | ||
- `+16`: take `c7` from stack (smart-contract context) | ||
- `+32`: return final value of `c5` (actions) | ||
- `+64`: pop hard gas limit (enabled by ACCEPT) `g_m` from stack | ||
- `+128`: "isolated gas consumption". Child VM will have a separate set of visited cells and a separate chksgn counter. | ||
- `+256`: pop integer `r`, return exactly `r` values from the top: | ||
- If RUNVM call successful and r is set, it returns r elements. If r not set - returns all; | ||
- if RUNVM successful but there is not enough elements on stack (stack depth less than r) it is considered as exception in child VM, with exit_code=-3 and exit_arg=0 (so 0 is returned as only stack element); | ||
- if RUNVM fails with exception - only one element is returned - exit arg (not to be mistaken with exit_code); | ||
- in case of OOG, exit_code = -14 and exit_arg is amount of gas. | ||
|
||
Gas cost: | ||
- 66 gas | ||
- 1 gas for every stack element given to the child VM (first 32 are free) | ||
- 1 gas for every stack element returned from the child VM (first 32 are free) | ||
|
||
## See Also | ||
|
||
- [TVM Instructions](/v3/documentation/tvm/instructions) |
171 changes: 171 additions & 0 deletions
171
docs/v3/guidelines/nodes/monitoring/performance-monitoring.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
# Performance Monitoring | ||
|
||
## Monitoring TON server performance | ||
|
||
|
||
Tools like `htop`, `iotop`, `iftop`, `dstat`, `nmon` and others are good for measuring real-time performance, but they lack functionalities when it comes to troubleshooting past performance. | ||
|
||
This guide recommends and explains how to use the Linux sar (System Activity Report) utility for TON server performance monitoring. | ||
|
||
:::tip | ||
This guideline helps to identify if your server experiences any resource shortage, not if validator-engine performs badly. | ||
::: | ||
|
||
### Installation | ||
#### SAR Installation | ||
|
||
```bash | ||
sudo apt-get install sysstat | ||
``` | ||
|
||
#### Enable automatic statistics gathering | ||
|
||
```bash | ||
sudo sed -i 's/false/true/g' /etc/default/sysstat | ||
``` | ||
|
||
#### Enable the service | ||
|
||
```bash | ||
sudo systemctl enable sysstat sysstat-collect.timer sysstat-summary.timer | ||
``` | ||
|
||
|
||
#### Start the service | ||
|
||
```bash | ||
sudo systemctl start sysstat sysstat-collect.timer sysstat-summary.timer | ||
``` | ||
|
||
### Usage | ||
|
||
By default sar gathers statistics every 10 minutes and shows statistics for the current day, starting at midnight. You can check it by running sar without parameters: | ||
|
||
```bash | ||
sar | ||
``` | ||
|
||
|
||
If you want to see statistics of the previous day or two days before, pass the number as an option: | ||
|
||
```bash | ||
sar -1 # previous day | ||
sar -2 # two days ago | ||
``` | ||
|
||
For the exact date, you should use the f option to point to the sa file of a given day within a month. Thus, for the September 23rd it would be: | ||
|
||
```bash | ||
sar -f /var/log/sysstat/sa23 | ||
``` | ||
|
||
What sar reports to run and how to read them in order to identify performance issues? | ||
|
||
Below is the list of sar commands that can be used to gather different system statistics. You can supplement them with the above options to quickly get the reports for the required date. | ||
|
||
|
||
|
||
### Memory report | ||
|
||
```bash | ||
sar -rh | ||
``` | ||
|
||
Since the TON validator-engine utilizes jemalloc feature it caches a lot of data, this is the reason why sar -rh command most of the time returns a low number in column `%memused`. | ||
|
||
At the same time, there always be a high number in the column `kbcached`. For the same reason, you should not worry about the low number of free RAM shown in column `kbmemfree`. The important indicator however is the number that comes from the `%memused` column. | ||
|
||
If it goes above 90% you should consider adding more RAM and keep an eye if your validator engine is not stopping abnormally due to OOM (out of memory) reason - the best way to check that is to grep `/var/ton-work/log` file for Signal messages. | ||
|
||
|
||
|
||
Swap usage | ||
|
||
```bash | ||
sar -Sh | ||
``` | ||
|
||
If you notice that swap is used you should consider adding more RAM. The general recommendation from the TON Core team is to have swap disabled. | ||
|
||
|
||
|
||
### CPU report | ||
|
||
```bash | ||
sar -u | ||
``` | ||
|
||
If your server utilizes CPU on average up to 70% (see '%user' column), this should be considered as good. | ||
|
||
|
||
|
||
### Disk Usage report | ||
|
||
```bash | ||
sar -dh | ||
``` | ||
|
||
Watch the '%util' column and react accordingly if it stays above 90% for a particular disk. | ||
|
||
|
||
|
||
### Network report | ||
|
||
```bash | ||
sar -n DEV -h | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
sar -n DEV -h --iface=<interface name> | ||
``` | ||
|
||
if you want to filter results by network interface name. | ||
|
||
Check out the result of column `%ifutil` - it shows the usage of your interface considering its maximum link speed. | ||
|
||
You can check what speed is supported by your NIC by executing the command below: | ||
|
||
```bash | ||
cat /sys/class/net/<interface>/speed | ||
``` | ||
|
||
:::info | ||
This is not the link speed your provider provided you. | ||
::: | ||
|
||
Consider upgrading your link speed if `%ifutil` shows above 70% usage, or columns rxkB/s and txkB/s reporting values close to a bandwidth provided by your provider. | ||
|
||
|
||
|
||
### Reporting a performance issue | ||
|
||
Before reporting any performance issues, please ensure you are fulfilling the minimal requirements for the node. Then execute the following commands: | ||
|
||
```bash | ||
sar -rudh | cat && sar -n DEV -h --iface=eno1 | cat > report_today.txt | ||
``` | ||
|
||
For yesterday's report execute: | ||
|
||
```bash | ||
sar -rudh -1 | cat && sar -n DEV -h --iface=eno1 -1 | cat > report_yesterday.txt | ||
``` | ||
|
||
Also, stop the TON node and measure your disk IO and network speed. | ||
|
||
```bash | ||
sudo fio --randrepeat=1 --ioengine=io_uring --direct=1 --gtod_reduce=1 --name=test --filename=/var/ton-work/testfile --bs=4096 --iodepth=1 --size=40G --readwrite=randread --numjobs=1 --group_reporting | ||
``` | ||
|
||
Look for value at `read: IOPS=` and send it with the report. A value above 10k IOPS should be considered good. | ||
|
||
```bash | ||
curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python3 - | ||
``` | ||
Download and Upload speeds above 700 Mbit/s should be regarded as good. | ||
|
||
When reporting please send the SAR report as well as IOPS and network speed results to [@mytonctrl_help_bot](https://t.me/mytonctrl_help_bot). | ||
|
||
Initial version by [@neodix](https://t.me/neodix) - Ton Core team, September 23, 2024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters