diff --git a/README.md b/README.md index ee28a337..7857ff2c 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ ===================================== generator=datazen version=3.1.2 - hash=6a3f7b1658909aed705809485a62426b + hash=c18860c7914c78fabefbae5f111993f1 ===================================== --> -# runtimepy ([1.7.0](https://pypi.org/project/runtimepy/)) +# runtimepy ([1.7.1](https://pypi.org/project/runtimepy/)) [![python](https://img.shields.io/pypi/pyversions/runtimepy.svg)](https://pypi.org/project/runtimepy/) ![Build Status](https://github.com/vkottler/runtimepy/workflows/Python%20Package/badge.svg) diff --git a/pyproject.toml b/pyproject.toml index 3913563f..5fd399e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__" [project] name = "runtimepy" -version = "1.7.0" +version = "1.7.1" description = "A framework for implementing Python services." readme = "README.md" requires-python = ">=3.8" diff --git a/runtimepy/__init__.py b/runtimepy/__init__.py index 1d743c44..5eba9124 100644 --- a/runtimepy/__init__.py +++ b/runtimepy/__init__.py @@ -1,7 +1,7 @@ # ===================================== # generator=datazen # version=3.1.2 -# hash=428163e0258b1d93839c3226a9246203 +# hash=5d1b6856bd3cb27cb017bd1036a96932 # ===================================== """ @@ -10,4 +10,4 @@ DESCRIPTION = "A framework for implementing Python services." PKG_NAME = "runtimepy" -VERSION = "1.7.0" +VERSION = "1.7.1" diff --git a/runtimepy/net/arbiter/housekeeping/__init__.py b/runtimepy/net/arbiter/housekeeping/__init__.py index 318c347e..0a8f3034 100644 --- a/runtimepy/net/arbiter/housekeeping/__init__.py +++ b/runtimepy/net/arbiter/housekeeping/__init__.py @@ -30,7 +30,7 @@ async def dispatch(self) -> bool: def metrics_poller( - manager: _ConnectionManager, period_s: float = 0.1 + manager: _ConnectionManager, period_s: float = 0.5 ) -> ConnectionMetricsPoller: """Create a metrics-polling task.""" diff --git a/runtimepy/net/metrics.py b/runtimepy/net/metrics.py index 69bbb696..23e63e12 100644 --- a/runtimepy/net/metrics.py +++ b/runtimepy/net/metrics.py @@ -3,13 +3,15 @@ """ # third-party -from vcorelib.math import RateTracker +from vcorelib.math import RateTracker as _RateTracker # internal from runtimepy.primitives import Float as _Float from runtimepy.primitives import Uint32 as _Uint32 from runtimepy.primitives import Uint64 as _Uint64 +METRICS_DEPTH = 50 + class ChannelMetrics: """Metrics for a network channel.""" @@ -18,23 +20,33 @@ def __init__(self) -> None: """Initialize this instance.""" self.messages = _Uint32() + self.message_rate = _Float() + self._message_rate_tracker = _RateTracker(depth=METRICS_DEPTH) + self.bytes = _Uint64() self.kbps = _Float() - self._kbps_tracker = RateTracker() - self.stale = True + self._kbps_tracker = _RateTracker(depth=METRICS_DEPTH) def poll(self, time_ns: int = None) -> None: """Poll kbps tracking.""" + self.kbps.raw.value = self._kbps_tracker.poll(time_ns=time_ns) + self.message_rate.raw.value = self._message_rate_tracker.poll( + time_ns=time_ns + ) def increment(self, count: int, time_ns: int = None) -> None: """Update tracking.""" + self.messages.raw.value += 1 + self.message_rate.raw.value = self._message_rate_tracker( + time_ns=time_ns + ) + self.bytes.raw.value += count self.kbps.raw.value = self._kbps_tracker( time_ns=time_ns, value=float(count) / 1000.0 ) - self.stale = False def reset(self) -> None: """Reset metrics.""" @@ -43,7 +55,6 @@ def reset(self) -> None: self.bytes.raw.value = 0 self.kbps.raw.value = 0.0 self._kbps_tracker() - self.stale = True class ConnectionMetrics: