Repository: risingwavelabs/risingwave
File: grafana/dashboard/dev/streaming_actors_tokio.py (Python)

Code before:
from . import section


@section
def _(outer_panels: Panels):
    panels = outer_panels.sub_panel()
    return [
        outer_panels.row_collapsed(
            "Streaming Actors (Tokio)",
            [
                panels.timeseries_percentage(
                    "Actor Execution Rate",
                    "",
                    [
                        panels.target(
                            f"rate({metric('stream_actor_execution_duration')}[$__rate_interval]) / 1000000000",
                            "actor {{actor_id}} fragment {{fragment_id}}",
                        ),
                    ],
                ),
                panels.timeseries_percentage(
                    "Tokio: Actor Fast Poll Rate",
                    "",
                    [
                        panels.target(
                            f"rate({metric('stream_actor_fast_poll_duration')}[$__rate_interval]) / 1000000000",
                            "actor {{actor_id}} fragment {{fragment_id}}",
                        ),
                    ],
                ),
                panels.timeseries_actor_ops_small(
                    "Tokio: Actor Fast Poll Count",
                    "",
                    [
                        panels.target(
                            f"rate({metric('stream_actor_fast_poll_cnt')}[$__rate_interval]) > 0",
                            "actor {{actor_id}} fragment {{fragment_id}}",
                        ),
                    ],
                ),
                panels.timeseries_percentage(
                    "Tokio: Actor Fast Poll Avg Rate",
                    "",
                    [
                        panels.target(
                            f"rate({metric('stream_actor_fast_poll_duration')}[$__rate_interval]) / (rate({metric('stream_actor_fast_poll_cnt')}[$__rate_interval]) > 0) / 1000000000",
                            "actor {{actor_id}} fragment {{fragment_id}}",
                        ),
                    ],
                ),
                panels.timeseries_actor_latency_small(

Review comment (performance):
We use an int counter instead for better performance, and consistency with other latency measures (e.g. backpressure metrics). We increment in `nanoseconds` to maintain precision, so we need to normalize by 1e9 here.

Code after:
from . import section


@section
def _(outer_panels: Panels):
    panels = outer_panels.sub_panel()
    return [
        outer_panels.row_collapsed(
            "Streaming Actors (Tokio)",
            [
                panels.timeseries_percentage(
                    "Tokio: Actor Poll Rate Per Actor",
                    "This can be used to estimate the CPU usage of an actor",
                    [
                        panels.target(
                            f"sum(rate({metric('stream_actor_poll_duration')}[$__rate_interval])) by (fragment_id)"
                            f"/ on(fragment_id) sum({metric('stream_actor_count')}) by (fragment_id)"
                            f" / 1000000000",
                            "fragment {{fragment_id}}",
                        ),
                    ],
                ),
                panels.timeseries_actor_ops_small(
                    "Tokio: Actor Poll Count",
                    "",
                    [
                        panels.target(
                            f"rate({metric('stream_actor_poll_cnt')}[$__rate_interval]) > 0",
                            "fragment {{fragment_id}}",
                        ),
                    ],
                ),
                panels.timeseries_percentage(
                    "Tokio: Actor Poll Avg Rate Per Poll",
                    "",
                    [
                        panels.target(
                            f"rate({metric('stream_actor_poll_duration')}[$__rate_interval]) / (rate({metric('stream_actor_poll_cnt')}[$__rate_interval]) > 0) / 1000000000",
                            "fragment {{fragment_id}}",
                        ),
                    ],
                ),
                panels.timeseries_percentage(
                    "Tokio: Actor Idle Rate Per Actor",
                    "Idle time could be due to no data to process, or waiting for async operations like IO",
                    [
                        panels.target(
                            f"sum(rate({metric('stream_actor_idle_duration')}[$__rate_interval])) by (fragment_id)"
                            f"/ on(fragment_id) sum({metric('stream_actor_count')}) by (fragment_id)"
                            f" / 1000000000",
                            "fragment {{fragment_id}}",