forked from natefinch/lumberjack
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Only run mill goroutine as long as is needed #2
Open
jdhenke
wants to merge
1
commit into
v2.0
Choose a base branch
from
only-mill-as-needed
base: v2.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jdhenke
force-pushed
the
only-mill-as-needed
branch
from
August 6, 2019 23:31
5d19ece
to
a2b11fe
Compare
jdhenke
force-pushed
the
only-mill-as-needed
branch
from
August 6, 2019 23:45
a2b11fe
to
26c3208
Compare
jdhenke
pushed a commit
that referenced
this pull request
Aug 6, 2019
Previously, each lumberjack logger starts its own mill goroutine the first time that the logger writes to a file, and the goroutine is never stopped. The project has an open pull request, natefinch#80, to stop the goroutine when the logger is closed. However, even with that design, each open logger will always have a mill goroutine that is active (even if it is not performing work). It also means that a logger will never be garbage-collected (and hence its file will never be closed) unless it is explicitly closed. Furthemore, even if a logger is explicitly closed, if Write is called on any references to that logger, that will restart the persistent mill goroutine and reintroduce the leaked file handle. This change modifies the mill goroutine logic. It still maintains the overall design of synchronously rotating and asynchronously deleting and compressing (milling) the old, rotated log files, and that if a request to mill comes in while one call is already happening, another mill will be executed after the current one to ensure any newly rotated files are not missed. There is at most one active mill goroutine which is in the process of performing a single pass of deletions and compressions of rotated log files, and at most one queued mill goroutine which is just waiting on a mutex. Now, each mill goroutine exits once a single pass is done and future calls to mill will start a new goroutine (if one is not already queued.) This modification allows for lumberjack loggers to be garbage-collected, which allows it to close file handles gracefully without an explicit call to "close". The downside to this new approach is in the case where rotations are constantly happening, rather than having a single goroutine simply process each mill pass, a new goroutine must be started for each pass. --- We have an internal fork of lumberjack that contains this change that we are using in production. An alternative approach was sketched after the fact that is not in use internally but would have at most one mill goroutine per logger at any time, rather than one active and one queued as in this approach. This alternative design is shown here: #2
jdhenke
changed the title
only run a mill goroutine as long as it is needed
Only run mill goroutine as long as is needed
Aug 6, 2019
jdhenke
pushed a commit
that referenced
this pull request
Aug 6, 2019
Previously, each lumberjack logger starts its own mill goroutine the first time that the logger writes to a file, and the goroutine is never stopped. The project has an open pull request, natefinch#80, to stop the goroutine when the logger is closed. However, even with that design, each open logger will always have a mill goroutine that is active (even if it is not performing work). It also means that a logger will never be garbage-collected (and hence its file will never be closed) unless it is explicitly closed. Furthemore, even if a logger is explicitly closed, if Write is called on any references to that logger, that will restart the persistent mill goroutine and reintroduce the leaked file handle. This change modifies the mill goroutine logic. It still maintains the overall design of synchronously rotating and asynchronously deleting and compressing (milling) the old, rotated log files, and that if a request to mill comes in while one call is already happening, another mill will be executed after the current one to ensure any newly rotated files are not missed. There is at most one active mill goroutine which is in the process of performing a single pass of deletions and compressions of rotated log files, and at most one queued mill goroutine which is just waiting on a mutex. Now, each mill goroutine exits once a single pass is done and future calls to mill will start a new goroutine (if one is not already queued.) This modification allows for lumberjack loggers to be garbage-collected, which allows it to close file handles gracefully without an explicit call to "close". The downside to this new approach is in the case where rotations are constantly happening, rather than having a single goroutine simply process each mill pass, a new goroutine must be started for each pass. --- We have an internal fork of lumberjack that contains this change that we are using in production. An alternative approach was sketched after the fact that is not in use internally but would have at most one mill goroutine per logger at any time, rather than one active and one queued as in this approach. This alternative design is shown here: #2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.