|
22 | 22 | import awe_components.components.viewpointFeatures |
23 | 23 | import awe_components.components.lexicalClusters |
24 | 24 | import awe_components.components.contentSegmentation |
| 25 | +from writing_observer.caching_performance import CachePerformance |
25 | 26 | import json |
26 | 27 | import warnings |
27 | 28 |
|
|
30 | 31 | import learning_observer.util |
31 | 32 |
|
32 | 33 | RUN_MODES = enum.Enum('RUN_MODES', 'MULTIPROCESSING SERIAL') |
| 34 | +cache_stats = CachePerformance() |
33 | 35 |
|
34 | 36 |
|
35 | 37 | def init_nlp(): |
@@ -316,6 +318,15 @@ async def process_and_cache_missing_features(unfound_features, found_features, r |
316 | 318 | await cache.set(text_hash, text_cache_data) |
317 | 319 | return writing |
318 | 320 |
|
| 321 | +async def update_cache_stats(hits=0, misses=0): |
| 322 | + """ |
| 323 | + Updates cache statistics like Hits and Misses. |
| 324 | + """ |
| 325 | + if hits!= 0: |
| 326 | + await cache_stats.increment_hit_count(hits) |
| 327 | + if misses!=0: |
| 328 | + await cache_stats.increment_miss_count(misses) |
| 329 | + |
319 | 330 |
|
320 | 331 | async def process_writings_with_caching(writing_data, options=None, mode=RUN_MODES.MULTIPROCESSING, sleep_interval=1, wait_time_for_running_features=60): |
321 | 332 | ''' |
@@ -360,18 +371,23 @@ async def process_writings_with_caching(writing_data, options=None, mode=RUN_MOD |
360 | 371 | # If all options were found |
361 | 372 | if found_features == requested_features: |
362 | 373 | results.append(writing) |
| 374 | + await update_cache_stats(hits=len(found_features)) |
363 | 375 | continue |
364 | 376 |
|
365 | 377 | # Check if some options are a subset of running_features: features that are needed but are already running |
366 | 378 | unfound_features, found_features, writing = await check_and_wait_for_running_features(writing, requested_features, found_features, cache, sleep_interval, wait_time_for_running_features, text_hash) |
367 | 379 | # If all options are found |
368 | 380 | if found_features == requested_features: |
369 | 381 | results.append(writing) |
| 382 | + await update_cache_stats(hits=len(found_features)) |
370 | 383 | continue |
371 | 384 |
|
372 | 385 | # Add not found options to running_features and update cache |
373 | 386 | results.append(await process_and_cache_missing_features(unfound_features, found_features, requested_features, cache, text_hash, writing)) |
374 | 387 |
|
| 388 | + # Update Cache Performance |
| 389 | + await update_cache_stats(hits=len(found_features), misses=len(unfound_features)) |
| 390 | + |
375 | 391 | return results |
376 | 392 |
|
377 | 393 |
|
|
0 commit comments