Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

Performance tuning for uploads and downloads with Java

Feedback

In this article

When an application transfers data using the Azure Storage client library for Java, there are several factors that can affect speed, memory usage, and even the success or failure of the request. To maximize performance and reliability for data transfers, it's important to be proactive in configuring client library transfer options based on the environment your app runs in.

This article walks through several considerations for tuning data transfer options. When properly tuned, the client library can efficiently distribute data across multiple requests, which can result in improved operation speed, memory usage, and network stability.

Performance tuning for uploads

Properly tuning data transfer options is key to reliable performance for uploads. Storage transfers are partitioned into several subtransfers based on the values of these arguments. The maximum supported transfer size varies by operation and service version, so be sure to check the documentation to determine the limits. For more information on transfer size limits for Blob storage, seeScale targets for Blob storage.

Set transfer options for uploads

You can configure the values inParallelTransferOptions to improve performance for data transfer operations. The following values can be tuned for uploads based on the needs of your app:

  • maxSingleUploadSize: The maximum blob size in bytes for a single request upload.
  • blockSize: The maximum block size to transfer for each request.
  • maxConcurrency: The maximum number of parallel requests issued at any given time as a part of a single parallel transfer.

Note

The client libraries will use defaults for each data transfer option, if not provided. These defaults are typically performant in a data center environment, but not likely to be suitable for home consumer environments. Poorly tuned data transfer options can result in excessively long operations and even request timeouts. It's best to be proactive in testing these values, and tuning them based on the needs of your application and environment.

maxSingleUploadSize

ThemaxSingleUploadSize value is the maximum blob size in bytes for a single request upload. This value can be set using the following method:

If the size of the data is less than or equal tomaxSingleUploadSize, the blob is uploaded with a singlePut Blob request. If the blob size is greater thanmaxSingleUploadSize, or if the blob size is unknown, the blob is uploaded in chunks using a series ofPut Block calls followed byPut Block List.

It's important to note that the value you specify forblockSizedoes not limit the value that you define formaxSingleUploadSize. ThemaxSingleUploadSize argument defines a separate size limitation for a request to perform the entire operation at once, with no subtransfers. It's often the case that you wantmaxSingleUploadSize to beat least as large as the value you define forblockSize, if not larger. Depending on the size of the data transfer, this approach can be more performant, as the transfer is completed with a single request and avoids the overhead of multiple requests.

If you're unsure of what value is best for your situation, a safe option is to setmaxSingleUploadSize to the same value used forblockSize.

blockSize

TheblockSize value is the maximum length of a transfer in bytes when uploading a block blob in chunks. This value can be set using the following method:

TheblockSize value is the maximum length of a transfer in bytes when uploading a block blob in chunks. As mentioned earlier, this valuedoes not limitmaxSingleUploadSize, which can be larger thanblockSize.

To keep data moving efficiently, the client libraries may not always reach theblockSize value for every transfer. Depending on the operation, the maximum supported value for transfer size can vary. For more information on transfer size limits for Blob storage, see the chart inScale targets for Blob storage.

maxConcurrency

ThemaxConcurrency value is the maximum number of parallel requests issued at any given time as a part of a single parallel transfer. This value can be set using the following method:

Code example

Make sure you have the followingimport directive to useParallelTransferOptions for an upload:

import com.azure.storage.blob.models.*;

The following code example shows how to set values forParallelTransferOptions and include the options as part of aBlobUploadFromFileOptions instance. If you're not uploading from a file, you can set similar options usingBlobParallelUploadOptions. The values provided in this sample aren't intended to be a recommendation. To properly tune these values, you need to consider the specific needs of your app.

ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions()        .setBlockSizeLong((long) (4 * 1024 * 1024)) // 4 MiB block size        .setMaxConcurrency(2)        .setMaxSingleUploadSizeLong((long) 8 * 1024 * 1024); // 8 MiB max size for single request uploadBlobUploadFromFileOptions options = new BlobUploadFromFileOptions("<localFilePath>");options.setParallelTransferOptions(parallelTransferOptions);Response<BlockBlobItem> blockBlob = blobClient.uploadFromFileWithResponse(options, null, null);

In this example, we set the maximum number of parallel transfer workers to 2 using thesetMaxConcurrency method. We also setmaxSingleUploadSize to 8 MiB using thesetMaxSingleUploadSizeLong method. If the blob size is smaller than 8 MiB, only a single request is necessary to complete the upload operation. If the blob size is larger than 8 MiB, the blob is uploaded in chunks with a maximum chunk size of 4 MiB, which we set using thesetBlockSizeLong method.

Performance considerations for uploads

During an upload, the Storage client libraries split a given upload stream into multiple subuploads based on the configuration options defined byParallelTransferOptions. Each subupload has its own dedicated call to the REST operation. For aBlobClient object, this operation isPut Block. The Storage client library manages these REST operations in parallel (depending on transfer options) to complete the full upload.

Note

Block blobs have a maximum block count of 50,000 blocks. The maximum size of your block blob, then, is 50,000 timesblock_size.

Buffering during uploads

The Storage REST layer doesn’t support picking up a REST upload operation where you left off; individual transfers are either completed or lost. To ensure resiliency for stream uploads, the Storage client libraries buffer data for each individual REST call before starting the upload. In addition to network speed limitations, this buffering behavior is a reason to consider a smaller value forblockSize, even when uploading in sequence. Decreasing the value ofblockSize decreases the maximum amount of data that is buffered on each request and each retry of a failed request. If you're experiencing frequent timeouts during data transfers of a certain size, reducing the value ofblockSize reduces the buffering time, and may result in better performance.

Performance tuning for downloads

Properly tuning data transfer options is key to reliable performance for downloads. Storage transfers are partitioned into several subtransfers based on the values defined inParallelTransferOptions.

Set transfer options for downloads

The following values can be tuned for downloads based on the needs of your app:

  • blockSize: The maximum block size to transfer for each request. You can set this value by using thesetBlockSizeLong method.
  • maxConcurrency: The maximum number of parallel requests issued at any given time as a part of a single parallel transfer. You can set this value by using thesetMaxConcurrency method.

Code example

Make sure you have the followingimport directive to useParallelTransferOptions for a download:

import com.azure.storage.common.*;

The following code example shows how to set values forParallelTransferOptions and include the options as part of aBlobDownloadToFileOptions instance.

ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions()        .setBlockSizeLong((long) (4 * 1024 * 1024)) // 4 MiB block size        .setMaxConcurrency(2);BlobDownloadToFileOptions options = new BlobDownloadToFileOptions("<localFilePath>");options.setParallelTransferOptions(parallelTransferOptions);blobClient.downloadToFileWithResponse(options, null, null);

Performance considerations for downloads

During a download, the Storage client libraries split a given download request into multiple subdownloads based on the configuration options defined byParallelTransferOptions. Each subdownload has its own dedicated call to the REST operation. Depending on transfer options, the client libraries manage these REST operations in parallel to complete the full download.

Next steps


Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

  • Last updated on

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?