-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Lag on catReadableStream (possibly other stream methods as well) #1706
Comments
@alanshaw I don't think these are the same but could be the same cause? #1709 sounds like it is taking 8 seconds to transfer a local file from one local peer to another and does not seem to have anything to do with the websocket functionality. My issue is that the embedded browser node from I was thinking at first that it could be blocks that are out of order coming in first and the lag is due to waiting for the initial blocks to construct the beginning of the stream but then remembered reading something in the white paper for IPFS that said that beginning blocks are sent first to avoid such an issue? |
@lifeBCE is the first data event being triggered after the full response is received? |
@alanshaw It does eventually get triggered but it doesn't seem to be after the full download completes. It seems to be about the same 8-10 seconds regardless of the size of the file. I have tested this against small 30 second video clips as well as an over 2 hour video and the lag time is the same for both and any length in between. I have added some additional logic to my service to pre-load the first 5 MB of the next video in order to combat this lag a bit and that does seem to help. Pre-loaded videos show about only a 2 second lag before the |
Did some initial digging. According to js-ipfs/src/core/components/files-regular.js Line 249 in ac5fa8e
The logic above is called from the public function definition here: js-ipfs/src/core/components/files-regular.js Line 382 in ac5fa8e
I started honing in on Doing some A/B testing (maybe benchmarking) between
This is where the Looks like something is lagging when calling the |
@lifeBCE a few things I think you can check/do:
|
const IPFS = require('ipfs');
const pull = require('pull-stream')
const type = process.argv[2];
console.log('Instantiating IPFS node');
const node = new IPFS();
const hash = 'QmRm5YAWoudjGj926YKc2PuBFX7vTp2YzqbWFdmqyqWRQS';
const streamFunc = type === 'readable' ? node.files.catReadableStream : node.files.catPullStream;
let dataEvent = false;
node.on('ready', () => {
console.log('IPFS node is ready');
const readyTime = Math.floor(Date.now() / 1000);
const stream = streamFunc(hash, { offset: 0, length: 5000000 });
console.log('Stream has been created, waiting for data....');
const pullable = () => {
pull(
stream,
pull.concat((err, data) => {
if (!dataEvent) {
dataEvent = true;
const dataTime = Math.floor(Date.now() / 1000);
console.log('Stream is receiving data: ' + Math.floor(dataTime - readyTime) + ' seconds');
}
})
)
}
const readable = () => {
stream.on('data', (block) => {
if (!dataEvent) {
dataEvent = true;
const dataTime = Math.floor(Date.now() / 1000);
console.log('Stream is receiving data: ' + Math.floor(dataTime - readyTime) + ' seconds');
}
})
stream.on('end', () => node.stop());
}
type === 'readable' ? readable() : pullable();
})
node.on('error', error => {
console.error(error.message);
}) Execute like:
Don't forget to blow away your local cache after each run or the next run will be invalid (0 seconds). Example Output:
The hash is a large video file of some IPFS demo from a couple years ago that has been formatted as DASH. The contents of the file is not super important, just needed a larger file to ensure that it wasn't lagging waiting until the complete file downloaded. This example logic here generates a 12-13 second lag repeatedly for me when using either stream. |
Looking into this I've opened a PR ipfs-inactive/js-ipfs-unixfs-exporter#13 which shaves a number of seconds off the time to first byte, but the significant delay of around 10s remains. It's worth noting that your node needs to receive some blocks before it can start emitting data, as has to do a depth first traversal before it gets to the node with the first byte of data. UPDATE: if I add a 15s timeout after the node is ready and then start the (there's some extra logging in here that I've added) Before: $ rm -rf ~/.jsipfs && node slow-cat2.js
Instantiating IPFS node
ipld got block QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V
ipld got block QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y
ipld got block QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT
ipld got block QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB
ipld got block QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7
ipld got block QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha
ipld got block QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs
ipld got block QmQ5vhrL7uv6tuoN9KeVBwd4PwfQkXdVVmDLUZuTNxqgvm
ipld got block QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC
ipld got block QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te
ipld got block QmfGBRT6BbWJd7yUc2uYdaUZJBbnEFvTqehPFoSMQ6wgdr
ipld got block QmfGBRT6BbWJd7yUc2uYdaUZJBbnEFvTqehPFoSMQ6wgdr
ipld got block QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V
ipld got block QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y
ipld got block QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha
ipld got block QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC
ipld got block QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7
ipld got block QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB
ipld got block QmQ5vhrL7uv6tuoN9KeVBwd4PwfQkXdVVmDLUZuTNxqgvm
ipld got block QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te
ipld got block QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT
ipld got block QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs
ipld got block QmZ9ANfh6BMFoeinQU1WQ2BQrRea4UusEikQ1kupx3HtsY
ipld got block QmdEtks1KYQsrgJ8FXpP1vXygnVHSqnyFTKQ3wcWVd4D2y
ipld got block QmbxHkprr5qdLSK8EZWdBzKFzNXGoKrxb7A4PHX3eH6JPp
Swarm listening on /ip4/127.0.0.1/tcp/4002/ipfs/QmVArb8KVn94EjfxewDtuWy3zgUCXRAq7waLkzchCCgiCA
Swarm listening on /ip4/192.168.1.68/tcp/4002/ipfs/QmVArb8KVn94EjfxewDtuWy3zgUCXRAq7waLkzchCCgiCA
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/ipfs/QmVArb8KVn94EjfxewDtuWy3zgUCXRAq7waLkzchCCgiCA
ipld got block QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn
ipfs-unixfs-exporter resolved QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn
ipld got block QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn
IPFS node is ready
Waiting 15s...
Stream has been created, waiting for data....
ipfs-bitswap getFromOutside QmaFzTWvp9ktfeC7co1jMCvHQQ2uLpNbEEqdttEEyHVQS3
ipfs-bitswap received block QmaFzTWvp9ktfeC7co1jMCvHQQ2uLpNbEEqdttEEyHVQS3
ipld got block QmaFzTWvp9ktfeC7co1jMCvHQQ2uLpNbEEqdttEEyHVQS3
ipfs-unixfs-exporter resolved QmaFzTWvp9ktfeC7co1jMCvHQQ2uLpNbEEqdttEEyHVQS3
ipfs-bitswap getFromOutside QmT91fmjEBBbVBc774oiR3W8rTv1UZt7iUajRpF4Ri5wWg
ipfs-bitswap received block QmT91fmjEBBbVBc774oiR3W8rTv1UZt7iUajRpF4Ri5wWg
ipld got block QmT91fmjEBBbVBc774oiR3W8rTv1UZt7iUajRpF4Ri5wWg
ipfs-unixfs-exporter resolved QmT91fmjEBBbVBc774oiR3W8rTv1UZt7iUajRpF4Ri5wWg
js-ipfs collected GO� tT'+��mVڻݭ�ۢ3�A
ipfs-bitswap getFromOutside QmUyyM7CfmosHtKCY6PsAeU7dLsj4gL2iurQgtP17fvSaP
ipfs-bitswap received block QmUyyM7CfmosHtKCY6PsAeU7dLsj4gL2iurQgtP17fvSaP
ipfs-bitswap getFromOutside QmbcpWEkchyeSc5FMkpVkQs6AD3a5nozR3SYy7oyvMFZbN
ipfs-bitswap getFromOutside QmfXApKEQiFpoZwCiEPiKG7r5PqUWey2HHRwHg7XvRrXrg
ipfs-bitswap getFromOutside QmaWGUpyGuVjqax1Kf3ZxzA9Ta2rgXUJyEs7uZJ7reSv9b
ipfs-bitswap getFromOutside QmZDdGHgy8oCNuMmNbS3BdEYysnqBJmeduqck3yrynRSWB
ipfs-bitswap getFromOutside QmdAr7yCgn8KZQr32KaxLwxHFuUbY2sQfqNKPfk494dCky
ipfs-bitswap getFromOutside Qmegd6yHtYP49eLRBq7VKH1SCrEKY9PSZZseaFXJEBniZv
ipfs-bitswap getFromOutside QmNWGfRSL9krg5swbjZZCofc9SBC7oZixJv6WKCDaLRSzv
ipfs-bitswap getFromOutside Qmay5VLWsYQwF1a4z7zB6Y8GGA2iiQTCNSGs7NUjimpDSn
ipfs-bitswap getFromOutside QmbbnxCX4rtC9My2K4B4ZhM2bHHRPQAXnvFeJyEnjUudjx
ipfs-bitswap getFromOutside QmPK8odxBVSKpKkzP3xdM9LyhLC7VcZgtJyqNmfeMdmKgF
ipfs-bitswap getFromOutside QmQhz9yXh2HxrNyy9LosuVbpApEYsf6qV89ca6U8v1vL5b
ipfs-bitswap getFromOutside QmeszXodJVjAQyBikH2heYC7vMoQePQszXdg7LjvTP9MNQ
ipfs-bitswap getFromOutside QmcPYEZcUs1trvkDbpU7YKMmE1vHhWYukSu4e1ptocBnAY
ipfs-bitswap getFromOutside QmesityR3KUQSbxizobSEVrCQEwtp8tqTCi8uAv6iq41ph
ipfs-bitswap getFromOutside Qmdze91CeFM68STkh4WuB2PtUHf13eYGCGyoFsYezN5Pqy
ipfs-bitswap getFromOutside QmQExNEQFfHjHu1GxQqJWAE3QirDLAjf3GAXLGDdD9u9fP
ipfs-bitswap getFromOutside QmZoopANmKFKNMYzXkLMcUUsEXqEZM5JXoKgr3quLpXsJ3
ipfs-bitswap getFromOutside QmQHkU8BLDvsAe3U78FaT8q8dtajY2UoJuTjzshpjVogYT
ipfs-bitswap getFromOutside QmbCe2kSPPA4jpV6B9kweBpFrotHA4ktGyxVNSZDD79bt2
ipfs-bitswap getFromOutside QmcEFwkhm7Jjn2x35qcQQCgNsj6sWDkHXJ5o3VFFXQk46r
ipfs-bitswap received block QmbcpWEkchyeSc5FMkpVkQs6AD3a5nozR3SYy7oyvMFZbN
ipfs-bitswap received block QmfXApKEQiFpoZwCiEPiKG7r5PqUWey2HHRwHg7XvRrXrg
ipfs-bitswap received block QmaWGUpyGuVjqax1Kf3ZxzA9Ta2rgXUJyEs7uZJ7reSv9b
ipfs-bitswap received block QmZDdGHgy8oCNuMmNbS3BdEYysnqBJmeduqck3yrynRSWB
ipfs-bitswap received block QmdAr7yCgn8KZQr32KaxLwxHFuUbY2sQfqNKPfk494dCky
ipfs-bitswap received block Qmegd6yHtYP49eLRBq7VKH1SCrEKY9PSZZseaFXJEBniZv
ipfs-bitswap received block QmNWGfRSL9krg5swbjZZCofc9SBC7oZixJv6WKCDaLRSzv
ipfs-bitswap received block Qmay5VLWsYQwF1a4z7zB6Y8GGA2iiQTCNSGs7NUjimpDSn
ipfs-bitswap received block QmbbnxCX4rtC9My2K4B4ZhM2bHHRPQAXnvFeJyEnjUudjx
ipfs-bitswap received block QmPK8odxBVSKpKkzP3xdM9LyhLC7VcZgtJyqNmfeMdmKgF
ipfs-bitswap received block QmQhz9yXh2HxrNyy9LosuVbpApEYsf6qV89ca6U8v1vL5b
ipfs-bitswap received block QmeszXodJVjAQyBikH2heYC7vMoQePQszXdg7LjvTP9MNQ
ipfs-bitswap received block QmcPYEZcUs1trvkDbpU7YKMmE1vHhWYukSu4e1ptocBnAY
ipfs-bitswap received block QmesityR3KUQSbxizobSEVrCQEwtp8tqTCi8uAv6iq41ph
ipfs-bitswap received block Qmdze91CeFM68STkh4WuB2PtUHf13eYGCGyoFsYezN5Pqy
ipfs-bitswap received block QmQExNEQFfHjHu1GxQqJWAE3QirDLAjf3GAXLGDdD9u9fP
ipfs-bitswap received block QmZoopANmKFKNMYzXkLMcUUsEXqEZM5JXoKgr3quLpXsJ3
ipfs-bitswap received block QmQHkU8BLDvsAe3U78FaT8q8dtajY2UoJuTjzshpjVogYT
ipfs-bitswap received block QmbCe2kSPPA4jpV6B9kweBpFrotHA4ktGyxVNSZDD79bt2
ipfs-bitswap received block QmcEFwkhm7Jjn2x35qcQQCgNsj6sWDkHXJ5o3VFFXQk46r
Stream is receiving data: 4 seconds
done Here you can see that your code doesn't actually start receiving data until bitswap has received all the blocks in the links from the root block. After ipfs-inactive/js-ipfs-unixfs-exporter#13: $ rm -rf ~/.jsipfs && node slow-cat2.js
Instantiating IPFS node
ipld got block QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V
ipld got block QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y
ipld got block QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT
ipld got block QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7
ipld got block QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha
ipld got block QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB
ipld got block QmQ5vhrL7uv6tuoN9KeVBwd4PwfQkXdVVmDLUZuTNxqgvm
ipld got block QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs
ipld got block QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC
ipld got block QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te
ipld got block QmfGBRT6BbWJd7yUc2uYdaUZJBbnEFvTqehPFoSMQ6wgdr
ipld got block QmfGBRT6BbWJd7yUc2uYdaUZJBbnEFvTqehPFoSMQ6wgdr
ipld got block QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V
ipld got block QmegvLXxpVKiZ4b57Xs1syfBVRd8CbucVHAp7KpLQdGieC
ipld got block QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y
ipld got block QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7
ipld got block QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB
ipld got block QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha
ipld got block QmQ5vhrL7uv6tuoN9KeVBwd4PwfQkXdVVmDLUZuTNxqgvm
ipld got block QmciSU8hfpAXKjvK5YLUSwApomGSWN5gFbP4EpDAEzu2Te
ipld got block QmQN88TEidd3RY2u3dpib49fERTDfKtDpvxnvczATNsfKT
ipld got block QmYE7xo6NxbHEVEHej1yzxijYaNY51BaeKxjXxn6Ssa6Bs
ipld got block QmZ9ANfh6BMFoeinQU1WQ2BQrRea4UusEikQ1kupx3HtsY
ipld got block QmdEtks1KYQsrgJ8FXpP1vXygnVHSqnyFTKQ3wcWVd4D2y
ipld got block QmbxHkprr5qdLSK8EZWdBzKFzNXGoKrxb7A4PHX3eH6JPp
Swarm listening on /ip4/127.0.0.1/tcp/4002/ipfs/QmbWBysea6YL2hzPmE5FeDHVxaiHAX3rXYLTB9yjN7Ma2J
Swarm listening on /ip4/192.168.1.68/tcp/4002/ipfs/QmbWBysea6YL2hzPmE5FeDHVxaiHAX3rXYLTB9yjN7Ma2J
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/ipfs/QmbWBysea6YL2hzPmE5FeDHVxaiHAX3rXYLTB9yjN7Ma2J
ipld got block QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn
ipfs-unixfs-exporter resolved QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn
ipld got block QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn
IPFS node is ready
Waiting 15s...
Stream has been created, waiting for data....
ipfs-bitswap getFromOutside QmaFzTWvp9ktfeC7co1jMCvHQQ2uLpNbEEqdttEEyHVQS3
ipfs-bitswap received block QmaFzTWvp9ktfeC7co1jMCvHQQ2uLpNbEEqdttEEyHVQS3
ipld got block QmaFzTWvp9ktfeC7co1jMCvHQQ2uLpNbEEqdttEEyHVQS3
ipfs-unixfs-exporter resolved QmaFzTWvp9ktfeC7co1jMCvHQQ2uLpNbEEqdttEEyHVQS3
ipfs-bitswap getFromOutside QmT91fmjEBBbVBc774oiR3W8rTv1UZt7iUajRpF4Ri5wWg
ipfs-bitswap received block QmT91fmjEBBbVBc774oiR3W8rTv1UZt7iUajRpF4Ri5wWg
ipld got block QmT91fmjEBBbVBc774oiR3W8rTv1UZt7iUajRpF4Ri5wWg
ipfs-unixfs-exporter resolved QmT91fmjEBBbVBc774oiR3W8rTv1UZt7iUajRpF4Ri5wWg
js-ipfs collected GO� tT'+��mVڻݭ�ۢ3�A
ipfs-bitswap getFromOutside QmUyyM7CfmosHtKCY6PsAeU7dLsj4gL2iurQgtP17fvSaP
ipfs-bitswap received block QmUyyM7CfmosHtKCY6PsAeU7dLsj4gL2iurQgtP17fvSaP
ipld got block QmUyyM7CfmosHtKCY6PsAeU7dLsj4gL2iurQgtP17fvSaP
ipfs-bitswap getFromOutside QmbcpWEkchyeSc5FMkpVkQs6AD3a5nozR3SYy7oyvMFZbN
ipfs-bitswap getFromOutside QmfXApKEQiFpoZwCiEPiKG7r5PqUWey2HHRwHg7XvRrXrg
ipfs-bitswap getFromOutside QmaWGUpyGuVjqax1Kf3ZxzA9Ta2rgXUJyEs7uZJ7reSv9b
ipfs-bitswap getFromOutside QmZDdGHgy8oCNuMmNbS3BdEYysnqBJmeduqck3yrynRSWB
ipfs-bitswap getFromOutside QmdAr7yCgn8KZQr32KaxLwxHFuUbY2sQfqNKPfk494dCky
ipfs-bitswap getFromOutside Qmegd6yHtYP49eLRBq7VKH1SCrEKY9PSZZseaFXJEBniZv
ipfs-bitswap getFromOutside QmNWGfRSL9krg5swbjZZCofc9SBC7oZixJv6WKCDaLRSzv
ipfs-bitswap getFromOutside Qmay5VLWsYQwF1a4z7zB6Y8GGA2iiQTCNSGs7NUjimpDSn
ipfs-bitswap getFromOutside QmbbnxCX4rtC9My2K4B4ZhM2bHHRPQAXnvFeJyEnjUudjx
ipfs-bitswap getFromOutside QmPK8odxBVSKpKkzP3xdM9LyhLC7VcZgtJyqNmfeMdmKgF
ipfs-bitswap getFromOutside QmQhz9yXh2HxrNyy9LosuVbpApEYsf6qV89ca6U8v1vL5b
ipfs-bitswap getFromOutside QmeszXodJVjAQyBikH2heYC7vMoQePQszXdg7LjvTP9MNQ
ipfs-bitswap getFromOutside QmcPYEZcUs1trvkDbpU7YKMmE1vHhWYukSu4e1ptocBnAY
ipfs-bitswap getFromOutside QmesityR3KUQSbxizobSEVrCQEwtp8tqTCi8uAv6iq41ph
ipfs-bitswap getFromOutside Qmdze91CeFM68STkh4WuB2PtUHf13eYGCGyoFsYezN5Pqy
ipfs-bitswap getFromOutside QmQExNEQFfHjHu1GxQqJWAE3QirDLAjf3GAXLGDdD9u9fP
ipfs-bitswap getFromOutside QmZoopANmKFKNMYzXkLMcUUsEXqEZM5JXoKgr3quLpXsJ3
ipfs-bitswap getFromOutside QmQHkU8BLDvsAe3U78FaT8q8dtajY2UoJuTjzshpjVogYT
ipfs-bitswap getFromOutside QmbCe2kSPPA4jpV6B9kweBpFrotHA4ktGyxVNSZDD79bt2
ipfs-bitswap getFromOutside QmcEFwkhm7Jjn2x35qcQQCgNsj6sWDkHXJ5o3VFFXQk46r
ipfs-bitswap received block QmesityR3KUQSbxizobSEVrCQEwtp8tqTCi8uAv6iq41ph
ipld got block QmesityR3KUQSbxizobSEVrCQEwtp8tqTCi8uAv6iq41ph
ipfs-bitswap received block Qmay5VLWsYQwF1a4z7zB6Y8GGA2iiQTCNSGs7NUjimpDSn
ipld got block Qmay5VLWsYQwF1a4z7zB6Y8GGA2iiQTCNSGs7NUjimpDSn
ipfs-bitswap received block QmbcpWEkchyeSc5FMkpVkQs6AD3a5nozR3SYy7oyvMFZbN
ipld got block QmbcpWEkchyeSc5FMkpVkQs6AD3a5nozR3SYy7oyvMFZbN
Stream is receiving data: 2 seconds
ipfs-bitswap received block QmcEFwkhm7Jjn2x35qcQQCgNsj6sWDkHXJ5o3VFFXQk46r
ipld got block QmcEFwkhm7Jjn2x35qcQQCgNsj6sWDkHXJ5o3VFFXQk46r
ipfs-bitswap received block QmQhz9yXh2HxrNyy9LosuVbpApEYsf6qV89ca6U8v1vL5b
ipld got block QmQhz9yXh2HxrNyy9LosuVbpApEYsf6qV89ca6U8v1vL5b
ipfs-bitswap received block QmNWGfRSL9krg5swbjZZCofc9SBC7oZixJv6WKCDaLRSzv
ipld got block QmNWGfRSL9krg5swbjZZCofc9SBC7oZixJv6WKCDaLRSzv
ipfs-bitswap received block QmfXApKEQiFpoZwCiEPiKG7r5PqUWey2HHRwHg7XvRrXrg
ipld got block QmfXApKEQiFpoZwCiEPiKG7r5PqUWey2HHRwHg7XvRrXrg
ipfs-bitswap received block Qmdze91CeFM68STkh4WuB2PtUHf13eYGCGyoFsYezN5Pqy
ipld got block Qmdze91CeFM68STkh4WuB2PtUHf13eYGCGyoFsYezN5Pqy
ipfs-bitswap received block QmcPYEZcUs1trvkDbpU7YKMmE1vHhWYukSu4e1ptocBnAY
ipld got block QmcPYEZcUs1trvkDbpU7YKMmE1vHhWYukSu4e1ptocBnAY
ipfs-bitswap received block QmeszXodJVjAQyBikH2heYC7vMoQePQszXdg7LjvTP9MNQ
ipld got block QmeszXodJVjAQyBikH2heYC7vMoQePQszXdg7LjvTP9MNQ
ipfs-bitswap received block QmPK8odxBVSKpKkzP3xdM9LyhLC7VcZgtJyqNmfeMdmKgF
ipld got block QmPK8odxBVSKpKkzP3xdM9LyhLC7VcZgtJyqNmfeMdmKgF
ipfs-bitswap received block QmZDdGHgy8oCNuMmNbS3BdEYysnqBJmeduqck3yrynRSWB
ipld got block QmZDdGHgy8oCNuMmNbS3BdEYysnqBJmeduqck3yrynRSWB
ipfs-bitswap received block QmbCe2kSPPA4jpV6B9kweBpFrotHA4ktGyxVNSZDD79bt2
ipld got block QmbCe2kSPPA4jpV6B9kweBpFrotHA4ktGyxVNSZDD79bt2
ipfs-bitswap received block QmZoopANmKFKNMYzXkLMcUUsEXqEZM5JXoKgr3quLpXsJ3
ipld got block QmZoopANmKFKNMYzXkLMcUUsEXqEZM5JXoKgr3quLpXsJ3
ipfs-bitswap received block QmQExNEQFfHjHu1GxQqJWAE3QirDLAjf3GAXLGDdD9u9fP
ipld got block QmQExNEQFfHjHu1GxQqJWAE3QirDLAjf3GAXLGDdD9u9fP
ipfs-bitswap received block QmbbnxCX4rtC9My2K4B4ZhM2bHHRPQAXnvFeJyEnjUudjx
ipld got block QmbbnxCX4rtC9My2K4B4ZhM2bHHRPQAXnvFeJyEnjUudjx
ipfs-bitswap received block Qmegd6yHtYP49eLRBq7VKH1SCrEKY9PSZZseaFXJEBniZv
ipld got block Qmegd6yHtYP49eLRBq7VKH1SCrEKY9PSZZseaFXJEBniZv
ipfs-bitswap received block QmdAr7yCgn8KZQr32KaxLwxHFuUbY2sQfqNKPfk494dCky
ipld got block QmdAr7yCgn8KZQr32KaxLwxHFuUbY2sQfqNKPfk494dCky
ipfs-bitswap received block QmaWGUpyGuVjqax1Kf3ZxzA9Ta2rgXUJyEs7uZJ7reSv9b
ipld got block QmaWGUpyGuVjqax1Kf3ZxzA9Ta2rgXUJyEs7uZJ7reSv9b
ipfs-bitswap received block QmQHkU8BLDvsAe3U78FaT8q8dtajY2UoJuTjzshpjVogYT
ipld got block QmQHkU8BLDvsAe3U78FaT8q8dtajY2UoJuTjzshpjVogYT
done You can see that after the PR "Stream is receiving data: 2 seconds" appears mid way through the output, this is because it now can start emitting data before all blocks in the root node have been received by bitswap. Note I amended your example as follows: const IPFS = require('ipfs')
const pull = require('pull-stream')
const type = process.argv[2]
console.log('Instantiating IPFS node')
const node = new IPFS()
const hash = '/ipfs/QmaFzTWvp9ktfeC7co1jMCvHQQ2uLpNbEEqdttEEyHVQS3/2.mov'
const streamFunc = type === 'readable' ? node.catReadableStream : node.catPullStream
let dataEvent = false
node.on('ready', () => {
console.log('IPFS node is ready')
console.log('Waiting 15s...')
setTimeout(() => {
const readyTime = Math.floor(Date.now() / 1000)
const stream = streamFunc(hash, { offset: 0, length: 5000000 })
console.log('Stream has been created, waiting for data....')
const pullable = () => {
pull(
stream,
pull.through(() => {
if (!dataEvent) {
dataEvent = true
const dataTime = Math.floor(Date.now() / 1000)
console.log('Stream is receiving data: ' + Math.floor(dataTime - readyTime) + ' seconds')
}
}),
pull.onEnd((err) => {
if (err) throw err
console.log('done')
node.stop()
})
)
}
const readable = () => {
stream.on('data', (block) => {
if (!dataEvent) {
dataEvent = true
const dataTime = Math.floor(Date.now() / 1000)
console.log('Stream is receiving data: ' + Math.floor(dataTime - readyTime) + ' seconds')
}
})
stream.on('end', () => node.stop())
}
type === 'readable' ? readable() : pullable()
}, 15000)
})
node.on('error', console.error) |
Update - it looks like we're waiting 10s before connecting to the bootstrap nodes which would appear to be the cause of the delay. |
Previously we had to wait 10s (by default) **before** initial peer discovery, since the module uses an interval to re-emit discovered peers every 10s. This PR refactors `start` to do an initial discovery of the boostrap peers immediately after it has started (i.e. after the callback has been called). This addresses the problem where a call to `cat`/`get`/others immediately after the IPFS `ready` event would take at minimum 10s to get content stored on the preload nodes due to the initial delay in discovery. fixes #85 resolves ipfs/js-ipfs#1706 License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
Previously we had to wait 10s (by default) **before** initial peer discovery, since the module uses an interval to re-emit discovered peers every 10s. This PR refactors `start` to do an initial discovery of the boostrap peers immediately after it has started (i.e. after the callback has been called). This addresses the problem where a call to `cat`/`get`/others immediately after the IPFS `ready` event would take at minimum 10s to get content stored on the preload nodes due to the initial delay in discovery. fixes #85 resolves ipfs/js-ipfs#1706 License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
Version:
0.33.1
Platform:
Mac OS X 10.12.6
Chrome: Version 70.0.3538.77 (Official Build) (64-bit)
FireFox: 63.0.1 (64-bit)
Subsystem:
?
Type:
Bug (maybe Enhancement?)
Severity:
High
Description:
When using js-ipfs as a client in a browser, executing
node.files.catReadableStream
starts the blocks streaming into the websocket connections immediately but it takes sometimes over 10 seconds before the stream triggers the firstdata
event.Basically, more than 10 seconds of lag between these two lines:
But as soon as the first line is executed, I see blocks coming across the websocket instantly. Is this by design or is there a problem here?
Steps to reproduce the error:
catReadableStream
on any hash (larger files work better as the process is really over before you know what happened on smaller files)The text was updated successfully, but these errors were encountered: