Bitswap is slower with a DHT vs without

I have been debugging why part of my program runs so slow and I have narrowed it down to whether or not there is a DHT component in Libp2p/Helia.

In my testing I found it took around a minute to add a pin with a DHT and around 10s without. The pinned content is on another node on the same machine with a direct connection to it so network issues should be minimal.

I’ve found in the tests for bitswap that the timeouts are quite different with DHT and without DHT so I’m guessing this behavior should be expected:

describe('bitswap without DHT', function () {
  this.timeout(20 * 1000)
...
describe('bitswap with DHT', function () {
  this.timeout(60 * 1000)

Why does Bitswap (Helia) use the DHT when it is so much slower? Is there an option to configure Helila/Bitswap to not use the DHT even though it is present?

@Saul thanks for the great question!

Why bitswap use DHT if it’s slower

I am not sure about this, but maybe someone with deeper protocol knowledge (@Jorropo @danieln @achingbrain) could chime in.

Is there an option to configure Helia’s bitswap instance not to use the DHT?

This was discussed in Allow for custom data transfer mechanisms · Issue #109 · ipfs/helia · GitHub and Multiple/alternative data retrieval implemenations · Issue #98 · ipfs/helia · GitHub, and now with the helia@next release and the BlockBroker interface, you should be able to customize the bitswap instance being used by Helia.

You can find the BlockBroker interface for bitswap at https://github.com/ipfs/helia/blob/main/packages/helia/src/block-brokers/bitswap.ts

Please let us know if you try it out and run into any issues =)

The increased time to pin using the DHT is likely the time it takes to publish to the DHT, no? Without the DHT this doesn’t happen.

The increased time to pin using the DHT is likely the time it takes to publish to the DHT, no? Without the DHT this doesn’t happen.

As far as I can tell the publish isn’t waited on:

Also I am getting similar speeds when manually traversing the DAG with blockstore.get so it’s not the pinning specifically.

1 Like