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

Fixing memory leak #363

Merged
merged 5 commits into from
Jun 25, 2019
Merged

Fixing memory leak #363

merged 5 commits into from
Jun 25, 2019

Conversation

kazu-yamamoto
Copy link
Collaborator

@ocheron found that session values of ByteString lead memory leak. I also found that session keys (IDs) of ByteString leak memory. 1afb213 fixes it. In my server, this reduced memory usage from 30% to 11%.

b0ba6a9 changes the internal data structure from ByteString to ShortByteString to avoid fragmentation. This improves memory footprint from 11% to 5%. I did both experiments with dbMaxSize = 1,000.

@kazu-yamamoto
Copy link
Collaborator Author

Ping @ocheron
I think this should be urgent.

@vincenthz
Copy link
Collaborator

why not move to basement Block Word8 instead of ShortByteString ?

@kazu-yamamoto
Copy link
Collaborator Author

I used ShortByteString because it is available if bytestring is installed.

Would you tell me advantages of Block?

@vincenthz
Copy link
Collaborator

vincenthz commented Jun 21, 2019

@kazu-yamamoto much better and complete APIs : http://hackage.haskell.org/package/basement-0.0.10/docs/Basement-Block.html and breaking from the monomorphic Word8-biased world.

or even the type-level-size'd version http://hackage.haskell.org/package/basement-0.0.10/docs/Basement-Sized-Block.html

@kazu-yamamoto
Copy link
Collaborator Author

@vincenthz How to convert ByteString to Block Word8. I gave a look but did not find how to convert.

@ocheron
Copy link
Contributor

ocheron commented Jun 22, 2019

convert from memory should work.

@ocheron
Copy link
Contributor

ocheron commented Jun 22, 2019

Additionally, I'm wondering if the copy in handshakeTerminate could be moved earlier in the code flow.
If done before calling setSession, the original sessionId would not be retained by the context.
This needs to be done only for sessionIds parsed from a network packet.

Other than that it looks good.
The bang pattern in let !v = (sd',ref) is not necessary but that was preexisting.

EDIT: when -> before

@vincenthz
Copy link
Collaborator

as @ocheron point out convert is the way to go, but it's even possible (I haven't checked this particular one) fromList . BS.unpack would be somewhat optimized (good producer/consumer) or even better fromListN (BS.length bs) (BS.unpack bs)

@kazu-yamamoto
Copy link
Collaborator Author

@ocheron @vincenthz Thanks. Now Block and convert are used.

@kazu-yamamoto
Copy link
Collaborator Author

@ocheron

Additionally, I'm wondering if the copy in handshakeTerminate could be moved earlier in the code flow.
If done before calling setSession, the original sessionId would not be retained by the context.
This needs to be done only for sessionIds parsed from a network packet.

Would you pursue this idea in another issue? We should release version 1.5.1 asap.

kazu-yamamoto added a commit to kazu-yamamoto/hs-tls that referenced this pull request Jun 25, 2019
@kazu-yamamoto kazu-yamamoto merged commit 36fdb18 into haskell-tls:master Jun 25, 2019
@kazu-yamamoto kazu-yamamoto deleted the leak branch June 25, 2019 03:08
@kazu-yamamoto
Copy link
Collaborator Author

I have rebased and merged this PR.

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