Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/docket/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import inspect
from typing import Any, Iterable, Mapping, Self

from .instrumentation import CACHE_SIZE


class Annotation(abc.ABC):
_cache: dict[tuple[type[Self], inspect.Signature], Mapping[str, Self]] = {}
Expand All @@ -10,6 +12,7 @@ class Annotation(abc.ABC):
def annotated_parameters(cls, signature: inspect.Signature) -> Mapping[str, Self]:
key = (cls, signature)
if key in cls._cache:
CACHE_SIZE.set(len(cls._cache), {"cache": "annotation"})
return cls._cache[key]

annotated: dict[str, Self] = {}
Expand All @@ -30,6 +33,7 @@ def annotated_parameters(cls, signature: inspect.Signature) -> Mapping[str, Self
annotated[param_name] = arg_type()

cls._cache[key] = annotated
CACHE_SIZE.set(len(cls._cache), {"cache": "annotation"})
return annotated


Expand Down
3 changes: 3 additions & 0 deletions src/docket/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from .docket import Docket
from .execution import Execution, TaskFunction, get_signature
from .instrumentation import CACHE_SIZE

if TYPE_CHECKING: # pragma: no cover
from .worker import Worker
Expand Down Expand Up @@ -415,6 +416,7 @@ def get_dependency_parameters(
function: TaskFunction | DependencyFunction[Any],
) -> dict[str, Dependency]:
if function in _parameter_cache:
CACHE_SIZE.set(len(_parameter_cache), {"cache": "parameter"})
return _parameter_cache[function]

dependencies: dict[str, Dependency] = {}
Expand All @@ -428,6 +430,7 @@ def get_dependency_parameters(
dependencies[parameter] = param.default

_parameter_cache[function] = dependencies
CACHE_SIZE.set(len(_parameter_cache), {"cache": "parameter"})
return dependencies


Expand Down
4 changes: 3 additions & 1 deletion src/docket/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from opentelemetry import propagate, trace

from .annotations import Logged
from .instrumentation import message_getter
from .instrumentation import CACHE_SIZE, message_getter

logger: logging.Logger = logging.getLogger(__name__)

Expand All @@ -32,10 +32,12 @@

def get_signature(function: Callable[..., Any]) -> inspect.Signature:
if function in _signature_cache:
CACHE_SIZE.set(len(_signature_cache), {"cache": "signature"})
return _signature_cache[function]

signature = inspect.signature(function)
_signature_cache[function] = signature
CACHE_SIZE.set(len(_signature_cache), {"cache": "signature"})
return signature


Expand Down
6 changes: 6 additions & 0 deletions src/docket/instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
unit="1",
)

CACHE_SIZE = meter.create_gauge(
"docket_cache_size",
description="Size of internal docket caches",
unit="1",
)

Message = dict[bytes, bytes]


Expand Down
Loading