Skip to content

Commit

Permalink
fix(api): improve cache logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Mar 6, 2023
1 parent 39b9741 commit cfc20d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion api/onnx_web/server/model_cache.py
Expand Up @@ -13,15 +13,18 @@ def __init__(self, limit: int) -> None:
self.limit = limit

def drop(self, tag: str, key: Any) -> None:
logger.debug("dropping item from cache: %s", tag)
self.cache[:] = [
model for model in self.cache if model[0] != tag and model[1] != key
]

def get(self, tag: str, key: Any) -> Any:
for t, k, v in self.cache:
if tag == t and key == k:
logger.debug("found cached model: %s", tag)
return v

logger.debug("model not found in cache: %s", tag)
return None

def set(self, tag: str, key: Any, value: Any) -> None:
Expand All @@ -44,7 +47,7 @@ def prune(self):
total = len(self.cache)
if total > self.limit:
logger.info(
"Removing models from cache, %s of %s", (total - self.limit), total
"removing models from cache, %s of %s", (total - self.limit), total
)
self.cache[:] = self.cache[-self.limit :]
else:
Expand Down
4 changes: 2 additions & 2 deletions api/onnx_web/worker/pool.py
Expand Up @@ -245,7 +245,7 @@ def done(self, key: str) -> Tuple[Optional[bool], int]:
return (True, p)

if key not in self.active_jobs:
logger.warn("checking status for unknown job: %s", key)
logger.debug("checking status for unknown job: %s", key)
return (None, 0)

_device, progress = self.active_jobs[key]
Expand Down Expand Up @@ -357,7 +357,7 @@ def submit(
else:
self.total_jobs[device] = 1

logger.debug("device job count: %s", self.total_jobs[device])
logger.debug("job count for device %s: %s", device, self.total_jobs[device])
self.recycle()

self.pending[device].put((key, fn, args, kwargs), block=False)
Expand Down

0 comments on commit cfc20d3

Please sign in to comment.