Skip to content

Commit f8348b5

Browse files
committed
changes from testing, and new reports
1 parent 9fc3c93 commit f8348b5

12 files changed

Lines changed: 2045 additions & 2564 deletions

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

Lines changed: 140 additions & 45 deletions
Large diffs are not rendered by default.

cache/__tests__/cache-metrics.sh

Lines changed: 156 additions & 78 deletions
Large diffs are not rendered by default.

cache/__tests__/rerum-metrics.sh

Lines changed: 1528 additions & 0 deletions
Large diffs are not rendered by default.

cache/docs/CACHE_METRICS_REPORT.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# RERUM Cache Metrics & Functionality Report
22

3-
**Generated**: Tue Nov 4 22:07:39 CST 2025
3+
**Generated**: Wed Nov 5 12:44:10 CST 2025
44
**Test Duration**: Full integration and performance suite
55
**Server**: http://localhost:3001
66

77
---
88

99
## Executive Summary
1010

11-
**Overall Test Results**: 45 passed, 0 failed, 0 skipped (45 total)
11+
**Overall Test Results**: 42 passed, 4 failed, 0 skipped (46 total)
1212

1313
### Cache Performance Summary
1414

@@ -17,7 +17,7 @@
1717
| Cache Hits | 6 |
1818
| Cache Misses | 1006 |
1919
| Hit Rate | 0.59% |
20-
| Cache Size | 7 entries |
20+
| Cache Size | 5 entries |
2121

2222
---
2323

@@ -47,12 +47,12 @@
4747

4848
| Endpoint | Cold Cache (DB) | Warm Cache (Memory) | Speedup | Benefit |
4949
|----------|-----------------|---------------------|---------|---------|
50-
| `/query` | 352ms | 23ms | -329ms | ✅ High |
51-
| `/search` | 336ms | 19ms | -317ms | ✅ High |
52-
| `/searchPhrase` | 294ms | 21ms | -273ms | ✅ High |
53-
| `/id` | 449 | N/A | N/A | N/A |
54-
| `/history` | 782 | N/A | N/A | N/A |
55-
| `/since` | 776 | N/A | N/A | N/A |
50+
| `/query` | 332ms | 22ms | -310ms | ✅ High |
51+
| `/search` | 61ms | 20ms | -41ms | ✅ High |
52+
| `/searchPhrase` | 54ms | 20ms | -34ms | ✅ High |
53+
| `/id` | 438 | N/A | N/A | N/A |
54+
| `/history` | 767 | N/A | N/A | N/A |
55+
| `/since` | 769 | N/A | N/A | N/A |
5656

5757
**Interpretation**:
5858
- **Cold Cache**: First request hits database (cache miss)
@@ -68,13 +68,13 @@
6868

6969
| Endpoint | Empty Cache | Full Cache (1000 entries) | Overhead | Impact |
7070
|----------|-------------|---------------------------|----------|--------|
71-
| `/create` | 53ms | 52ms | -1ms | ✅ None |
72-
| `/update` | 503ms | 508ms | +5ms | ✅ Negligible |
73-
| `/patch` | 510ms | 520ms | +10ms | ✅ Low |
74-
| `/set` | 497ms | 514ms | +17ms | ⚠️ Moderate |
75-
| `/unset` | 495ms | 512ms | +17ms | ⚠️ Moderate |
76-
| `/delete` | 508ms | 497ms | -11ms | ✅ None |
77-
| `/overwrite` | 498ms | 503ms | +5ms |Negligible |
71+
| `/create` | 53ms | 50ms | -3ms | ✅ None |
72+
| `/update` | 498ms | 510ms | +12ms | ⚠️ Moderate |
73+
| `/patch` | 509ms | 542ms | +33ms | ⚠️ Moderate |
74+
| `/set` | 495ms | 504ms | +9ms | ✅ Low |
75+
| `/unset` | 512ms | 511ms | -1ms | ✅ None |
76+
| `/delete` | 493ms | 469ms | -24ms | ✅ None |
77+
| `/overwrite` | 513ms | 522ms | +9ms |Low |
7878

7979
**Interpretation**:
8080
- **Empty Cache**: Write with no cache to invalidate
@@ -91,14 +91,14 @@
9191
### Overall Performance Impact
9292

9393
**Cache Benefits (Reads)**:
94-
- Average speedup per cached read: ~329ms
94+
- Average speedup per cached read: ~310ms
9595
- Typical hit rate in production: 60-80%
96-
- Net benefit on 1000 reads: ~230300ms saved (assuming 70% hit rate)
96+
- Net benefit on 1000 reads: ~217000ms saved (assuming 70% hit rate)
9797

9898
**Cache Costs (Writes)**:
99-
- Average overhead per write: ~6ms
99+
- Average overhead per write: ~5ms
100100
- Overhead percentage: ~1%
101-
- Net cost on 1000 writes: ~6000ms
101+
- Net cost on 1000 writes: ~5000ms
102102
- Tested endpoints: create, update, patch, set, unset, delete, overwrite
103103

104104
**Break-Even Analysis**:
@@ -110,17 +110,17 @@ For a workload with:
110110

111111
```
112112
Without Cache:
113-
800 reads × 352ms = 281600ms
113+
800 reads × 332ms = 265600ms
114114
200 writes × 53ms = 10600ms
115-
Total: 292200ms
115+
Total: 276200ms
116116
117117
With Cache:
118-
560 cached reads × 23ms = 12880ms
119-
240 uncached reads × 352ms = 84480ms
120-
200 writes × 52ms = 10400ms
121-
Total: 107760ms
118+
560 cached reads × 22ms = 12320ms
119+
240 uncached reads × 332ms = 79680ms
120+
200 writes × 50ms = 10000ms
121+
Total: 102000ms
122122
123-
Net Improvement: 184440ms faster (~64% improvement)
123+
Net Improvement: 174200ms faster (~64% improvement)
124124
```
125125

126126
---
@@ -130,9 +130,9 @@ Net Improvement: 184440ms faster (~64% improvement)
130130
### ✅ Deploy Cache Layer
131131

132132
The cache layer provides:
133-
1. **Significant read performance improvements** (329ms average speedup)
134-
2. **Minimal write overhead** (6ms average, ~1% of write time)
135-
3. **All endpoints functioning correctly** (45 passed tests)
133+
1. **Significant read performance improvements** (310ms average speedup)
134+
2. **Minimal write overhead** (5ms average, ~1% of write time)
135+
3. **All endpoints functioning correctly** (42 passed tests)
136136

137137
### 📊 Monitoring Recommendations
138138

@@ -163,7 +163,7 @@ Consider tuning based on:
163163
- Server: http://localhost:3001
164164
- Test Framework: Bash + curl
165165
- Metrics Collection: Millisecond-precision timing
166-
- Test Objects Created: 201
166+
- Test Objects Created: 202
167167
- All test objects cleaned up: ✅
168168

169169
**Test Coverage**:
@@ -175,6 +175,6 @@ Consider tuning based on:
175175

176176
---
177177

178-
**Report Generated**: Tue Nov 4 22:07:39 CST 2025
178+
**Report Generated**: Wed Nov 5 12:44:11 CST 2025
179179
**Format Version**: 1.0
180180
**Test Suite**: cache-metrics.sh

cache/docs/CACHE_METRICS_WORST_CASE_REPORT.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# RERUM Cache WORST-CASE Overhead Analysis
22

3-
**Generated**: Tue Nov 4 21:49:52 CST 2025
3+
**Generated**: Wed Nov 5 13:00:30 CST 2025
44
**Test Type**: Worst-case cache overhead measurement (O(n) scanning, 0 invalidations)
55
**Server**: http://localhost:3001
66

@@ -58,12 +58,12 @@
5858

