[KV Offload] Split cpu_cache_usage_perc into write/read usage gauges (#47666)
Signed-off-by: srinivas_oo7 <sklinkedin0120@gmail.com> Co-authored-by: srinivas_oo7 <sklinkedin0120@gmail.com> Co-authored-by: Or Ozeri <oro@il.ibm.com>
This commit is contained in:
co-authored by
srinivas_oo7
Or Ozeri
parent
ca3618bc69
commit
cdaa40d2a8
@@ -92,6 +92,21 @@ def verify_load_output(
|
||||
assert np.array_equal(expected_array, prepare_load_output.block_ids)
|
||||
|
||||
|
||||
def check_split_usage_stats(
|
||||
manager: CPUOffloadingManager, write: float, read: float, total: float
|
||||
):
|
||||
stats = manager.get_stats()
|
||||
assert stats is not None
|
||||
reduced = stats.reduce()
|
||||
assert reduced[CPUOffloadingMetrics.CPU_CACHE_WRITE_USAGE_PERC] == pytest.approx(
|
||||
write
|
||||
)
|
||||
assert reduced[CPUOffloadingMetrics.CPU_CACHE_READ_USAGE_PERC] == pytest.approx(
|
||||
read
|
||||
)
|
||||
assert reduced[CPUOffloadingMetrics.CPU_CACHE_USAGE_PERC] == pytest.approx(total)
|
||||
|
||||
|
||||
def verify_events(
|
||||
events: Iterable[OffloadingEvent],
|
||||
expected_stores: tuple[set[int], ...] = (),
|
||||
@@ -302,6 +317,40 @@ def test_cpu_manager_reports_allocation_size_on_eviction_failure():
|
||||
assert reduced[f"{CPUOffloadingMetrics.CPU_ALLOCATION_SIZE}_sum"] == 1
|
||||
|
||||
|
||||
def test_cpu_manager_reports_cache_write_and_read_usage_gauges():
|
||||
manager = make_cpu_manager(num_blocks=4)
|
||||
|
||||
# Store path: pins write usage until complete_store.
|
||||
manager.prepare_store(to_keys([1, 2]), _EMPTY_REQ_CTX)
|
||||
check_split_usage_stats(manager, write=0.5, read=0.0, total=0.5)
|
||||
|
||||
manager.complete_store(to_keys([1, 2]), _EMPTY_REQ_CTX)
|
||||
check_split_usage_stats(manager, write=0.0, read=0.0, total=0.0)
|
||||
|
||||
# Load path: pins read usage until complete_load.
|
||||
assert manager.lookup(to_key(1), _EMPTY_REQ_CTX) is LookupResult.HIT
|
||||
manager.prepare_load(to_keys([1]), _EMPTY_REQ_CTX)
|
||||
check_split_usage_stats(manager, write=0.0, read=0.25, total=0.25)
|
||||
|
||||
manager.complete_load(to_keys([1]), _EMPTY_REQ_CTX)
|
||||
check_split_usage_stats(manager, write=0.0, read=0.0, total=0.0)
|
||||
|
||||
# Concurrent write + read pins are both reflected and additive.
|
||||
manager.prepare_store(to_keys([3, 4]), _EMPTY_REQ_CTX)
|
||||
manager.prepare_load(to_keys([2]), _EMPTY_REQ_CTX)
|
||||
check_split_usage_stats(manager, write=0.5, read=0.25, total=0.75)
|
||||
|
||||
|
||||
def test_cpu_manager_clears_write_usage_after_failed_store():
|
||||
manager = make_cpu_manager(num_blocks=4)
|
||||
|
||||
manager.prepare_store(to_keys([1, 2]), _EMPTY_REQ_CTX)
|
||||
check_split_usage_stats(manager, write=0.5, read=0.0, total=0.5)
|
||||
|
||||
manager.complete_store(to_keys([1, 2]), _EMPTY_REQ_CTX, success=False)
|
||||
check_split_usage_stats(manager, write=0.0, read=0.0, total=0.0)
|
||||
|
||||
|
||||
def test_cpu_manager():
|
||||
"""
|
||||
Tests CPUOffloadingManager with lru policy.
|
||||
|
||||
Reference in New Issue
Block a user