Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract template registry to its own class #158

Merged

Conversation

yaauie
Copy link
Contributor

@yaauie yaauie commented Aug 24, 2018

This PR reduces the complexity of creating, persisting, loading, and retrieving BinData::Struct instances from the local- and file-based caches by extracting the relevant code and the necessary threadsafety mutexes into a new thread-safe class called TemplateRegistry.

This new class has two main entry points:

  • TemplateRegistry.register(key, fields): in a thread-safe manner and respecting the codec's @cache_ttl, register the given list of fields as a new BinData::Struct, persisting to disk if configured to do so.
  • TemplateRegistry.fetch(key): in a thread-safe manner, retrieve the BinData::Struct that has been registered with the given key.

It uses the existing tests to prove itself.

There is a minor change in behaviour to this implementation that surfaces in non-happy-path scenarios: when encountering a corrupt file, an unwritable file, or any other exception reading or writing the file, this implementation logs an error and continues instead of crashing the codec and potentially its input.

@jorritfolmer
Copy link
Contributor

Awesome! Thanks for the rework!
Performance is up +10% with 2 workers.

@jorritfolmer jorritfolmer merged commit e9575ef into logstash-plugins:master Aug 25, 2018
@yaauie yaauie deleted the isolated-template-cache branch August 28, 2018 15:18
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.

None yet

2 participants