Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Why is the local file access is so slow ? #1766

Closed
stanbar opened this issue Dec 9, 2018 · 5 comments
Closed

Why is the local file access is so slow ? #1766

stanbar opened this issue Dec 9, 2018 · 5 comments
Labels
kind/support A question or request for support

Comments

@stanbar
Copy link

stanbar commented Dec 9, 2018

  • Version: 0.33.1
  • Platform: Darwin 18.2.0

Type: Question

I'm extedning the example browser-video-streaming. I'm storing some videos in my local ipfs, and it's corresponding metadata in dag. I'm wondering why is the video file streaming so slow on my browser local? Isn't it connected to my local node directly?
When I force the browser node to connect to my local node like:

function createNode(): Promise<any> {
    const node = new IPFS();
    return new Promise((resolve, reject) => {
        node.on('ready', () => {
node.swarm.connect("/ip4/127.0.0.1/tcp/4001/ipfs/QmaeUxeAK3N5fyU5o5W8eFeHGy7SUgcxfscewNNGgFak8L");
                resolve(node)
            }
        )
    });
}

it throws
dial.js:365 Uncaught (in promise) Error: Circuit not enabled and all transports failed to dial peer QmaeUxeAK3N5fyU5o5W8eFeHGy7SUgcxfscewNNGgFak8L!

When I do:

const peers: Peer [] = await node.swarm.peers();
peers.forEach(peer => console.log(multiaddr(peer.addr).toString()));

it only shows:
/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd
/dns4/lon-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3
/dns4/nyc-1.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm
I guess it is not aware of my local node at all, so it tries to resolve files over internet. Is there any way to share my local repo or just connect to my local node ?

@daviddias daviddias added the kind/support A question or request for support label Dec 9, 2018
@daviddias
Copy link
Member

Hi @stasbar, there are a couple of things happening here, I'll try answering them by parts.

The first one is that browsers do not support TCP and therefore, when you do the swarm.connect call, your node is figuring that the peer you want to connect is using a Transport that it doesn't has and so it is trying to use Circuit Relay to reach out to it, however, given that you don't have Circuit Relay Enabled, it is failing. Learn more about Circuit Relay here https://github.com/ipfs/js-ipfs/tree/master/examples/circuit-relaying#tutorial---understanding-circuit-relay

On the slowness, v0.34.0 #1721 will bring some drastic performance improvements and you will see things getting better. However, in your case because you don't have a direct connection, the file is actually being streamed by preload nodes that exist on the IPFS Infrastructure, so that extra hop adds a bit of delay.

@daviddias daviddias added the status/deferred Conscious decision to pause or backlog label Dec 9, 2018
@stanbar
Copy link
Author

stanbar commented Dec 9, 2018

Thank you for your answer @daviddias , you showed me where the problem is. But is there any solution? I would like to watch the video in my browser, even when offline. Is it possible at the moment?

@daviddias
Copy link
Member

@stasbar it is indeed. You just need to enable a WebSockets listener in your local Desktop node. The tutorial -- https://github.com/ipfs/js-ipfs/tree/master/examples/exchange-files-in-browser -- shows how to do it :)

@stanbar
Copy link
Author

stanbar commented Dec 11, 2018

Thank you, it worked ❤️

@stanbar stanbar closed this as completed Dec 11, 2018
@ghost ghost removed the status/deferred Conscious decision to pause or backlog label Dec 11, 2018
@daviddias
Copy link
Member

Awesome! Glad to help :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/support A question or request for support
Projects
None yet
Development

No branches or pull requests

2 participants