|
| 1 | += Async-profiler |
| 2 | + |
| 3 | +Since https://issues.apache.org/jira/browse/CASSANDRA-20854[CASSANDRA-20854], it is possible to use |
| 4 | +https://github.com/async-profiler/async-profiler[async-profiler] to profile your nodes. Async-profiler is |
| 5 | +shipped with Cassandra, so you do not need to do anything else but start to use it by enabling a property. |
| 6 | +Async-profiler functionality is disabled by default. It can be turned on by setting Cassandra's `cassandra.async_profiler.enabled` property to `true`. |
| 7 | + |
| 8 | +There is a command in `nodetool` called `profile` with these sub-commands: |
| 9 | + |
| 10 | +== start |
| 11 | + |
| 12 | +Basic usage: |
| 13 | +---- |
| 14 | +$ nodetool profile start |
| 15 | +---- |
| 16 | + |
| 17 | +This will start profiling, by default for 60 seconds. If you want, for example, profile memory allocations for |
| 18 | +5 minutes and save results into a file memory-allocation-5m.html you would do: |
| 19 | + |
| 20 | +---- |
| 21 | +$ nodetool profile start -e alloc -d 5m -o memory-allocation-5m.html |
| 22 | +---- |
| 23 | + |
| 24 | +There are these events possible to profile: |
| 25 | + |
| 26 | +'cpu', 'alloc', 'lock', 'wall', 'nativemem', 'cache_misses', delimited by comma, defaults to 'cpu'. |
| 27 | + |
| 28 | +There are these output formats possible to specify, via `--format` flag: |
| 29 | + |
| 30 | +'flat', 'traces', 'collapsed', 'flamegraph', 'tree', 'jfr', 'otlp', defaults to 'flamegraph' |
| 31 | + |
| 32 | +== status |
| 33 | + |
| 34 | +You can then inspect the state of profiling by `status` subcommand: |
| 35 | + |
| 36 | +---- |
| 37 | +$ nodetool profile status |
| 38 | +Profiling is running for 7 seconds |
| 39 | +---- |
| 40 | + |
| 41 | +If you attempt to start another profiling while the current profiling is running, this will not be possible: |
| 42 | + |
| 43 | +---- |
| 44 | +$ nodetool profile start -e alloc -d 5m -o memory-allocation-5m.html |
| 45 | +Profiler has already started or there was a failure to start it. |
| 46 | +---- |
| 47 | + |
| 48 | +== stop |
| 49 | + |
| 50 | +You can stop the profiling prematurely by `stop` sub-command |
| 51 | + |
| 52 | +---- |
| 53 | +$ nodetool profile stop -o memory-allocation-5m.html |
| 54 | +---- |
| 55 | + |
| 56 | +After the profiling is finished, either by waiting until it stops on its own or by us explicitly, we have a result file in a results directory on a node. We can inspect what results there are by `list` sub-command: |
| 57 | + |
| 58 | +== list |
| 59 | + |
| 60 | +---- |
| 61 | +$ nodetool profile list |
| 62 | +memory-allocation-5m.html |
| 63 | +cpu.html |
| 64 | +---- |
| 65 | + |
| 66 | +== fetch |
| 67 | + |
| 68 | +If you have access to a node, you can just go to, by default, |
| 69 | +`logs` directory of Cassandra, into `async-profiler` and obtain a respective file. However, in a scenario when |
| 70 | +you are executing remote profiling (nodetool exection is on a physically different machine from Cassandra node), or you do not have the direct access to remote disk, you need to use `fetch` subcommand, which will sent the content of your result file locally where you can save it to whatever destination you want: |
| 71 | + |
| 72 | +---- |
| 73 | +$ nodetool profile fetch cpu.html /tmp/cpu.html |
| 74 | +---- |
| 75 | + |
| 76 | +== purge |
| 77 | + |
| 78 | +Of course, more you profile, more disk space the results will occupy. If you have direct access, you can just |
| 79 | +remove the files yourself, however if you do not, you need to use `purge` sub-command which will remove all profiling files: |
| 80 | + |
| 81 | +---- |
| 82 | +$ nodetool profile purge |
| 83 | +$ nodetool profile list |
| 84 | +<no output> |
| 85 | +---- |
| 86 | + |
| 87 | +== execute |
| 88 | + |
| 89 | +You can also execute arbitrary commands, by `execute` subcommand, like this: |
| 90 | + |
| 91 | +---- |
| 92 | +nodetool profile execute meminfo |
| 93 | +Call trace storage: 10244 KB |
| 94 | + Flight recording: 0 KB |
| 95 | + Dictionaries: 68 KB |
| 96 | + Code cache: 11934 KB |
| 97 | +------------------------------ |
| 98 | + Total: 22246 KB |
| 99 | +---- |
| 100 | +
|
| 101 | +However, to execute arbitrary commands for Async-profiler, we need to enable _unsafe_ async profiling by system property of Cassandra `cassandra.async_profiler.unsafe_mode` set to `true`. You will not be able to do this otherwise. |
| 102 | +
|
| 103 | +You can also control where profiling files go via `cassandra.logdir.async_profiler` system property. When not set, by default they will be stored to `cassandra.logdir` + `async-profiler` directory. |
0 commit comments