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

fix the memory leak on the wait API #1862

Merged
merged 4 commits into from
Mar 7, 2015

Conversation

mountkin
Copy link
Contributor

@mountkin mountkin commented Mar 6, 2015

The pollForIndex method starts a goroutine to check the latest index
periodically. But when the HTTP request finishs, the loop is still there
and the goroutine never exits.

This leads to a memory leak and goroutine leak after each request to the
"/wait/:index" API.

The problem can be reproduced by ab -c 10 -t 30 http://127.0.0.1:8086/wait/1.
After several times of benchmark you'll find that the memory usage grows markedly.

Signed-off-by: Shijiang Wei mountkin@gmail.com

@mountkin
Copy link
Contributor Author

mountkin commented Mar 6, 2015

Test is broken. I'll look into it.

The pollForIndex method starts a goroutine to check the latest index
periodically. But when the HTTP request finishs, the loop is still there
and the goroutine never exits.

This leads to a memory leak and goroutine leak after each request to the
"/wait/:index" API.

The problem can be reproduced by ```ab -c 10 -t 30 http://127.0.0.1:8086/wait/1```.
After several times of benchmark you'll find that the memory usage grows markedly.

Signed-off-by: Shijiang Wei <mountkin@gmail.com>
@mountkin mountkin force-pushed the fix-memory-leak-of-wait-api branch from 300a32e to 6d5ca0e Compare March 6, 2015 09:21
Signed-off-by: Shijiang Wei <mountkin@gmail.com>
Signed-off-by: Shijiang Wei <mountkin@gmail.com>
@otoolep
Copy link
Contributor

otoolep commented Mar 6, 2015

This change generally makes sense to me -- thanks @mountkin . However, can you move the new type and methods to nearer the top of the file, where is it isn't simply in the middle of other handler methods?

Signed-off-by: Shijiang Wei <mountkin@gmail.com>
@mountkin
Copy link
Contributor Author

mountkin commented Mar 7, 2015

Hi @otoolep
I just removed the new type and re-implement it with sync/atomic, which seems to be much cleaner.

@corylanou
Copy link
Contributor

@mountkin very clean approach. I like it a lot.

@corylanou
Copy link
Contributor

@mountkin can you sign the CLA here http://influxdb.com/community/cla.html and then we can merge.

@mountkin
Copy link
Contributor Author

mountkin commented Mar 7, 2015

@corylanou CLA signed

corylanou added a commit that referenced this pull request Mar 7, 2015
@corylanou corylanou merged commit 41e01e4 into influxdata:master Mar 7, 2015
corylanou added a commit that referenced this pull request Mar 7, 2015
corylanou added a commit that referenced this pull request Mar 7, 2015
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

3 participants