Skip to content

Conversation

@huksley
Copy link
Member

@huksley huksley commented Oct 25, 2025

This commit addresses GitHub issue #61 where memory usage keeps increasing and garbage collection fails, eventually causing node crashes after several days.

Root Causes:

  1. SimpleDateFormat objects were created on every message send operation (expensive and thread-unsafe, causing significant memory pressure)
  2. HashMap and StringBuilder objects were allocated on every message (constant allocations under high throughput causing GC pressure)

Changes Made:

PlainSender.java:

  • Added ThreadLocal to reuse date formatter instances
  • Added ThreadLocal to reuse string builder instances

CEFSender.java:

  • Added ThreadLocal to reuse string builder (512 byte capacity)

FullSender.java:

  • Added ThreadLocal instances for structured data parameters
  • Added ThreadLocal for dumpMessage method
  • All maps are cleared and reused instead of creating new instances

StructuredSender.java:

  • Added ThreadLocal instances for structured data parameters
  • Maps are cleared and reused on each message

TransparentSyslogSender.java:

  • Added ThreadLocal to reuse date formatter
  • Added ThreadLocal to reuse string builder (256 byte capacity)

SnareWindowsSender.java:

  • Added ThreadLocal for both syslog and MS Event formats
  • Added ThreadLocal to reuse string builder (512 byte capacity)

Impact:
These changes significantly reduce object allocations and GC pressure by reusing thread-local instances instead of creating new objects for every message. This is especially critical under high message throughput where the plugin was previously creating millions of short-lived objects.

The ThreadLocal pattern ensures thread-safety while maintaining performance and dramatically reducing memory consumption.

Fixes #61

🤖 Generated with Claude Code

This commit addresses GitHub issue #61 where memory usage keeps increasing
and garbage collection fails, eventually causing node crashes after several days.

Root Causes:
1. SimpleDateFormat objects were created on every message send operation
   (expensive and thread-unsafe, causing significant memory pressure)
2. HashMap and StringBuilder objects were allocated on every message
   (constant allocations under high throughput causing GC pressure)

Changes Made:

PlainSender.java:
- Added ThreadLocal<SimpleDateFormat> to reuse date formatter instances
- Added ThreadLocal<StringBuilder> to reuse string builder instances

CEFSender.java:
- Added ThreadLocal<StringBuilder> to reuse string builder (512 byte capacity)

FullSender.java:
- Added ThreadLocal<HashMap> instances for structured data parameters
- Added ThreadLocal<StringBuilder> for dumpMessage method
- All maps are cleared and reused instead of creating new instances

StructuredSender.java:
- Added ThreadLocal<HashMap> instances for structured data parameters
- Maps are cleared and reused on each message

TransparentSyslogSender.java:
- Added ThreadLocal<SimpleDateFormat> to reuse date formatter
- Added ThreadLocal<StringBuilder> to reuse string builder (256 byte capacity)

SnareWindowsSender.java:
- Added ThreadLocal<SimpleDateFormat> for both syslog and MS Event formats
- Added ThreadLocal<StringBuilder> to reuse string builder (512 byte capacity)

Impact:
These changes significantly reduce object allocations and GC pressure by
reusing thread-local instances instead of creating new objects for every
message. This is especially critical under high message throughput where
the plugin was previously creating millions of short-lived objects.

The ThreadLocal pattern ensures thread-safety while maintaining performance
and dramatically reducing memory consumption.

Fixes #61

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@huksley huksley closed this Oct 25, 2025
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.

SSL/Syslog output cef - OOM graylog crashed

3 participants