Skip to content

Commit 128c3e7

Browse files
committed
Changes from running between environments
1 parent f14072d commit 128c3e7

5 files changed

Lines changed: 141 additions & 515 deletions

File tree

cache/__tests__/cache-metrics-worst-case.sh

Lines changed: 42 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,39 +2252,36 @@ test_delete_endpoint_full() {
22522252
}
22532253

22542254
################################################################################
2255-
# Main Test Flow
2255+
# Main Test Flow (REFACTORED TO 5 PHASES - OPTIMIZED)
22562256
################################################################################
22572257

22582258
main() {
22592259
# Capture start time
22602260
local start_time=$(date +%s)
22612261

2262-
log_header "RERUM Cache Comprehensive Metrics & Functionality Test"
2262+
log_header "RERUM Cache WORST CASE Metrics Test"
22632263

22642264
echo "This test suite will:"
22652265
echo " 1. Test read endpoints with EMPTY cache (baseline performance)"
2266-
echo " 2. Fill cache to 1000 entries"
2267-
echo " 3. Test read endpoints with FULL cache (verify speedup)"
2268-
echo " 4. Clear cache and test write endpoints with EMPTY cache (baseline)"
2269-
echo " Note: Cache cleared to measure pure write performance without invalidation overhead"
2270-
echo " 5. Fill cache to 1000 entries again"
2271-
echo " 6. Test write endpoints with FULL cache (measure invalidation overhead)"
2272-
echo " 7. Generate comprehensive metrics report"
2266+
echo " 2. Test write endpoints with EMPTY cache (baseline performance)"
2267+
echo " 3. Fill cache to 1000 entries (intentionally NON-matching for worst case)"
2268+
echo " 4. Test read endpoints with FULL cache (cache misses - worst case)"
2269+
echo " 5. Test write endpoints with FULL cache (maximum invalidation overhead)"
22732270
echo ""
22742271

22752272
# Setup
22762273
check_server
22772274
get_auth_token
22782275
warmup_system
22792276

2280-
# Run all tests following Modified Third Option
2281-
log_header "Running Functionality & Performance Tests"
2277+
# Run optimized 5-phase test flow
2278+
log_header "Running Functionality & Performance Tests (Worst Case Scenario)"
22822279

22832280
# ============================================================
22842281
# PHASE 1: Read endpoints on EMPTY cache (baseline)
22852282
# ============================================================
22862283
echo ""
2287-
log_section "PHASE 1: Read Endpoints on EMPTY Cache (Baseline)"
2284+
log_section "PHASE 1: Read Endpoints with EMPTY Cache (Baseline)"
22882285
echo "[INFO] Testing read endpoints without cache to establish baseline performance..."
22892286
clear_cache
22902287

@@ -2297,38 +2294,51 @@ main() {
22972294
test_since_endpoint
22982295

22992296
# ============================================================
2300-
# PHASE 2: Fill cache with 1000 entries
2297+
# PHASE 2: Write endpoints on EMPTY cache (baseline)
23012298
# ============================================================
23022299
echo ""
2303-
log_section "PHASE 2: Fill Cache with 1000 Entries"
2304-
echo "[INFO] Filling cache to test read performance at scale..."
2305-
fill_cache $CACHE_FILL_SIZE
2300+
log_section "PHASE 2: Write Endpoints with EMPTY Cache (Baseline)"
2301+
echo "[INFO] Testing write endpoints without cache to establish baseline performance..."
2302+
2303+
# Cache is already empty from Phase 1
2304+
test_create_endpoint_empty
2305+
test_update_endpoint_empty
2306+
test_patch_endpoint_empty
2307+
test_set_endpoint_empty
2308+
test_unset_endpoint_empty
2309+
test_overwrite_endpoint_empty
2310+
test_delete_endpoint_empty # Uses objects from create_empty test
23062311

23072312
# ============================================================
2308-
# PHASE 3: Read endpoints on FULL cache (WORST CASE - cache misses)
2313+
# PHASE 3: Fill cache with 1000 entries (WORST CASE)
23092314
# ============================================================
23102315
echo ""
2311-
log_section "PHASE 3: Read Endpoints on FULL Cache (WORST CASE - Cache Misses)"
2312-
echo "[INFO] Testing read endpoints with full cache (${CACHE_FILL_SIZE} entries) using queries that DON'T match cache..."
2313-
echo "[INFO] This measures maximum overhead when cache provides NO benefit (full scan, no hits)..."
2316+
log_section "PHASE 3: Fill Cache with 1000 Entries (Worst Case - Non-Matching)"
2317+
echo "[INFO] Filling cache with entries that will NEVER match test queries (worst case)..."
2318+
fill_cache $CACHE_FILL_SIZE
23142319

2315-
# Test read endpoints with queries that will NOT be in the cache (worst case)
2316-
# Cache is filled with PerfTest, Annotation, and general queries
2317-
# Query for types that don't exist to force full cache scan with no hits
2320+
# ============================================================
2321+
# PHASE 4: Read endpoints on FULL cache (worst case - cache misses)
2322+
# ============================================================
2323+
echo ""
2324+
log_section "PHASE 4: Read Endpoints with FULL Cache (Worst Case - Cache Misses)"
2325+
echo "[INFO] Testing read endpoints with full cache (${CACHE_FILL_SIZE} entries) - all cache misses..."
23182326

2327+
# Test read endpoints WITHOUT clearing cache - but queries intentionally don't match
2328+
# This measures the overhead of scanning the cache without getting hits
23192329
log_info "Testing /api/query with full cache (cache miss - worst case)..."
2320-
local result=$(measure_endpoint "${API_BASE}/api/query" "POST" '{"type":"NonExistentType999","limit":5}' "Query with full cache (miss)")
2330+
local result=$(measure_endpoint "${API_BASE}/api/query" "POST" '{"type":"NonExistentType"}' "Query with cache miss")
23212331
log_success "Query with full cache (cache miss)"
23222332

23232333
log_info "Testing /api/search with full cache (cache miss - worst case)..."
2324-
result=$(measure_endpoint "${API_BASE}/api/search" "POST" '{"searchText":"xyzNonExistentQuery999","limit":5}' "Search with full cache (miss)")
2334+
result=$(measure_endpoint "${API_BASE}/api/search" "POST" '{"searchText":"zzznomatchzzz"}' "Search with cache miss")
23252335
log_success "Search with full cache (cache miss)"
23262336

23272337
log_info "Testing /api/search/phrase with full cache (cache miss - worst case)..."
2328-
result=$(measure_endpoint "${API_BASE}/api/search/phrase" "POST" '{"searchText":"xyzNonExistent phrase999","limit":5}' "Search phrase with full cache (miss)")
2338+
result=$(measure_endpoint "${API_BASE}/api/search/phrase" "POST" '{"searchText":"zzz no match zzz"}' "Search phrase with cache miss")
23292339
log_success "Search phrase with full cache (cache miss)"
23302340

2331-
# For ID, history, since - use objects created in Phase 1 (these will cause cache misses too)
2341+
# For ID, history, since - use objects created in Phase 1/2 if available
23322342
if [ ${#CREATED_IDS[@]} -gt 0 ]; then
23332343
local test_id="${CREATED_IDS[0]}"
23342344
log_info "Testing /id with full cache (cache miss - worst case)..."
@@ -2353,50 +2363,14 @@ main() {
23532363
fi
23542364

23552365
# ============================================================
2356-
# PHASE 4: Clear cache for write baseline
2357-
# ============================================================
2358-
echo ""
2359-
log_section "PHASE 4: Clear Cache for Write Baseline"
2360-
echo "[INFO] Clearing cache to establish write performance baseline..."
2361-
clear_cache
2362-
2363-
# ============================================================
2364-
# PHASE 5: Write endpoints on EMPTY cache (baseline)
2366+
# PHASE 5: Write endpoints on FULL cache (worst case - maximum invalidation)
23652367
# ============================================================
23662368
echo ""
2367-
log_section "PHASE 5: Write Endpoints on EMPTY Cache (Baseline)"
2368-
echo "[INFO] Testing write endpoints without cache to establish baseline performance..."
2369-
2370-
# Store number of created objects before empty cache tests
2371-
local empty_cache_start_count=${#CREATED_IDS[@]}
2372-
2373-
test_create_endpoint_empty
2374-
test_update_endpoint_empty
2375-
test_patch_endpoint_empty
2376-
test_set_endpoint_empty
2377-
test_unset_endpoint_empty
2378-
test_overwrite_endpoint_empty
2379-
test_delete_endpoint_empty # Uses objects from create_empty test
2380-
2381-
# ============================================================
2382-
# PHASE 6: Fill cache again with 1000 entries
2383-
# ============================================================
2384-
echo ""
2385-
log_section "PHASE 6: Fill Cache Again for Write Comparison"
2386-
echo "[INFO] Filling cache with 1000 entries to measure write invalidation overhead..."
2387-
fill_cache $CACHE_FILL_SIZE
2388-
2389-
# ============================================================
2390-
# PHASE 7: Write endpoints on FULL cache (WORST CASE - no invalidations)
2391-
# ============================================================
2392-
echo ""
2393-
log_section "PHASE 7: Write Endpoints on FULL Cache (WORST CASE - No Invalidations)"
2394-
echo "[INFO] Testing write endpoints with full cache (${CACHE_FILL_SIZE} entries) using objects that DON'T match cache..."
2395-
echo "[INFO] This measures maximum overhead when cache invalidation scans entire cache but finds nothing to invalidate..."
2396-
2397-
# Store number of created objects before full cache tests
2398-
local full_cache_start_count=${#CREATED_IDS[@]}
2369+
log_section "PHASE 5: Write Endpoints with FULL Cache (Worst Case - Maximum Invalidation Overhead)"
2370+
echo "[INFO] Testing write endpoints with full cache (${CACHE_FILL_SIZE} entries) - all entries must be scanned..."
23992371

2372+
# Cache is already full from Phase 3 - reuse it without refilling
2373+
# This measures worst-case invalidation: scanning all 1000 entries without finding matches
24002374
test_create_endpoint_full
24012375
test_update_endpoint_full
24022376
test_patch_endpoint_full

cache/__tests__/cache-metrics.sh

Lines changed: 35 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,7 +2250,7 @@ test_delete_endpoint_full() {
22502250
}
22512251

22522252
################################################################################
2253-
# Main Test Flow
2253+
# Main Test Flow (REFACTORED TO 5 PHASES - OPTIMIZED)
22542254
################################################################################
22552255

22562256
main() {
@@ -2261,28 +2261,25 @@ main() {
22612261

22622262
echo "This test suite will:"
22632263
echo " 1. Test read endpoints with EMPTY cache (baseline performance)"
2264-
echo " 2. Fill cache to 1000 entries"
2265-
echo " 3. Test read endpoints with FULL cache (verify speedup)"
2266-
echo " 4. Clear cache and test write endpoints with EMPTY cache (baseline)"
2267-
echo " Note: Cache cleared to measure pure write performance without invalidation overhead"
2268-
echo " 5. Fill cache to 1000 entries again"
2269-
echo " 6. Test write endpoints with FULL cache (measure invalidation overhead)"
2270-
echo " 7. Generate comprehensive metrics report"
2264+
echo " 2. Test write endpoints with EMPTY cache (baseline performance)"
2265+
echo " 3. Fill cache to 1000 entries"
2266+
echo " 4. Test read endpoints with FULL cache (measure speedup vs baseline)"
2267+
echo " 5. Test write endpoints with FULL cache (measure invalidation overhead vs baseline)"
22712268
echo ""
22722269

22732270
# Setup
22742271
check_server
22752272
get_auth_token
22762273
warmup_system
22772274

2278-
# Run all tests following Modified Third Option
2275+
# Run optimized 5-phase test flow
22792276
log_header "Running Functionality & Performance Tests"
22802277

22812278
# ============================================================
22822279
# PHASE 1: Read endpoints on EMPTY cache (baseline)
22832280
# ============================================================
22842281
echo ""
2285-
log_section "PHASE 1: Read Endpoints on EMPTY Cache (Baseline)"
2282+
log_section "PHASE 1: Read Endpoints with EMPTY Cache (Baseline)"
22862283
echo "[INFO] Testing read endpoints without cache to establish baseline performance..."
22872284
clear_cache
22882285

@@ -2295,22 +2292,37 @@ main() {
22952292
test_since_endpoint
22962293

22972294
# ============================================================
2298-
# PHASE 2: Fill cache with 1000 entries
2295+
# PHASE 2: Write endpoints on EMPTY cache (baseline)
22992296
# ============================================================
23002297
echo ""
2301-
log_section "PHASE 2: Fill Cache with 1000 Entries"
2302-
echo "[INFO] Filling cache to test read performance at scale..."
2298+
log_section "PHASE 2: Write Endpoints with EMPTY Cache (Baseline)"
2299+
echo "[INFO] Testing write endpoints without cache to establish baseline performance..."
2300+
2301+
# Cache is already empty from Phase 1
2302+
test_create_endpoint_empty
2303+
test_update_endpoint_empty
2304+
test_patch_endpoint_empty
2305+
test_set_endpoint_empty
2306+
test_unset_endpoint_empty
2307+
test_overwrite_endpoint_empty
2308+
test_delete_endpoint_empty # Uses objects from create_empty test
2309+
2310+
# ============================================================
2311+
# PHASE 3: Fill cache with 1000 entries
2312+
# ============================================================
2313+
echo ""
2314+
log_section "PHASE 3: Fill Cache with 1000 Entries"
2315+
echo "[INFO] Filling cache to test performance at scale..."
23032316
fill_cache $CACHE_FILL_SIZE
23042317

23052318
# ============================================================
2306-
# PHASE 3: Read endpoints on FULL cache (verify speedup)
2319+
# PHASE 4: Read endpoints on FULL cache (verify speedup)
23072320
# ============================================================
23082321
echo ""
2309-
log_section "PHASE 3: Read Endpoints on FULL Cache (Verify Speedup)"
2310-
echo "[INFO] Testing read endpoints with full cache (${CACHE_FILL_SIZE} entries) to verify performance improvement..."
2322+
log_section "PHASE 4: Read Endpoints with FULL Cache (Measure Speedup)"
2323+
echo "[INFO] Testing read endpoints with full cache (${CACHE_FILL_SIZE} entries) to measure speedup vs Phase 1..."
23112324

2312-
# Test read endpoints with the full cache WITHOUT clearing it
2313-
# Just measure the performance, don't re-test functionality
2325+
# Test read endpoints WITHOUT clearing cache - reuse what was filled in Phase 3
23142326
# IMPORTANT: Queries must match cache fill patterns (default limit=100, skip=0) to get cache hits
23152327
log_info "Testing /api/query with full cache..."
23162328
local result=$(measure_endpoint "${API_BASE}/api/query" "POST" '{"type":"CreatePerfTest"}' "Query with full cache")
@@ -2324,7 +2336,7 @@ main() {
23242336
result=$(measure_endpoint "${API_BASE}/api/search/phrase" "POST" '{"searchText":"test annotation"}' "Search phrase with full cache")
23252337
log_success "Search phrase with full cache"
23262338

2327-
# For ID, history, since - use objects created in Phase 1 if available
2339+
# For ID, history, since - use objects created in Phase 1/2 if available
23282340
if [ ${#CREATED_IDS[@]} -gt 0 ]; then
23292341
local test_id="${CREATED_IDS[0]}"
23302342
log_info "Testing /id with full cache..."
@@ -2349,49 +2361,13 @@ main() {
23492361
fi
23502362

23512363
# ============================================================
2352-
# PHASE 4: Clear cache for write baseline
2353-
# ============================================================
2354-
echo ""
2355-
log_section "PHASE 4: Clear Cache for Write Baseline"
2356-
echo "[INFO] Clearing cache to establish write performance baseline..."
2357-
clear_cache
2358-
2359-
# ============================================================
2360-
# PHASE 5: Write endpoints on EMPTY cache (baseline)
2361-
# ============================================================
2362-
echo ""
2363-
log_section "PHASE 5: Write Endpoints on EMPTY Cache (Baseline)"
2364-
echo "[INFO] Testing write endpoints without cache to establish baseline performance..."
2365-
2366-
# Store number of created objects before empty cache tests
2367-
local empty_cache_start_count=${#CREATED_IDS[@]}
2368-
2369-
test_create_endpoint_empty
2370-
test_update_endpoint_empty
2371-
test_patch_endpoint_empty
2372-
test_set_endpoint_empty
2373-
test_unset_endpoint_empty
2374-
test_overwrite_endpoint_empty
2375-
test_delete_endpoint_empty # Uses objects from create_empty test
2376-
2377-
# ============================================================
2378-
# PHASE 6: Fill cache again with 1000 entries
2364+
# PHASE 5: Write endpoints on FULL cache (measure invalidation)
23792365
# ============================================================
23802366
echo ""
2381-
log_section "PHASE 6: Fill Cache Again for Write Comparison"
2382-
echo "[INFO] Filling cache with 1000 entries to measure write invalidation overhead..."
2383-
fill_cache $CACHE_FILL_SIZE
2384-
2385-
# ============================================================
2386-
# PHASE 7: Write endpoints on FULL cache (measure invalidation)
2387-
# ============================================================
2388-
echo ""
2389-
log_section "PHASE 7: Write Endpoints on FULL Cache (Measure Invalidation Overhead)"
2390-
echo "[INFO] Testing write endpoints with full cache to measure cache invalidation overhead..."
2391-
2392-
# Store number of created objects before full cache tests
2393-
local full_cache_start_count=${#CREATED_IDS[@]}
2367+
log_section "PHASE 5: Write Endpoints with FULL Cache (Measure Invalidation Overhead)"
2368+
echo "[INFO] Testing write endpoints with full cache (${CACHE_FILL_SIZE} entries) to measure invalidation overhead vs Phase 2..."
23942369

2370+
# Cache is already full from Phase 3 - reuse it without refilling
23952371
test_create_endpoint_full
23962372
test_update_endpoint_full
23972373
test_patch_endpoint_full

0 commit comments

Comments
 (0)