question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stream write is slow and laggy

See original GitHub issue

Support plan

  • Which support plan is this issue covered by? Community
  • Currently blocking your project/work? no
  • Affecting a production system? no

Context

  • Node.js version: v16.17.0
  • Release Line of Formidable: Current
  • Formidable exact version: 3.2.4
  • Environment (node, browser, native, OS): node, browser
  • Used with (popular names of modules): Koa, koa-body

What are you trying to achieve or the steps to reproduce?

I’m trying to upload files directly to oracle cloud object storage. I use their API with npm package and fileWriteStreamHandler feature of formidable. When I upload a file, the upload from broweser perspective is terribly slow and not responsive to changes.

On browser side I’m checking upload progress by event

xhr.upload.onprogress = e => {
        this._uploadedSize = parseFloat(e.loaded);
        this._changed();
};

But this event is not often called and oftentimes the upload seems like it’s stuck. It gets stuck on some percentage, then after like a minute it jumps to different percentage and gets stuck again. Direct upload to oracle cloud from my computer is fast.

On server side I have a class which is basically adapter and this is the important code:

class OracleStorageDriver {
        // ...
        get formidable() {
                if (this.localTemp) {
                        return { uploadDir: this.tempDir };
                }
                const fileWriteStreamHandler = file => {
                        const object = tempDir + file.newFilename;
                        return this.createWriteStream(object);
                };
                return { fileWriteStreamHandler };
        }
        createWriteStream(path) {
                let uploadId;
                let partNum = 0;
                const partsToCommit = [];
                const { client } = this;

                const construct = done => {
                        const createMultipartUploadDetails = { object: path };
                        const requestCreate = this.cleanRequest({ createMultipartUploadDetails });
                        client.createMultipartUpload(requestCreate).then(response => {
                                uploadId = response.multipartUpload.uploadId;
                                done();
                        });
                };
                const write = (chunk, encoding, done) => {
                        // In debugger, breakpoint here is hitted oftentimes and quick
                        const uploadPartRequest = this.request(path, {
                                uploadId,
                                uploadPartNum: ++partNum,
                                contentLength: chunk.length,
                                uploadPartBody: chunk,
                        });
                        client.uploadPart(uploadPartRequest).then(response => {
                                partsToCommit.push({ partNum, etag: response.eTag });
                                done(); // This place is also often and quickly hit with breakpoint
                        });
                };
                const final = done => {
                        const commitMultipartUploadDetails = { partsToCommit };
                        const commitMultipartUploadRequest = this.request(path, {
                                uploadId,
                                commitMultipartUploadDetails,
                        });
                        client.commitMultipartUpload(commitMultipartUploadRequest).then(() => done());
                };
                const destroy = (err, done) => {
                        const abortMultipartUploadRequest = this.request(path, { uploadId });
                        client.abortMultipartUpload(abortMultipartUploadRequest).then(() => done());
                        throw err;
                };
                const stream = new Writable({ construct, write, destroy, final });
                return stream;
        }
        // ...
}

this.localTemp is variable from configuration, which switches between local storage of temporary files and uploading file directly from form to cloud storage. When I use local sotrage, everything works good and fast. With stream write, it’s slow. But write and done() in write are fired often and fast.

What was the result you got?

Slow and laggy upload with fileWriteStreamHandler

What result did you expect?

Approximately same speed/responsivenes as uploading when using local temp storage or as uploading directly to oracle cloud.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
GrosSacASaccommented, Oct 12, 2022

Also oracle API is AWS S3 compliant

Do it like the s3 example with a passtrough stream https://github.com/node-formidable/formidable/blob/master/examples/store-files-on-s3.js

0reactions
mariusrakcommented, Oct 11, 2022

As I said, those http requests are fast. And it is according to oracle documentation. So that is not the problem. Also oracle API is AWS S3 compliant. So how do you imagine utilizing fileWriteStreamHandler if not the way I’m using it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[SOLVED] OBS Lagging Issues | (Stream & Record)
1. Stop other bandwidth-intensive activities. Bandwidth hogging applications will slow down your network speed and trigger latency issues. Make ...
Read more >
8 Useful Tips to Speed Up a Slow Streaming Service
Frustrated by slow video streams that constantly buffer? Try these tips to help speed up your streaming services.
Read more >
How to Fix Input Lag and Slow Performance in Google Chrome
Fixing Input Lag and Slow Chrome Performance on Windows 7 · Pop open the Settings menu (click the icon in the top right...
Read more >
OpenCV real time streaming video capture is slow. How to ...
I'd like to set up an opencv system to process either HLS streams or RMTP streams, however, I am running into a strange...
Read more >
Throughput is Too Slow - Amazon Kinesis Data Analytics
There can be many causes for slow application throughput. If your application is not keeping up with input, check the following: If throughput...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found