Skip to content

Fix memory leaks in speedtest exporter#29

Merged
veerendra2 merged 2 commits into
mainfrom
feat/memory-optimization
Jun 3, 2026
Merged

Fix memory leaks in speedtest exporter#29
veerendra2 merged 2 commits into
mainfrom
feat/memory-optimization

Conversation

@veerendra2

@veerendra2 veerendra2 commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes observed memory growth (2MB → 12MB → 16MB over 2 hours) by optimizing handler allocation and improving garbage collection hints.

Close #28

Changes

  • Cache Prometheus handler: Moved promhttp.Handler() creation outside the request loop. Previously created a new handler instance per /metrics scrape, causing unnecessary allocations.
  • Explicit serverList cleanup: Set serverList = nil after extracting the target server to help GC reclaim the large server list object immediately.
  • Store handler in Exporter: Added metricsHandler field to reuse across all scrapes.

Impact

  • Reduces per-scrape memory allocations significantly
  • Handler is now created once at startup, not per-request
  • Large server list objects are released faster after each scrape

Testing

  • Build succeeds
  • Exporter starts without errors
  • Monitor memory growth over next few hours to confirm stabilization

🤖 Generated with Claude Code

- Cache Prometheus handler instead of creating per-request (major optimization)
- Explicitly nil serverList after use to aid garbage collection
- Store metricsHandler in Exporter struct for reuse across scrapes

This addresses the observed memory growth (2MB → 12MB → 16MB over 2 hours).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@veerendra2
veerendra2 marked this pull request as ready for review June 2, 2026 12:07
@veerendra2
veerendra2 merged commit 4300afe into main Jun 3, 2026
1 check passed
@veerendra2
veerendra2 deleted the feat/memory-optimization branch June 3, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix memory leaks in v1.3.0

1 participant