Skip to content

Commit 27a44fd

Browse files
Merge pull request #248033 from pauljewellmsft/pauljewell-perf-java
Add perf tuning article to Java dev guide
2 parents a5d878d + 27122df commit 27a44fd

6 files changed

+163
-11
lines changed

articles/storage/blobs/TOC.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,10 @@ items:
747747
href: sas-service-create-java.md
748748
- name: Create an account SAS
749749
href: ../common/storage-account-sas-create-java.md?toc=/azure/storage/blobs/toc.json&bc=/azure/storage/blobs/breadcrumb/toc.json
750+
- name: Client library configuration options
751+
items:
752+
- name: Performance tuning for uploads and downloads
753+
href: storage-blobs-tune-upload-download-java.md
750754
- name: JavaScript
751755
items:
752756
- name: Get started

articles/storage/blobs/storage-blob-download-java.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ You can configure values in [ParallelTransferOptions](/java/api/com.azure.storag
6868
- `blockSize`: The maximum block size to transfer for each request. You can set this value by using the [setBlockSizeLong](/java/api/com.azure.storage.common.paralleltransferoptions#com-azure-storage-common-paralleltransferoptions-setblocksizelong(java-lang-long)) method.
6969
- `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 the [setMaxConcurrency](/java/api/com.azure.storage.common.paralleltransferoptions#com-azure-storage-common-paralleltransferoptions-setmaxconcurrency(java-lang-integer)) method.
7070

71-
Add the following `import` directive to your file to use `ParallelTransferOptions`:
71+
Add the following `import` directive to your file to use `ParallelTransferOptions` for a download:
7272

7373
```java
7474
import com.azure.storage.common.*;
@@ -78,6 +78,8 @@ The following code example shows how to set values for `ParallelTransferOptions`
7878

7979
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobDownload.java" id="Snippet_DownloadBlobWithTransferOptions":::
8080

81+
To learn more about tuning data transfer options, see [Performance tuning for uploads and downloads with Java](storage-blobs-tune-upload-download-java.md).
82+
8183
## Resources
8284

8385
To learn more about how to download blobs using the Azure Blob Storage client library for Java, see the following resources.

articles/storage/blobs/storage-blob-upload-java.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,24 @@ You can define client library configuration options when uploading a blob. These
6262

6363
### Specify data transfer options on upload
6464

65-
You can configure values in [ParallelTransferOptions](/java/api/com.azure.storage.blob.models.paralleltransferoptions) to improve performance for data transfer operations. The following table lists the methods you can use to set these options, along with a description:
65+
You can configure values in [ParallelTransferOptions](/java/api/com.azure.storage.blob.models.paralleltransferoptions) to improve performance for data transfer operations. The following values can be tuned for uploads based on the needs of your app:
6666

67-
| Method | Description |
68-
| --- | --- |
69-
| [`setBlockSizeLong(Long blockSize)`](/java/api/com.azure.storage.blob.models.paralleltransferoptions#com-azure-storage-blob-models-paralleltransferoptions-setblocksizelong(java-lang-long)) | Sets the block size to transfer for each request. For uploads, the parameter `blockSize` is the size of each block that's staged. This value also determines the number of requests that need to be made. If `blockSize` is large, the upload makes fewer network calls, but each individual call sends more data. |
70-
| [`setMaxConcurrency(Integer maxConcurrency)`](/java/api/com.azure.storage.blob.models.paralleltransferoptions#com-azure-storage-blob-models-paralleltransferoptions-setmaxconcurrency(java-lang-integer)) | The parameter `maxConcurrency` is the maximum number of parallel requests that are issued at any given time as a part of a single parallel transfer. This value applies per API call. |
71-
| [`setMaxSingleUploadSizeLong(Long maxSingleUploadSize)`](/java/api/com.azure.storage.blob.models.paralleltransferoptions#com-azure-storage-blob-models-paralleltransferoptions-setmaxsingleuploadsizelong(java-lang-long)) | If the size of the data is less than or equal to this value, it's uploaded in a single put rather than broken up into chunks. If the data is uploaded in a single shot, the block size is ignored. |
67+
- `blockSize`: The maximum block size to transfer for each request. You can set this value by using the [setBlockSizeLong](/java/api/com.azure.storage.blob.models.paralleltransferoptions#com-azure-storage-blob-models-paralleltransferoptions-setblocksizelong(java-lang-long)) method.
68+
- `maxSingleUploadSize`: If the size of the data is less than or equal to this value, it's uploaded in a single put rather than broken up into chunks. If the data is uploaded in a single shot, the block size is ignored. You can set this value by using the [setMaxSingleUploadSizeLong](/java/api/com.azure.storage.blob.models.paralleltransferoptions#com-azure-storage-blob-models-paralleltransferoptions-setmaxsingleuploadsizelong(java-lang-long)) method.
69+
- `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 the [setMaxConcurrency](/java/api/com.azure.storage.blob.models.paralleltransferoptions#com-azure-storage-blob-models-paralleltransferoptions-setmaxconcurrency(java-lang-integer)) method.
70+
71+
Make sure you have the following `import` directive to use `ParallelTransferOptions` for an upload:
72+
73+
```java
74+
import com.azure.storage.blob.models.*;
75+
```
7276

7377
The following code example shows how to set values for [ParallelTransferOptions](/java/api/com.azure.storage.blob.models.paralleltransferoptions) and include the options as part of a [BlobUploadFromFileOptions](/java/api/com.azure.storage.blob.options.blobuploadfromfileoptions) instance. 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.
7478

7579
:::code language="java" source="~/azure-storage-snippets/blobs/howto/Java/blob-devguide/blob-devguide-blobs/src/main/java/com/blobs/devguide/blobs/BlobUpload.java" id="Snippet_UploadBlobWithTransferOptions":::
7680

81+
To learn more about tuning data transfer options, see [Performance tuning for uploads and downloads with Java](storage-blobs-tune-upload-download-java.md).
82+
7783
### Upload a block blob with index tags
7884

7985
Blob index tags categorize data in your storage account using key-value tag attributes. These tags are automatically indexed and exposed as a searchable multi-dimensional index to easily find data.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---
2+
title: Performance tuning for uploads and downloads with Azure Storage client library for Java
3+
titleSuffix: Azure Storage
4+
description: Learn how to tune your uploads and downloads for better performance with Azure Storage client library for Java.
5+
services: storage
6+
author: pauljewellmsft
7+
ms.author: pauljewell
8+
ms.service: azure-blob-storage
9+
ms.topic: how-to
10+
ms.date: 09/22/2023
11+
ms.devlang: java
12+
ms.custom: devx-track-java, devguide-java, devx-track-java
13+
---
14+
15+
# Performance tuning for uploads and downloads with Java
16+
17+
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.
18+
19+
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.
20+
21+
## Performance tuning for uploads
22+
23+
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, see [Scale targets for Blob storage](scalability-targets.md#scale-targets-for-blob-storage).
24+
25+
### Set transfer options for uploads
26+
27+
You can configure the values in [ParallelTransferOptions](/java/api/com.azure.storage.blob.models.paralleltransferoptions) to improve performance for data transfer operations. The following values can be tuned for uploads based on the needs of your app:
28+
29+
- [maxSingleUploadSize](#maxsingleuploadsize): The maximum blob size in bytes for a single request upload.
30+
- [blockSize](#blocksize): The maximum block size to transfer for each request.
31+
- [maxConcurrency](#maxconcurrency): The maximum number of parallel requests issued at any given time as a part of a single parallel transfer.
32+
33+
> [!NOTE]
34+
> 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.
35+
36+
#### maxSingleUploadSize
37+
38+
The `maxSingleUploadSize` value is the maximum blob size in bytes for a single request upload. This value can be set using the following method:
39+
40+
- [`setMaxSingleUploadSizeLong(Long maxSingleUploadSize)`](/java/api/com.azure.storage.blob.models.paralleltransferoptions#com-azure-storage-blob-models-paralleltransferoptions-setmaxsingleuploadsizelong(java-lang-long))
41+
42+
If the size of the data is less than or equal to `maxSingleUploadSize`, the blob is uploaded with a single [Put Blob](/rest/api/storageservices/put-blob) request. If the blob size is greater than `maxSingleUploadSize`, or if the blob size is unknown, the blob is uploaded in chunks using a series of [Put Block](/rest/api/storageservices/put-block) calls followed by [Put Block List](/rest/api/storageservices/put-block-list).
43+
44+
It's important to note that the value you specify for `blockSize` *does not* limit the value that you define for `maxSingleUploadSize`. The `maxSingleUploadSize` 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 want `maxSingleUploadSize` to be *at least* as large as the value you define for `blockSize`, 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.
45+
46+
If you're unsure of what value is best for your situation, a safe option is to set `maxSingleUploadSize` to the same value used for `blockSize`.
47+
48+
#### blockSize
49+
50+
The `blockSize` 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:
51+
52+
- [`setBlockSizeLong(Long blockSize)`](/java/api/com.azure.storage.blob.models.paralleltransferoptions#com-azure-storage-blob-models-paralleltransferoptions-setblocksizelong(java-lang-long))
53+
54+
The `blockSize` value is the maximum length of a transfer in bytes when uploading a block blob in chunks. As mentioned earlier, this value *does not* limit `maxSingleUploadSize`, which can be larger than `blockSize`.
55+
56+
To keep data moving efficiently, the client libraries may not always reach the `blockSize` 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 in [Scale targets for Blob storage](scalability-targets.md#scale-targets-for-blob-storage).
57+
58+
#### maxConcurrency
59+
60+
The `maxConcurrency` 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:
61+
62+
- [`setMaxConcurrency(Integer maxConcurrency)`](/java/api/com.azure.storage.blob.models.paralleltransferoptions#com-azure-storage-blob-models-paralleltransferoptions-setmaxconcurrency(java-lang-integer))
63+
64+
#### Code example
65+
66+
Make sure you have the following `import` directive to use `ParallelTransferOptions` for an upload:
67+
68+
```java
69+
import com.azure.storage.blob.models.*;
70+
```
71+
72+
The following code example shows how to set values for [ParallelTransferOptions](/java/api/com.azure.storage.blob.models.paralleltransferoptions) and include the options as part of a [BlobUploadFromFileOptions](/java/api/com.azure.storage.blob.options.blobuploadfromfileoptions) instance. If you're not uploading from a file, you can set similar options using [BlobParallelUploadOptions](/java/api/com.azure.storage.blob.options.blobparalleluploadoptions). 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.
73+
74+
```java
75+
ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions()
76+
.setBlockSizeLong((long) (4 * 1024 * 1024)) // 4 MiB block size
77+
.setMaxConcurrency(2)
78+
.setMaxSingleUploadSizeLong((long) 8 * 1024 * 1024); // 8 MiB max size for single request upload
79+
80+
BlobUploadFromFileOptions options = new BlobUploadFromFileOptions("<localFilePath>");
81+
options.setParallelTransferOptions(parallelTransferOptions);
82+
83+
Response<BlockBlobItem> blockBlob = blobClient.uploadFromFileWithResponse(options, null, null);
84+
```
85+
86+
In this example, we set the maximum number of parallel transfer workers to 2 using the `setMaxConcurrency` method. We also set `maxSingleUploadSize` to 8 MiB using the `setMaxSingleUploadSizeLong` 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 the `setBlockSizeLong` method.
87+
88+
### Performance considerations for uploads
89+
90+
During an upload, the Storage client libraries split a given upload stream into multiple subuploads based on the configuration options defined by `ParallelTransferOptions`. Each subupload has its own dedicated call to the REST operation. For a `BlobClient` object, this operation is [Put Block](/rest/api/storageservices/put-block). The Storage client library manages these REST operations in parallel (depending on transfer options) to complete the full upload.
91+
92+
> [!NOTE]
93+
> Block blobs have a maximum block count of 50,000 blocks. The maximum size of your block blob, then, is 50,000 times `block_size`.
94+
95+
#### Buffering during uploads
96+
97+
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 for `blockSize`, even when uploading in sequence. Decreasing the value of `blockSize` 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 of `blockSize` reduces the buffering time, and may result in better performance.
98+
99+
## Performance tuning for downloads
100+
101+
Properly tuning data transfer options is key to reliable performance for downloads. Storage transfers are partitioned into several subtransfers based on the values defined in `ParallelTransferOptions`.
102+
103+
### Set transfer options for downloads
104+
105+
The following values can be tuned for downloads based on the needs of your app:
106+
107+
- `blockSize`: The maximum block size to transfer for each request. You can set this value by using the [setBlockSizeLong](/java/api/com.azure.storage.common.paralleltransferoptions#com-azure-storage-common-paralleltransferoptions-setblocksizelong(java-lang-long)) method.
108+
- `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 the [setMaxConcurrency](/java/api/com.azure.storage.common.paralleltransferoptions#com-azure-storage-common-paralleltransferoptions-setmaxconcurrency(java-lang-integer)) method.
109+
110+
#### Code example
111+
112+
Make sure you have the following `import` directive to use `ParallelTransferOptions` for a download:
113+
114+
```java
115+
import com.azure.storage.common.*;
116+
```
117+
118+
The following code example shows how to set values for [ParallelTransferOptions](/java/api/com.azure.storage.common.paralleltransferoptions) and include the options as part of a [BlobDownloadToFileOptions](/java/api/com.azure.storage.blob.options.blobdownloadtofileoptions) instance.
119+
120+
```java
121+
ParallelTransferOptions parallelTransferOptions = new ParallelTransferOptions()
122+
.setBlockSizeLong((long) (4 * 1024 * 1024)) // 4 MiB block size
123+
.setMaxConcurrency(2);
124+
125+
BlobDownloadToFileOptions options = new BlobDownloadToFileOptions("<localFilePath>");
126+
options.setParallelTransferOptions(parallelTransferOptions);
127+
128+
blobClient.downloadToFileWithResponse(options, null, null);
129+
```
130+
131+
### Performance considerations for downloads
132+
133+
During a download, the Storage client libraries split a given download request into multiple subdownloads based on the configuration options defined by `ParallelTransferOptions`. 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.
134+
135+
## Next steps
136+
137+
- To understand more about factors that can influence performance for Azure Storage operations, see [Latency in Blob storage](storage-blobs-latency.md).
138+
- To see a list of design considerations to optimize performance for apps using Blob storage, see [Performance and scalability checklist for Blob storage](storage-performance-checklist.md).

articles/storage/blobs/storage-blobs-tune-upload-download-python.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
2-
title: Performance tuning for uploads and downloads with Azure Storage client library for Python - Azure Storage
2+
title: Performance tuning for uploads and downloads with Azure Storage client library for Python
3+
titleSuffix: Azure Storage
34
description: Learn how to tune your uploads and downloads for better performance with Azure Storage client library for Python.
45
services: storage
56
author: pauljewellmsft
@@ -11,7 +12,7 @@ ms.devlang: python
1112
ms.custom: devx-track-python, devguide-python, devx-track-python
1213
---
1314

14-
# Performance tuning for uploads and downloads with the Azure Storage client library for Python
15+
# Performance tuning for uploads and downloads with Python
1516

1617
When an application transfers data using the Azure Storage client library for Python, 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.
1718

articles/storage/blobs/storage-blobs-tune-upload-download.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
2-
title: Performance tuning for uploads and downloads with Azure Storage client library for .NET - Azure Storage
2+
title: Performance tuning for uploads and downloads with Azure Storage client library for .NET
3+
titleSuffix: Azure Storage
34
description: Learn how to tune your uploads and downloads for better performance with Azure Storage client library for .NET.
45
services: storage
56
author: pauljewellmsft
@@ -11,7 +12,7 @@ ms.devlang: csharp
1112
ms.custom: devx-track-csharp, devguide-csharp, devx-track-dotnet
1213
---
1314

14-
# Performance tuning for uploads and downloads with the Azure Storage client library for .NET
15+
# Performance tuning for uploads and downloads with .NET
1516

1617
When an application transfers data using the Azure Storage client library for .NET, 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.
1718

0 commit comments

Comments
 (0)