Skip to content

reset bufReader to avoid extreme growth of buffers - #10347

Merged
jessfraz merged 2 commits into
moby:masterfrom
unclejack:bufreader_reset
Mar 23, 2015
Merged

jessfraz merged 2 commits into
moby:masterfrom
unclejack:bufreader_reset

Conversation

@unclejack

Copy link
Copy Markdown
Contributor

This PR is an attempt to help solve problems like #9139 and #8502.

This PR changes bufReader to try to avoid the growth of bytes.Buffer to extreme sizes (hundreds of megabytes or even gigabytes). This makes long running containers which need to log to the console more reliable over time.

Please note that this PR only fixes this problem for now. Proper logging support is still needed.

Fixes #9139
Fixes #8539
Fixes #8502

@unclejack

Copy link
Copy Markdown
Contributor Author

ping @LK4D4

@tiborvass tiborvass added this to the 1.5.1 milestone Jan 26, 2015
@LK4D4

LK4D4 commented Jan 26, 2015

Copy link
Copy Markdown
Contributor

I tested - this fixing problem. I'm not reviewed code though.

@unclejack

Copy link
Copy Markdown
Contributor Author

@LK4D4 Thanks for trying it out!

@unclejack

Copy link
Copy Markdown
Contributor Author

This PR fixes 3 issues and it needs to be reviewed so that I can make any necessary changes after review and feedback.

ping @crosbymichael @dmcgowan @duglin @erikh @icecrime @jfrazelle @jlhawn @LK4D4 @tiborvass @vbatts

Comment thread pkg/ioutils/readers.go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't there potential here to overstep bounds with the type conversions? Should these really be int instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erikh I've made this explicit to avoid problems on 32bit platforms. I'm not sure how this could cause a problem.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess int automatically gets promoted, or something. Sorry to waste your time.

@dmcgowan

dmcgowan commented Feb 3, 2015

Copy link
Copy Markdown
Member

looks good, the branching logic for reset should be cleaned up for readability and reduce the if blocks as Josh suggested

Comment thread pkg/ioutils/readers.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there is time.Since for such thing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LK4D4 I'm using now later on in the code and I'm avoiding getting a timestamp twice using this.

@unclejack

Copy link
Copy Markdown
Contributor Author

@LK4D4 I've made some of the changes, but I'd like to keep those numbers as 64 bit ints everywhere to avoid having to sprinke int64(var) in some places.

@stevvooe There's a description now. Please take a look and let me know if it looks good to you.

@unclejack

Copy link
Copy Markdown
Contributor Author

I've updated the PR to remove the truncate.

@thaJeztah

Copy link
Copy Markdown
Member

@unclejack should this be moved to the 1.6 milestone? iiuc, there won't be a 1.5.1 release?

Also wondering if something is holding up this PR (apart from time constraint), as it seems to be resolving quite some issues 👍

@unclejack

Copy link
Copy Markdown
Contributor Author

I've rebased this PR on master and I'm using a binary built from this branch as my Docker daemon.

@thaJeztah It needs more testing and reviews at this point. This was the simplest change which could have been made to fix this problem without hurting performance after trying many other options. There's not much left to change regarding the design itself.

@stevvooe

stevvooe commented Mar 5, 2015

Copy link
Copy Markdown
Contributor

@unclejack Thanks for the explanation. So, this is effectively a buffer reader that does some read ahead?

@lqez

lqez commented Mar 16, 2015

Copy link
Copy Markdown

👍

@jessfraz jessfraz modified the milestones: 1.6.0, 1.5.1 Mar 16, 2015
@unclejack

Copy link
Copy Markdown
Contributor Author

@stevvooe Yes, it does read ahead so that it doesn't block the other readers by avoiding a reader to take too long to read everything.

We need to figure out what else needs to be done for this and get it merged. Many users are affected by the problem this PR fixes.

@unclejack

Copy link
Copy Markdown
Contributor Author

The PR has been rebased on master and comments have been added.
@tiborvass PTAL

@unclejack

Copy link
Copy Markdown
Contributor Author

This PR needs to be in 1.6.0.

@LK4D4

LK4D4 commented Mar 23, 2015

Copy link
Copy Markdown
Contributor

LGTM

1 similar comment
@jessfraz

Copy link
Copy Markdown
Contributor

LGTM

jessfraz pushed a commit that referenced this pull request Mar 23, 2015
reset bufReader to avoid extreme growth of buffers
@jessfraz
jessfraz merged commit c4603de into moby:master Mar 23, 2015
@unclejack
unclejack deleted the bufreader_reset branch March 23, 2015 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet