tus-js-client icon indicating copy to clipboard operation
tus-js-client copied to clipboard

uploading large file 3GB or more as readablestream consume huge amount of memory.

Open Guling85 opened this issue 2 years ago • 3 comments

Im trying to upload a large file around 3GB with TUS client. It seems to me that TUS client doesnt use readablestream as intended because the memory usage is huge. The memory usage of chrome is like 2.5GB for 3 GB file.

here is my code.

 const file = $event.target.files[0];

      const upload = new Upload(file.stream().getReader(), {
        endpoint: "https://localhost:8443/upload/file",
        retryDelays: [0, 3000, 6000, 12000, 24000],
        chunkSize: 6553600,
        uploadLengthDeferred: true,
        metadata: {
          uuid: result[0].uploadId,
          order: chunkOrder.toString()
        },
        //chunkSize: 1048576,
        onBeforeRequest: (req) => {
          const xhr = req.getUnderlyingObject();
          xhr.withCredentials = false;
        },
        onError: async (error) => {
          console.log(error);

        },
        onProgress: function (bytesUploaded, bytesTotal) {
          let percentage = Math.ceil(bytesUploaded / bytesTotal * 100);

          console.log(bytesUploaded, bytesTotal, percentage + "%")
        },
        onSuccess: async () => {
          console.log('Upload success');
        }
      });

      upload.start();

Im a doing this wrong?

Because when using "file" instead of "file.stream()" works fine. The reason i dont wanna use "file" is because im gonna make a custom ReadableStream that modifies the data and upload it as a stream.

Guling85 avatar May 18 '22 11:05 Guling85

Thank you for this report. Does the memory consumption also grow in Firefox or browsers other than Chrome?

Acconut avatar May 23 '22 12:05 Acconut

Hi same in Firefox and edge.

Guling85 avatar May 25 '22 12:05 Guling85

Thanks, I will look into this when I have the time.

Acconut avatar May 30 '22 12:05 Acconut

Hello, any update on this?

ISnowFoxI avatar Sep 08 '23 18:09 ISnowFoxI

I tested a similar setup as @Guling85 described:

new Upload(file.stream().getReader(), {
        chunkSize: 6553600,
        uploadLengthDeferred: true,

However, I did not find any signs of a memory leak or excessive memory usage in general when uploading a 1GB file. In Chrome, the heap size was around 17MB, while Firefox only reported a 3MB heap (which seems a bit odd given that we configured a buffer of 6553600 bytes).

image

image

@ISnowFoxI Are you experiencing memory issues with tus-js-client in the browser? If not, I will close this issue. Since it was originally opened, we also reworked parts of the client for handling stream resource. So it is possible that there was an issue in older versions.

Acconut avatar Oct 17 '23 14:10 Acconut

@Acconut No, I was using it on react native (Ios and Android), and it seems like it was because of Blob, that said, I am still not sure what the issue was.

ISnowFoxI avatar Oct 17 '23 14:10 ISnowFoxI

Ok, feel free to open another issues if you experience issues with tus-js-client on React Native again. I will close this ticket because the original problems is not present anymore.

Acconut avatar Oct 18 '23 06:10 Acconut