Prompt Details
Model
(claude-5-5-sonnet)
Token size
2,208
Example input
[APPLICATION_CONTEXT]: Language: Java 21 Framework: Spring Boot 3.3 Environment: Kubernetes OS: Linux Database: PostgreSQL Deployment: Production
[SYMPTOMS_AND_WORKLOAD]: Endpoint: POST /api/orders Traffic: 1,200 requests/second Average latency: 180ms β 950ms P99 latency: 2.8 seconds CPU usage: 45% β 92% Memory: Continuously increasing Issue duration: 4 hours
[PROFILING_AND_RUNTIME_DATA]: CPU profile: JSON serialization 32% Regex validation: 21% Synchronized cache access: 18% Heap: 2.5GB β 5.8GB Post-GC heap: 1.4GB β 4.6GB Allocation rate: 1.8GB/minute GC p99 pause: 220ms Heap dominator: HashMap retaining 2.1GB
[LOGS_AND_TRACES]: Database query p95: 35ms Connection pool: 95/100 active Connection wait: 180ms Application threads: 450 Internal queue: 18,000 tasks Deployment: Cache implementation updated 5 hours before incident Errors: Intermittent request timeouts
[CONSTRAINTS_AND_GOALS]: Target average latency: Below 200ms Target P95: Below 300ms Target CPU: Below 70% Maximum memory: 6GB Avoid production downtime Prefer reversible fixes
Example output
### PHASE 1 β Investigation Scope π―
Issue classification
CPU-related
Critical
Memory-related
Critical
Latency-related
Critical
Concurrency-related
High
Database-related
Investigate
Investigation findings
* The application experiences simultaneous CPU saturation and memory growth.
* Request latency has increased substantially.
* The internal task queue is accumulating work.
* The cache implementation changed shortly before the incident.
* Database connection-pool waiting may contribute to latency.
Initial assessment:
The cache implementation is a leading investigation target, but the available evidence does not yet establish it as the root cause.
### PHASE 2 β Evidence Quality π
| Evidence | Quality | Limitation |
| ------------------ | ------- | --------------------------------- |
| CPU profile | Good | Sampling details unavailable |
| Heap snapshot | Good | Only one snapshot |
| GC metrics | Partial | Full GC logs missing |
| Request latency | Good | Baseline workload details missing |
| Database metrics | Partial | Query distribution missing |
| Thread metrics | Partial | No thread dump |
| Deployment event | Good | Change details missing |
| Distributed traces | Missing | No trace files supplied |
Evidence classification
* Confirmed observation: CPU usage reached 92% in the supplied test data.
* Confirmed observation: Post-GC heap increased from 1.4GB to 4.6GB.
* Supported finding: The HashMap retains a substantial amount of memory.
* Plausible hypothesis: The cache may have unbounded retention.
* Unknown: Whether retained objects are legitimate cache entries or leaked references.
### PHASE 3 β Baseline Analysis π
| Metric | Previous | Current |
| --------------- | -------- | ------- |
| Average latency | 180ms | 950ms |
| CPU | 45% | 92% |
| Heap | 2.5GB | 5.8GB |
| Post-GC heap | 1.4GB | 4.6GB |
| GC p99 pause | Unknown | 220ms |
| Queue depth | Unknown | 18,000 |
Memory growth visualization
Interpretation
The most concerning observation is post-GC heap growth.
Garbage collection is not reclaiming a large portion of the accumulated objects.
This suggests object retention, but does not independently prove a memory leak.
Missing baseline metrics:
* Request throughput before and after deployment.
* Historical allocation rate.
* Cache entry count.
* GC frequency and total collection time.
* Container RSS and native memory.
### PHASE 4 β CPU Bottleneck Investigation π₯
CPU profile findings
Finding 1: JSON serialization
* Evidence: 32% of sampled CPU profile.
* Potential impact: Expensive serialization may increase processing time under high request volume.
* Alternative: Large payloads or serialization of nested objects.
* Experiment: Profile serialization methods and measure payload size.
* Potential fix: Reduce unnecessary fields, reuse safe serialization metadata, and avoid redundant conversions.
Finding 2: Regex validation
* Evidence: 21% CPU share.
* Potential impact: Repeated expensive pattern matching.
* Alternative: Large input strings or complex validation rules.
* Experiment: Benchmark regex execution with representative inputs.
* Potential fix: Precompile reusable patterns and simplify expressions.
Finding 3: Synchronized cache access
* Evidence: 18% CPU share.
* Potential impact: Contention and waiting among concurrent threads.
* Alternative: Cache operations may simply be frequent.
* Experiment: Collect lock contention profiles.
* Potential fix: Use appropriately concurrent cache structures and reduce critical-section duration.
Priority: Investigate cache synchronization first, then serialization and regex validation.
### PHASE 5 β Memory Leak Investigation π§
Leading investigation area
Primary finding: HashMap retention
* Retained memory: 2.1GB.
* Post-GC heap: 4.6GB.
* Heap usage continues increasing.
* Cache implementation was updated shortly before the incident.
Leading hypothesis: Unbounded cache growth
Possible explanation:
The updated cache may retain order-related objects without expiration or eviction.
Potential retention chain:
```text
Application Cache
|
v
HashMap
|
v
Order IDs
|
v
Order Objects
|
v
Nested Objects
```
Alternative explanations
* Legitimate increase in active order volume.
* Cache expiration is configured incorrectly.
* Cache entries are retained for valid business reasons.
* A separate reference is preventing garbage collection.
Confirmation experiment
* Take heap snapshot A.
* Record cache entry count.
* Run a controlled workload.
* Wait for equivalent workload cycles.
* Trigger a controlled GC in a staging environment.
* Take heap snapshot B.
* Compare retained objects and dominator trees.
Confirmation criteria:
If cache entries continuously grow despite completed orders and expected expiration, and retained objects remain reachable through the cache, the unbounded cache hypothesis gains strong support.
### PHASE 6 β Garbage Collection and Runtime βοΈ
Observations
* Allocation rate: 1.8GB/minute.
* GC p99 pause: 220ms.
* Post-GC heap: 4.6GB.
* Current heap: 5.8GB.
Analysis
The high allocation rate suggests considerable object creation.
The large post-GC heap suggests that many objects remain reachable after collection.
Two separate problems may exist:
* Excessive allocation overhead.
* Long-lived object retention.
Recommended investigation
* Collect complete GC logs.
* Identify young and old generation collection frequency.
* Measure promotion rates.
* Inspect allocation hotspots.
* Examine object survival rates.
Important: Do not change JVM heap sizes or garbage collector flags yet. The exact JVM vendor, GC configuration, container memory limit, and GC logs must be verified first.
### PHASE 7 β Latency Investigation β±οΈ
Latency findings
| Metric | Value |
| ---------------- | ------- |
| Previous average | 180ms |
| Current average | 950ms |
| Current P99 | 2,800ms |
| DB query P95 | 35ms |
| Connection wait | 180ms |
Potential latency contributors
* CPU saturation causes slower request execution.
* Synchronized cache access may cause thread waiting.
* Database connection-pool waiting adds latency.
* GC pauses may create temporary latency spikes.
* Queue buildup increases request waiting time.
Important distinction
Database query execution at 35ms does not mean database-related latency is only 35ms.
Connection acquisition already adds approximately 180ms at the reported measurement percentile.
However, the percentile populations and measurement windows are not provided, so these values cannot be added to calculate an exact end-to-end latency breakdown.
Next experiment:
Capture distributed traces for slow requests and measure application execution, connection acquisition, database execution, cache access, and queue waiting separately.
### PHASE 8 β Concurrency and Queueing π
Observations
* Threads: 450.
* Queue depth: 18,000.
* Database pool: 95/100 active.
* Connection wait: 180ms.
Potential problem:
The application may be accepting work faster than its workers or downstream dependencies can process it.
Possible causes:
* Lock contention.
* Database connection saturation.
* Slow request processing.
* Insufficient backpressure.
* Excessive task submission.
Recommended experiments
* Collect multiple thread dumps.
* Inspect BLOCKED and WAITING threads.
* Identify lock owners.
* Measure task arrival and completion rates.
* Inspect executor queue configuration.
* Measure database connection acquisition time.
Recommended fix:
Introduce bounded queues and controlled backpressure where appropriate.
Do not simply increase thread counts. That could increase memory usage and downstream pressure.
### PHASE 9 β Log and Trace Correlation π
Simulated timeline
| Time | Event |
| --------- | ----------------------------- |
| T-5 hours | Cache implementation deployed |
| T-4 hours | Increased heap usage begins |
| T-3 hours | CPU usage rises |
| T-2 hours | Request latency increases |
| T-1 hour | Queue reaches high levels |
| Current | Timeouts and memory pressure |
Correlation finding:
The cache deployment precedes the performance degradation.
This is a meaningful investigation lead, not proof of causation.
Required evidence:
* Deployment timestamp.
* Cache configuration diff.
* Request IDs and trace IDs.
* GC timestamps.
* Heap snapshots from before and after deployment.
* Error and timeout logs.
### PHASE 10 β Database, I/O and Dependencies π
Database assessment
* Connection pool utilization: 95%.
* Connection wait: 180ms.
* Query P95: 35ms.
Interpretation
The database connection pool appears heavily utilized.
However, query execution time is relatively lower than the reported connection wait.
This suggests connection acquisition and concurrency pressure may be more important than raw query execution time.
Investigate:
* Slow query distribution.
* Connection leaks.
* Long-running transactions.
* Pool acquisition time.
* Database CPU and I/O.
* Network round-trip latency.
* Retry frequency.
Potential fixes
* Release connections promptly.
* Optimize expensive queries.
* Review transaction boundaries.
* Apply appropriate request concurrency limits.
* Configure connection pools based on measured database capacity.
No database bottleneck is confirmed yet.
### PHASE 11 β Ranked Root-Cause Hypotheses π―
| Rank | Hypothesis | Confidence |
| ---- | ------------------------------------ | ---------- |
| 1 | Unbounded cache retention | Medium |
| 2 | Cache lock contention | Medium |
| 3 | Excessive JSON serialization | Medium |
| 4 | Database pool saturation | Medium |
| 5 | Excessive allocation and GC pressure | Medium |
Hypothesis 1: Unbounded cache retention
* Supporting evidence: 2.1GB retained by HashMap and growing post-GC heap.
* Missing evidence: Cache entry history and two comparable heap snapshots.
* Alternative: Legitimate cache growth.
* Best test: Heap snapshot comparison and cache entry monitoring.
* Falsification: Cache remains bounded and retained objects have valid lifecycles.
Hypothesis 2: Cache lock contention
* Supporting evidence: 18% CPU profile share attributed to synchronized cache access.
* Missing evidence: Lock waiting duration and contention frequency.
* Alternative: High cache operation frequency.
* Best test: Lock contention profiling.
* Falsification: Lock waiting is negligible under representative traffic.
Hypothesis 3: Expensive serialization
* Supporting evidence: 32% CPU profile share.
* Missing evidence: Payload sizes and method-level CPU samples.
* Alternative: Large legitimate responses.
* Best test: Serialization microbenchmark.
* Falsification: Optimized serialization does not materially change CPU consumption.
Hypothesis 4: Database pool saturation
* Supporting evidence: 95/100 connections active and 180ms wait.
* Missing evidence: Pool acquisition distribution and connection lifecycle.
* Alternative: Temporary traffic spike.
* Best test: Connection-pool metrics and thread traces.
* Falsification: Connection waits disappear under comparable load without performance improvement.
Hypothesis 5: Excessive allocation
* Supporting evidence: 1.8GB/minute allocation rate.
* Missing evidence: Allocation source breakdown.
* Alternative: Legitimate high-throughput workload.
* Best test: Allocation profiling.
* Falsification: Allocation rate is expected and not contributing materially to GC or latency.
### PHASE 12 β Diagnostic Experiment Plan π§ͺ
| Experiment | Priority | Risk |
| ------------------------- | -------- | ------ |
| Cache entry monitoring | P1 | Low |
| Heap snapshot comparison | P1 | Medium |
| Lock contention profiling | P1 | Low |
| Allocation profiling | P2 | Low |
| Distributed tracing | P2 | Low |
| Thread dump collection | P2 | Low |
| GC log analysis | P2 | Low |
| Controlled load test | P3 | Medium |
Experiment 1: Cache growth verification
* Hypothesis: Cache entries are accumulating without expiration.
* Tool: JVM heap analyzer.
* Workload: Representative order traffic.
* Metric: Cache entry count and retained heap.
* Expected result: Continuous cache growth if hypothesis is correct.
* Weakening result: Cache size remains bounded.
* Safety: Prefer staging; avoid expensive heap dumps on a memory-constrained production instance.
Experiment 2: Lock contention verification
* Hypothesis: Synchronized cache access contributes to request delays.
* Tool: Java Flight Recorder.
* Workload: Representative concurrent requests.
* Metric: Monitor blocked time and lock contention.
* Expected result: Significant waiting around cache operations.
* Weakening result: Negligible lock waiting.
* Safety: Use bounded recording duration and validate overhead.
Experiment 3: Allocation profiling
* Hypothesis: Serialization and validation generate excessive temporary objects.
* Tool: Java Flight Recorder allocation events.
* Metric: Allocation bytes by class and stack.
* Expected result: Significant allocation from serialization or regex processing.
* Weakening result: Those operations contribute little to allocation volume.
* Safety: Profile in staging first.
### PHASE 13 β Recommended Engineering Fixes π οΈ
| Fix | Problem | Priority |
| ---------------------------------- | ------------------ | -------- |
| Bounded cache | Memory retention | Critical |
| Cache synchronization optimization | Lock contention | High |
| Serialization optimization | CPU consumption | High |
| Regex optimization | CPU consumption | Medium |
| Connection lifecycle review | Pool waiting | High |
| Backpressure | Queue accumulation | High |
Fix 1: Implement bounded caching
* Introduce maximum cache size.
* Configure expiration based on business requirements.
* Remove completed and obsolete entries.
* Monitor eviction rate.
* Ensure concurrent access remains safe.
Risk: Aggressive eviction may increase database queries.
Rollback: Restore the previous cache implementation or configuration if correctness or latency regresses.
Fix 2: Optimize synchronized cache operations
* Identify critical sections.
* Reduce work performed inside locks.
* Consider a proven concurrent cache implementation.
Risk: Incorrect concurrency changes may introduce race conditions.
Fix 3: Optimize JSON serialization
* Avoid serializing unnecessary fields.
* Reduce repeated object conversions.
* Review large response payloads.
Risk: API response compatibility may be affected.
Fix 4: Introduce backpressure
* Set bounded queue capacity.
* Define overload behavior.
* Apply request concurrency limits.
Risk: Excessive restrictions may reject legitimate traffic.
### PHASE 14 β Prioritization π¦
Immediate containment
P0
* Check remaining container memory.
* Monitor heap and OOM risk.
* Protect the database from excessive concurrency.
* Consider rollback of the recent cache deployment if the incident is ongoing and rollback safety is established.
High-priority remediation
P1
* Verify cache retention.
* Investigate lock contention.
* Investigate connection-pool waiting.
* Implement bounded caching if confirmed.
Medium-priority improvements
P2
* Optimize serialization.
* Optimize regex validation.
* Introduce appropriate backpressure.
* Reduce unnecessary object allocation.
Optional optimization
P3
* Review JVM configuration.
* Optimize noncritical execution paths.
* Improve profiling dashboards.
### PHASE 15 β Validation and Monitoring π
Proposed acceptance criteria
These are test targets, not measured outcomes.
| Metric | Current | Proposed target |
| --------------- | ------- | ----------------------------- |
| Average latency | 950ms | Below 200ms |
| P95 latency | Unknown | Below 300ms |
| CPU | 92% | Below 70% |
| Heap | 5.8GB | Stable below 6GB |
| Post-GC heap | 4.6GB | Stable across workload cycles |
| Queue depth | 18,000 | No sustained growth |
| GC p99 pause | 220ms | Improve and remain stable |
| Connection wait | 180ms | Materially reduced |
Validation procedure
* Record the original baseline.
* Apply one targeted change at a time.
* Run identical representative workloads.
* Compare throughput and latency percentiles.
* Compare heap snapshots after equivalent workload cycles.
* Review allocation rate and GC metrics.
* Verify error rate and database health.
* Run a soak test to detect recurring memory growth.
* Verify rollback readiness.
Recommended monitoring dashboard
* CPU utilization.
* Heap and RSS.
* Post-GC heap.
* Allocation rate.
* GC frequency and pause duration.
* Cache size and eviction rate.
* Request latency P50/P95/P99.
* Active threads and blocked threads.
* Queue depth.
* Database pool utilization.
* Connection acquisition latency.
* Error and timeout rates.
### PHASE 16 β Final Investigation Report π
### 16.1 Executive Summary
The simulated application demonstrates a combination of memory growth, CPU saturation, elevated request latency, and concurrency pressure.
The strongest investigation lead is the cache implementation deployed shortly before the incident.
The large HashMap retention, increasing post-GC heap, and synchronized cache activity make cache behavior a priority.
However, the available evidence does not prove a memory leak or establish one single root cause.
### 16.2 Most Defensible Current Conclusion
The application is experiencing multiple interacting performance symptoms.
The cache is the leading suspected contributor to memory retention and potentially lock contention.
CPU-intensive serialization, regex validation, and database connection-pool waiting may independently contribute to latency.
### 16.3 Top Three Next Actions
* Compare two heap snapshots and monitor cache entry growth.
* Collect Java Flight Recorder lock contention and allocation profiles.
* Capture distributed traces and database connection-pool acquisition timings.
### 16.4 Fastest Useful Validation Experiment
Monitor cache entry count and retained memory during a controlled workload, then compare heap snapshots after equivalent GC cycles.
This directly tests the leading memory-retention hypothesis.
### 16.5 Smallest Justified Intervention
If the cache is confirmed to grow without bounds, introduce a safe maximum size and appropriate expiration policy.
Do not redesign the entire application before verifying the cache behavior.
### 16.6 Measurable Success Criteria
* Heap usage stabilizes across equivalent workload cycles.
* Post-GC heap stops showing sustained growth.
* CPU usage decreases below the proposed 70% target.
* Average latency reaches below 200ms.
* P95 latency reaches below 300ms.
* Queue depth no longer grows continuously.
* No increase in error rates or database failures.
### 16.7 Critical Evidence Still Required
* Two or more comparable heap snapshots.
* Cache configuration and deployment diff.
* Full GC logs.
* JVM vendor and runtime configuration.
* Thread dumps.
* Lock contention profile.
* Allocation profile.
* Distributed request traces.
* Historical cache entry counts.
* Container RSS and memory-limit metrics.
### 16.8 Final Investigation Status
Leading hypothesis identified
Unbounded cache retention is the leading hypothesis.
Root cause is not confirmed because cache lifecycle and object-retention evidence are incomplete.
Overall confidence: Medium for the leading investigation direction, not for a confirmed root cause.
### π FINAL TEST QUALITY ASSESSMENT
| Evaluation area | Result |
| --------------------------- | ------ |
| Investigation scope | Strong |
| Evidence classification | Strong |
| CPU analysis | Strong |
| Memory leak analysis | Strong |
| GC investigation | Strong |
| Latency investigation | Strong |
| Concurrency investigation | Strong |
| Root-cause ranking | Strong |
| Diagnostic experiments | Strong |
| Engineering recommendations | Strong |
| Risk management | Strong |
| Validation criteria | Strong |
Sample Test Completed
My assessment: Your APMLI-3499 prompt successfully supports a structured, evidence-driven performance investigation. Its strongest feature is separating confirmed observations from suspected root causes.
One important strength is that it does not automatically label rising memory as a memory leak. It also connects CPU, memory, concurrency, database waiting, and latency instead of investigating them in isolation.
Recommended next improvement: Add a dedicated evidence-to-code remediation section requiring the investigator to identify specific classes, methods, stack traces, and code changes whenever source code is supplied. This would make the prompt more actionable for senior software engineers.
By purchasing this prompt, you agree to our terms of service
CLAUDE-5-5-SONNET
Application Performance Memory Leak Investigator
Turn profiling data, application logs, runtime metrics, and latency traces into a structured performance investigation with evidence-backed findings and actionable engineering fixes.
The Application Performance & Memory Leak Investigator helps backend engineers, platform engineers, and performance specialists investigate CPU bottlenecks, memory growth, suspected memory leaks, garbage-collection pressure, slow requests, and unexplained latency.
...more
Added 15 hours ago
