Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

optimize peerstore memory #71

Merged
merged 3 commits into from
Apr 23, 2019
Merged

optimize peerstore memory #71

merged 3 commits into from
Apr 23, 2019

Conversation

Stebalien
Copy link
Member

fixes #68

Ideally, we'd store a bitmap. But we'll have to think through how we want that
to play out with the datastore-backed peerstore (maybe move the `*Protocols`
methods down to the backend implementation?).
@ghost ghost assigned Stebalien Apr 23, 2019
@ghost ghost added the status/in-progress In progress label Apr 23, 2019
@Stebalien Stebalien requested a review from raulk April 23, 2019 08:01
@@ -75,13 +80,30 @@ func (ps *peerstore) PeerInfo(p peer.ID) PeerInfo {
}
}

func (ps *peerstore) internProtocol(s string) string {
if len(s) > maxInternedProtocolSize {
Copy link
Member Author

Choose a reason for hiding this comment

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

These checks are in case we're using, e.g., the datastore backed peerstore.

peerstore.go Show resolved Hide resolved
pstoremem/metadata.go Show resolved Hide resolved
@Stebalien
Copy link
Member Author

Ideally, we'd handle this in the actual peerstore implementation but that would require pushing these functions down into the implementation. If we do that, we can, e.g., use a bitfield in the memory version and some kind of id system in the datastore backed version.

peerstore.go Outdated
@@ -10,6 +10,9 @@ import (

var _ Peerstore = (*peerstore)(nil)

const maxInternedProtocols = 256
const maxInternedProtocolSize = 96
Copy link
Contributor

Choose a reason for hiding this comment

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

let's make these a little larger.

Copy link
Member

Choose a reason for hiding this comment

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

I think the sizing is fine; can't really see protocol strings being longer than 96 chars nor us handling 256 unique proto IDs over a long period. (Opinion weakly held).

Copy link
Member Author

Choose a reason for hiding this comment

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

Upped. Note: I consider this to be a temporary fix. We should probably specialize protocol handling and push it down into the peerstore implementations.

Copy link
Member Author

Choose a reason for hiding this comment

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

I doubt this'll be an issue but 512/256 is probably fine anyways (128KiB).

Copy link
Member

@raulk raulk left a comment

Choose a reason for hiding this comment

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

LGTM.

pstoremem/metadata.go Show resolved Hide resolved
512 * 256 (max path length on many systems) = 128KiB
@Stebalien Stebalien merged commit b496ee5 into master Apr 23, 2019
@ghost ghost removed the status/in-progress In progress label Apr 23, 2019
@Stebalien Stebalien deleted the feat/optimize-mem branch April 23, 2019 16:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deduplicate stored protocols
3 participants