ipfs / ipfs/helia

High Memory Usage with Persistent IPFS Node in Browser via Helia

Open
#526 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.3k
Forks
159
Avg merge
2h 11m
Merged PRs (30d)
16

Description

I have initialized an IPFS node in my browser using the Helia package with persistence enabled. As the peerstore grows (currently over 5,000 peers), the memory consumption has reached 1GB. Despite spending dozens of hours reviewing the Helia and js-libp2p documentation, I haven't found an effective way to manage these resources. Specifically, I am struggling with reducing the number of storage peers and managing the current memory usage.

**Environment**:
- Browser version: Google Chrome 123.0.6312, Microsoft Edge 123.2420
- OS: Windows 2022

**Attempts to Resolve**:
- Documentation Reviewed:
- [Helia Initialization Interface](https://helia.io/interfaces/helia.HeliaInit.html)
- [Libp2p Initialization Options](https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html)
- [Libp2p Limits](https://github.com/libp2p/js-libp2p/blob/main/doc/LIMITS.md)

- Configurations Tried:
```javascript
import { IDBBlockstore } from 'blockstore-idb';
import { IDBDatastore } from 'datastore-idb';
import { createHelia } from 'helia';
import { yamux } from '@chainsafe/libp2p-yamux'
import { mplex } from '@libp2p/mplex'
import { noise } from '@chainsafe/libp2p-noise'

const instantiateHeliaNode = async () => {
const datastore = new IDBDatastore('/datastore2');
const blockstore = new IDBBlockstore('/blockstore2');
await datastore.open();
await blockstore.open();
const heliaInstance = await createHelia({
libp2p: {
streamMuxers: [
yamux(),
mplex()
],
connectionEncryption: [
noise()
],
connectionManager: {
maxConnections: 200,
minConnections: 4,
maxIncomingPendingConnections: 100,
inboundConnectionThreshold: 100
}
},
peerStore: {
persistence: false,
threshold: 5
},
keychain: {
pass: 'very-strong-password',
dek: {
hash: 'sha2-512',
salt: 'at-least-16-char-long-random-salt',
iterationCount: 2000,
keyLength: 64
}
},
datastore: datastore,
blockstore: blockstore
});

return heliaInstance;
};

window.helia = await instantiateHeliaNode();
```

I am seeking advice on how to automatically clean up the number of stored peers or set a cap on it.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.