Skip to content

Commit 8b52580

Browse files
committed
Decrease default maximum payload size to 10MiB
The previous setting 10GiB causes a growing memory usage since a buffer of the upload size will be allocated. This causes OOM exceptions on mobile phones (see tus/tus-android-client#22).
1 parent aa7b3b2 commit 8b52580

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/main/java/io/tus/java/client/TusUploader.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class TusUploader {
2525
private long offset;
2626
private TusClient client;
2727
private byte[] buffer;
28-
private int requestPayloadSize = 1024 * 1024 * 1024;
28+
private int requestPayloadSize = 10 * 1024 * 1024;
2929
private int bytesRemainingForRequest;
3030

3131
private HttpURLConnection connection;
@@ -116,12 +116,17 @@ public int getChunkSize() {
116116
* bigger uploads into multiple requests. For example, if you have a resource of 2MB and
117117
* the payload size set to 1MB, the upload will be transferred by two requests of 1MB each.
118118
*
119-
* The default value for this setting is 1024 * 1024 * 1024 bytes (GiB).
119+
* The default value for this setting is 10 * 1024 * 1024 bytes (10 MiB).
120120
*
121-
* Be aware that setting a low maximum payload size (in the megabytes or even less range) will result in decreased
121+
* Be aware that setting a low maximum payload size (in the low megabytes or even less range) will result in decreased
122122
* performance since more requests need to be used for an upload. Each request will come with its overhead in terms
123-
* of longer upload times. Furthermore, changing this setting is rarely necessary and is only advised in a situation
124-
* when a server cannot deal with streaming request bodies (e.g. some Python frameworks).
123+
* of longer upload times.
124+
*
125+
* Be aware that setting a high maximum payload size may result in a high memory usage since
126+
* tus-java-client usually allocates a buffer with the maximum payload size (this buffer is used
127+
* to allow retransmission of lost data if necessary). If the client is running on a memory-
128+
* constrained device (e.g. mobile app) and the maximum payload size is too high, it might
129+
* result in an {@link OutOfMemoryError}.
125130
*
126131
* This method must not be called when the uploader has currently an open connection to the
127132
* remote server. In general, try to set the payload size before invoking {@link #uploadChunk()}

src/test/java/io/tus/java/client/TestTusUploader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public void testSetRequestPayloadSize() throws Exception {
171171

172172
TusUploader uploader = new TusUploader(client, uploadUrl, input, 0);
173173

174-
assertEquals(uploader.getRequestPayloadSize(), 1024 * 1024 * 1024);
174+
assertEquals(uploader.getRequestPayloadSize(), 10 * 1024 * 1024);
175175
uploader.setRequestPayloadSize(5);
176176
assertEquals(uploader.getRequestPayloadSize(), 5);
177177

0 commit comments

Comments
 (0)