5959
| Endpoint | Empty Cache (0 entries) | Full Cache (1000 entries) | Difference | Analysis |
6060
|----------|-------------------------|---------------------------|------------|----------|
61-
| `/query` | 364ms | 367ms | 3ms | ✅ No overhead (O(1) verified) |
62-
| `/search` | 58ms | 53ms | -5ms |No overhead (O(1) verified) |
63-
| `/searchPhrase` | 55ms | 52ms | -3ms |No overhead (O(1) verified) |
64-
| `/id` | 453ms | 442ms | -11ms | ✅ Faster (DB variance, not cache) |
65-
| `/history` | 781ms | 780ms | -1ms | ✅ No overhead (O(1) verified) |
66-
| `/since` | 764ms | 775ms | 11ms | ⚠️ Slower (likely DB variance) |
61+
| `/query` | 362ms | 361ms | -1ms | ✅ No overhead (O(1) verified) |
62+
| `/search` | 62ms | 54ms | -8ms |Faster (DB variance, not cache) |
63+
| `/searchPhrase` | 57ms | 51ms | -6ms |Faster (DB variance, not cache) |
64+
| `/id` | 442ms | 422ms | -20ms | ✅ Faster (DB variance, not cache) |
65+
| `/history` | 754ms | 768ms | 14ms | ⚠️ Slower (likely DB variance) |
66+
| `/since` | 763ms | 753ms | -10ms | ✅ Faster (DB variance, not cache) |
6767

6868
**Key Insight**: Cache uses **O(1) hash-based lookups** for reads.
6969

@@ -81,13 +81,13 @@
8181

8282
| Endpoint | Empty Cache | Full Cache (1000 entries) | Overhead | Impact |
8383
|----------|-------------|---------------------------|----------|--------|
84-
| `/create` | 54ms | 51ms | -3ms | ✅ None |
85-
| `/update` | 494ms | 523ms | +29ms | ⚠️ Moderate |
86-
| `/patch` | 506ms | 525ms | +19ms | ⚠️ Moderate |
87-
| `/set` | 496ms | 549ms | +53ms | ⚠️ Moderate |
88-
| `/unset` | 502ms | 525ms | +23ms | ⚠️ Moderate |
89-
| `/delete` | 493ms | 469ms | -24ms | ✅ None |
90-
| `/overwrite` | 501ms | 523ms | +22ms | ⚠️ Moderate |
84+
| `/create` | 57ms | 51ms | -6ms | ✅ None |
85+
| `/update` | 491ms | 525ms | +34ms | ⚠️ Moderate |
86+
| `/patch` | 502ms | 535ms | +33ms | ⚠️ Moderate |
87+
| `/set` | 497ms | 526ms | +29ms | ⚠️ Moderate |
88+
| `/unset` | 510ms | 528ms | +18ms | ⚠️ Moderate |
89+
| `/delete` | 504ms | 515ms | +11ms | ⚠️ Moderate |
90+
| `/overwrite` | 495ms | 525ms | +30ms | ⚠️ Moderate |
9191

9292
**Key Insight**: Cache uses **O(n) linear scanning** for write invalidation.
9393

@@ -116,22 +116,22 @@
116116
- **Conclusion**: Reads are always fast, even with cache misses
117117

118118
**Write Operations (O(n)):**
119-
- Average O(n) scanning overhead: ~17ms per write
120-
- Overhead percentage: ~3% of write time
121-
- Total cost for 1000 writes: ~17000ms
119+
- Average O(n) scanning overhead: ~21ms per write
120+
- Overhead percentage: ~4% of write time
121+
- Total cost for 1000 writes: ~21000ms
122122
- Tested endpoints: create, update, patch, set, unset, delete, overwrite
123123
- **This is WORST CASE**: Real scenarios will have cache invalidations (better than pure scanning)
124124

125125
**This worst-case test shows:**
126126
- O(1) read lookups mean cache size never slows down reads
127-
- O(n) write scanning overhead is 17ms on average
128-
- Even in worst case (no invalidations), overhead is typically 3% of write time
127+
- O(n) write scanning overhead is 21ms on average
128+
- Even in worst case (no invalidations), overhead is typically 4% of write time
129129

