diff options
author | Charlie Sale <softwaresale01@gmail.com> | 2021-08-11 23:59:14 -0400 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2021-09-04 10:34:00 +1000 |
commit | efb714b31cd30c21df179d8cbe3730b05fffd6bd (patch) | |
tree | 2896acbb79acb833dfaa7c4fa3873d7f3349c5e3 /lib | |
parent | f951282bec86589011a5c852d2342b882c410b3a (diff) |
Order downloads by descending max_size
When downloading in parallel, sort by package size so that the larger
packages are queued first to fully leverage parallelism.
Addresses FS#70172
Signed-off-by: Charlie Sale <softwaresale01@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libalpm/dload.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 15e6dff7..4322318b 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -847,6 +847,19 @@ cleanup: return ret; } +/* + * Use to sort payloads by max size in decending order (largest -> smallest) + */ +static int compare_dload_payload_sizes(const void *left_ptr, const void *right_ptr) +{ + struct dload_payload *left, *right; + + left = (struct dload_payload *) left_ptr; + right = (struct dload_payload *) right_ptr; + + return right->max_size - left->max_size; +} + /* Returns -1 if an error happened for a required file * Returns 0 if a payload was actually downloaded * Returns 1 if no files were downloaded and all errors were non-fatal @@ -860,6 +873,10 @@ static int curl_download_internal(alpm_handle_t *handle, int max_streams = handle->parallel_downloads; int updated = 0; /* was a file actually updated */ CURLM *curlm = handle->curlm; + size_t payloads_size = alpm_list_count(payloads); + + /* Sort payloads by package size */ + payloads = alpm_list_msort(payloads, payloads_size, &compare_dload_payload_sizes); while(active_downloads_num > 0 || payloads) { CURLMcode mc; |