Share via

Is there one way to decrease the frequency of invoking ProgressReceiver for BlobAsyncClient upload file

Anonymous
2022-02-14T13:28:48.793+00:00

I defined ParallelTransferOptions as below, to get the upload progress for BlobAsyncClient. I found function OnProgressReceived() was called about 30 times within 1 second. Is there one way to decrease the frequency to call it? Thanks a lot for your help.

BlobAsyncClient client = new BlobClientBuilder()
.endpoint(url)
.blobName("300.tar.gz")
.buildAsyncClient();

ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions()
.setBlockSizeLong(blockSize)
.setMaxConcurrency(maxConcurrency)
.setProgressReceiver(bytesTransferred -> OnProgressReceived(bytesTransferred));

client.uploadFromFile(filePath, parallelTransferOptions, headers, null, AccessTier.HOT, null)
.doOnSuccess(success -> OnSuccess())
.doOnError(throwable -> OnError(throwable.getMessage()))
.subscribe();

Azure Blob Storage
Azure Blob Storage

An Azure service that stores unstructured data in the cloud as blobs.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Michael Taylor 61,221 Reputation points
    2022-02-14T16:06:18.443+00:00

    In theory up the block size. The block size determines how big a block is transferred at a time. Each block triggers a progress call I believe. So if you are uploading a 100K file and you set the block size at 25K then you'd expect 4 calls for that file. If you want fewer calls then increase the block size. Of course if you have a fast network connection then you will get more progress notifications per second because of the faster connection speed.

    Also be aware that the concurrency kicks in as well. So if you are dealing with that 100K file with a block size of 10K and you have concurrency set to 2 then you would expect 10 calls but those are happening across 2 "threads" so you could see 2 calls each time. The higher the concurrency and smaller the block size then the more calls you'll be seeing at once.

    Finally, if you are doing something expensive during the progress handler then you could also consider batching that as well. For example if you are updating a UI each time the handler is called then you could use some heuristics to determine when to update the UI instead (e.g. only every 2% or something).

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.