130130
**Real-World Scenarios:**
131131
- Production caches will have LOWER overhead than this worst case
132132
- Cache invalidations occur when writes match cached queries (productive work)
133133
- This test forces pure scanning with zero productive invalidations (maximum waste)
134-
- If 17ms overhead is acceptable here, production will be better
134+
- If 21ms overhead is acceptable here, production will be better
135135

136136
---
137137

@@ -141,7 +141,7 @@
141141

142142
**What This Test Shows:**
143143
1. **Read overhead**: NONE - O(1) hash lookups are instant regardless of cache size
144-
2. **Write overhead**: 17ms average O(n) scanning cost for 1000 entries
144+
2. **Write overhead**: 21ms average O(n) scanning cost for 1000 entries
145145
3. **Worst-case verified**: Pure scanning with zero matches
146146

147147
**If write overhead ≤ 5ms:** Cache overhead is negligible - deploy with confidence
@@ -150,9 +150,9 @@
150150

151151
### ✅ Is Cache Overhead Acceptable?
152152

153-
Based on 17ms average overhead:
153+
Based on 21ms average overhead:
154154
- **Reads**: ✅ Zero overhead (O(1) regardless of size)
155-
- **Writes**: ✅ Acceptable
155+
- **Writes**: ⚠️ Review recommended
156156

157157
### 📊 Monitoring Recommendations
158158

@@ -194,6 +194,6 @@ Tuning considerations:
194194

195195
---
196196

197-
**Report Generated**: Tue Nov 4 21:49:52 CST 2025
197+
**Report Generated**: Wed Nov 5 13:00:30 CST 2025
198198
**Format Version**: 1.0
199199
**Test Suite**: cache-metrics.sh

cache/docs/RERUM_METRICS_REPORT.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# RERUM Baseline Performance Analysis (No Cache)
2+
3+
**Generated**: Wed Nov 5 12:31:45 CST 2025
4+
**Server**: https://devstore.rerum.io
5+
**Branch**: main (no cache layer)
6+
**Test Duration**: 4 minutes 41 seconds
7+
8+
---
9+
10+
## Executive Summary
11+
12+
**Overall Test Results**: 17 passed, 0 failed, 0 skipped (17 total)
13+
14+
This report establishes baseline performance metrics for the RERUM API without the cache layer. These metrics can be compared against CACHE_METRICS_REPORT.md to evaluate the impact of the caching implementation.
15+
16+
---
17+
18+
## Endpoint Functionality Status
19+
20+
| Endpoint | Status | Description |
21+
|----------|--------|-------------|
22+
| `/query` | ✅ Functional | Query database with filters |
23+
| `/search` | ✅ Functional | Full-text search |
24+
| `/searchPhrase` | ✅ Functional | Phrase search |
25+
| `/id` | ✅ Functional | Retrieve object by ID |
26+
| `/history` | ✅ Functional | Get version history |
27+
| `/since` | ✅ Functional | Get version descendants |
28+
| `/create` | ✅ Functional | Create new objects |
29+
| `/update` | ✅ Functional | Update existing objects |
30+
| `/patch` | ✅ Functional | Patch existing objects |
31+
| `/set` | ✅ Functional | Add properties to objects |
32+
| `/unset` | ✅ Functional | Remove properties from objects |
33+
| `/delete` | ✅ Functional | Delete objects |
34+
| `/overwrite` | ✅ Functional | Overwrite objects without versioning |
35+
36+
---
37+
38+
## Read Performance
39+
40+
| Endpoint | Avg (ms) | Median (ms) | Min (ms) | Max (ms) |
41+
|----------|----------|-------------|----------|----------|
42+
| `/query` | 453 | 453 | 453 | 453 |
43+
| `/search` | 151 | 151 | 151 | 151 |
44+
| `/searchPhrase` | 136 | 136 | 136 | 136 |
45+
| `/id` | 530 | 530 | 530 | 530 |
46+
| `/history` | 852 | 852 | 852 | 852 |
47+
| `/since` | 864 | 864 | 864 | 864 |
48+
49+
**Interpretation**:
50+
- All read operations hit the database directly (no caching)
51+
- Times represent baseline database query performance
52+
- These metrics can be compared with cached read performance to calculate cache speedup
53+
54+
---
55+
56+
## High-Volume Query Load Test
57+
58+
This test performs 1000 diverse read queries to measure baseline database performance under load. It directly corresponds to the `fill_cache()` operation in cache-metrics.sh, enabling direct comparison.
59+
60+
| Metric | Value |
61+
|--------|-------|
62+
| Total Queries | 1000 |
63+
| Total Time | 66 seconds (66000ms) |
64+
| Average per Query | 66ms |
65+
| Successful Queries | 1000/1000 |
66+
| Failed Queries | 0/1000 |
67+
68+
**Query Distribution**:
69+
- Rotates through 6 endpoint types: /api/query, /api/search, /api/search/phrase, /id/{id}, /history/{id}, /since/{id}
70+
- Each query uses unique parameters to prevent database-level caching
71+
72+
**Comparison with Cache**:
73+
- Compare this total time with the cache fill operation time in CACHE_METRICS_REPORT.md
74+
- This shows baseline database performance for 1000 diverse queries without caching
75+
- Cache fill time includes both database queries (on cache misses) and cache.set() operations
76+
77+
---
78+
79+
## Write Performance
80+
81+
| Endpoint | Avg (ms) | Median (ms) | Min (ms) | Max (ms) | Successful/Total |
82+
|----------|----------|-------------|----------|----------|------------------|
83+
| `/create` | 151 | 140 | 127 | 1195 | 100/100 |
84+
| `/update` | 587 | 566 | 547 | 1561 | 50/50 |
85+
| `/patch` | 568 | 567 | 547 | 618 | 50/50 |
86+
| `/set` | 597 | 570 | 542 | 1079 | 50/50 |
87+
| `/unset` | 572 | 566 | 543 | 710 | 50/50 |
88+
| `/delete` | 565 | 565 | 546 | 604 | 50/50 |
89+
| `/overwrite` | 567 | 568 | 550 | 594 | 50/50 |
90+
91+
**Interpretation**:
92+
- All write operations execute without cache invalidation overhead
93+
- Times represent baseline write performance
94+
- These metrics can be compared with cached write performance to calculate cache overhead
95+
96+
---
97+
98+
## Summary Statistics
99+
100+
**Total Operations**:
101+
- Read operations: 6 endpoints tested
102+
- Write operations: 400 operations across 7 endpoints
103+
104+
**Success Rates**:
105+
- Create: 100/100
106+
- Update: 50/50
107+
- Patch: 50/50
108+
- Set: 50/50
109+
- Unset: 50/50
110+
- Delete: 50/50
111+
- Overwrite: 50/50
112+
113+
**Test Execution**:
114+
- Total duration: 4 minutes 41 seconds
115+
- Test objects created: 100
116+
- Server: https://devstore.rerum.io
117+
118+
---
119+
120+
## Comparison Guide
121+
122+
To compare with cache performance (CACHE_METRICS_REPORT.md):
123+
124+
1. **Read Speedup**: Calculate cache benefit
125+
```
126+
Speedup = Baseline Read Time - Cached Read Time
127+
Speedup % = (Speedup / Baseline Read Time) × 100
128+
```
129+
130+
2. **Write Overhead**: Calculate cache cost
131+
```
132+
Overhead = Cached Write Time - Baseline Write Time
133+
Overhead % = (Overhead / Baseline Write Time) × 100
134+
```
135+
136+
3. **Net Benefit**: Evaluate overall impact based on your read/write ratio
137+
138+
---
139+
140+
## Notes
141+
142+
- This test was run against the **main branch** without the cache layer
143+
- All timing measurements are in milliseconds
144+
- Clock skew was handled gracefully (operations with negative timing marked as 0ms)
145+
- Test objects should be manually cleaned from MongoDB using the commands provided at test start
146+
147+
---
148+
149+
**Report Generated**: Wed Nov 5 12:31:45 CST 2025
150+
**Format Version**: 1.0
151+
**Test Suite**: rerum-metrics.sh

0 commit comments

Comments
 (0)