-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Parallelise uploads #16268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Parallelise uploads #16268
Conversation
…ad safe vars and make sure UI updates accordingly Signed-off-by: Raphael Vieira <raphaelecv@hotmail.com>
… safety Signed-off-by: Raphael Vieira <raphaelecv@hotmail.com>
…progress Signed-off-by: Raphael Vieira <raphaelecv@hotmail.com>
bd4ef78 to
1a5bac6
Compare
Signed-off-by: Raphael Vieira <raphaelecv@hotmail.com>
app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadWorker.kt
Outdated
Show resolved
Hide resolved
…ting easier. Added various unit tests and an IT to test the FileUploadWorker Signed-off-by: Raphael Vieira <raphaelecv@hotmail.com>
…roid into parallelise-uploads
…ting easier. Added various unit tests and an IT to test the FileUploadWorker Signed-off-by: Raphael Vieira <raphaelecv@hotmail.com>
…current uploads Signed-off-by: Raphael Vieira <raphaelecv@hotmail.com>
…loads Shared preference - Max concurrent uploads
Signed-off-by: Raphael Vieira <raphaelecv@hotmail.com>
…roid into parallelise-uploads
Signed-off-by: Raphael Vieira <raphaelecv@hotmail.com>
alperozturk96
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello
Thank you for the PR 👍
I really appreciate the time and effort you’ve put into this.
I wanted to share some feedback after reviewing the changes. Using ConcurrentHashMap, Semaphore, atomics, and synchronized blocks to achieve parallel uploads makes the implementation quite fragile and hard to maintain in the long run. It also increases complexity in an area of the codebase that is already fairly sensitive.
In fact, we can achieve parallel uploads with a much simpler change. Currently, in BackgroundJobManagerImpl, the startFilesUploadJob function uses the same worker tag together with the ExistingWorkPolicy.APPEND_OR_REPLACE policy. Because of this, a new worker is not used for each upload attempt; instead, uploads are queued and executed sequentially.
By making the tag unique (for example, by appending a random value), a new worker will be started for each upload, enabling parallelism with minimal changes:
val tag = startFileUploadJobTag(user.accountName + Random.nextInt())
Introducing parallel uploads is definitely a good idea, but it’s something we should approach incrementally and carefully to ensure the overall robustness of the app. FileUploadWorker is a critical component: it also triggers UI updates via the broadcast manager and is observed by multiple screens. Making it parallel will likely have side effects in those areas (notifications, upload list, file listing, etc.), so we need to be mindful of that impact.
I’d suggest the following approach:
-
Enable parallel uploads with the minimal change (unique worker tags).
-
Observe and adjust the behavior of the caller functions, and add appropriate tests.
-
Observe UI behavior (notifications, file list, upload list) and address any issues that arise.
Thanks again for your contribution and initiative on this topic. :)
@ZetaTom @tobiasKaminsky fyi.
Thank you @alperozturk96 for taking the time to review and I appreciate you sharing your expertise in this area. I don't disagree with any of the comments and I will happily explore your suggestion. |
Signed-off-by: Raphael Vieira <raphaelecv@hotmail.com>
…roid into parallelise-uploads
|
@alperozturk96 I have looked into your suggestion, and managed to get it working. It's significantly less changes and anecdotally seems to run much faster =]. Unfortunately it has had the side effects you mentioned. Notably the upload list is not reflective of the parallel nature (multiple files should be marked as uploading) - I am not sure how to address this without the ConcurrentHashMap solution I previously incorporated into FileUploadWorker. Could you please advise in this case? May I also clarify what you mean by "file list"? |
…s, added necessary unit tests
Signed-off-by: Raphael Vieira <raphaelecv@hotmail.com>
|
From a design POV, "max concurrent uploads" should definitely not be a user-configurable setting. Just pick a sensible default and stick with that. If it doesn't work for everyone, we should investigate then. |
Hey @kra-mo happy to remove the configurability and simply default, but could you help me understand why it "should definitely not be user configurable?". Seems like a useful reasonable option at a glance Alternatively if the fear is that we are giving the user "a foot gun", we can provide a limited selection of options 1,2,5,10,20? |
|
It's against our design principles:
From https://docs.nextcloud.com/server/27/developer_manual/design/introduction.html But TL;DR the more preferences you have that most users shouldn't touch, the harder it is to find ones that they do care about. If there is no reason for something to be configurable other than "why not", it's best to just not :) |
|
If there is a need to have different numbers of for different scenarios, it'll probably come up, and we can probably solve it for that scenario automatically, as the developers. We shouldn't put the burden on the user. |
|
@kra-mo great response, consider me convinced. I will revert the changes and default |


Issue: #10124
This PR aims to introduce improvements to the file upload process by parallelizing uploads using Kotlin Coroutines and a Semaphore (which I defaulted to 10 concurrent tasks) to improve throughput.
Key Changes