Categories
SysOps

How to improve dnf download times

Improve dnf download times.

Inspect current dnf configuration.

$ cat /etc/dnf/dnf.conf 
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=True
skip_if_unavailable=False

Increase the number of simultaneous downloads from default 3 to 10 (up to 20).

$ echo max_parallel_downloads=10 | sudo tee -a /etc/dnf/dnf.conf 

Install a package.

$ sudo dnf install sysstat
Last metadata expiration check: 0:36:58 ago on Sat Apr  9 22:52:26 2022.
Dependencies resolved.
======================================================================================================================
 Package                            Architecture      Version                              Repository            Size
======================================================================================================================
Installing:
 sysstat                            x86_64            12.5.4-3.el9                         appstream            480 k
Installing dependencies:
 avahi-libs                         x86_64            0.8-11.el9                           baseos                68 k
 crypto-policies-scripts            noarch            20220223-1.git5203b41.el9            baseos                95 k
 libevent                           x86_64            2.1.12-6.el9                         baseos               263 k
 libuv                              x86_64            1:1.42.0-1.el9                       appstream            150 k
 lm_sensors-libs                    x86_64            3.6.0-10.el9                         appstream             42 k
 nspr                               x86_64            4.32.0-9.el9                         appstream            137 k
 nss                                x86_64            3.71.0-7.el9                         appstream            699 k
 nss-softokn                        x86_64            3.71.0-7.el9                         appstream            363 k
 nss-softokn-freebl                 x86_64            3.71.0-7.el9                         appstream            332 k
 nss-sysinit                        x86_64            3.71.0-7.el9                         appstream             22 k
 nss-util                           x86_64            3.71.0-7.el9                         appstream             91 k
 pcp-conf                           x86_64            5.3.5-8.el9                          appstream             31 k
 pcp-libs                           x86_64            5.3.5-8.el9                          appstream            602 k
 xz                                 x86_64            5.2.5-7.el9                          baseos               226 k

Transaction Summary
======================================================================================================================
Install  15 Packages

Total download size: 3.5 M
Installed size: 9.7 M
Is this ok [y/N]: y
Downloading Packages:
(1/15): lm_sensors-libs-3.6.0-10.el9.x86_64.rpm                                       101 kB/s |  42 kB     00:00    
(2/15): nss-sysinit-3.71.0-7.el9.x86_64.rpm                                           181 kB/s |  22 kB     00:00    
(3/15): avahi-libs-0.8-11.el9.x86_64.rpm                                              100 kB/s |  68 kB     00:00    
(4/15): crypto-policies-scripts-20220223-1.git5203b41.el9.noarch.rpm                  138 kB/s |  95 kB     00:00    
(5/15): nspr-4.32.0-9.el9.x86_64.rpm                                                  198 kB/s | 137 kB     00:00    
(6/15): libuv-1.42.0-1.el9.x86_64.rpm                                                 198 kB/s | 150 kB     00:00    
(7/15): xz-5.2.5-7.el9.x86_64.rpm                                                     293 kB/s | 226 kB     00:00    
(8/15): libevent-2.1.12-6.el9.x86_64.rpm                                              328 kB/s | 263 kB     00:00    
(9/15): nss-util-3.71.0-7.el9.x86_64.rpm                                              318 kB/s |  91 kB     00:00    
(10/15): nss-softokn-freebl-3.71.0-7.el9.x86_64.rpm                                   336 kB/s | 332 kB     00:00    
(11/15): pcp-conf-5.3.5-8.el9.x86_64.rpm                                               92 kB/s |  31 kB     00:00    
(12/15): pcp-libs-5.3.5-8.el9.x86_64.rpm                                              1.3 MB/s | 602 kB     00:00    
(13/15): sysstat-12.5.4-3.el9.x86_64.rpm                                              779 kB/s | 480 kB     00:00    
(14/15): nss-softokn-3.71.0-7.el9.x86_64.rpm                                          259 kB/s | 363 kB     00:01    
(15/15): nss-3.71.0-7.el9.x86_64.rpm                                                  422 kB/s | 699 kB     00:01    
----------------------------------------------------------------------------------------------------------------------
Total                                                                                 1.1 MB/s | 3.5 MB     00:03     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                              1/1 
  Installing       : nspr-4.32.0-9.el9.x86_64                                                                    1/15 
  Installing       : nss-util-3.71.0-7.el9.x86_64                                                                2/15 
  Installing       : nss-softokn-freebl-3.71.0-7.el9.x86_64                                                      3/15 
  Installing       : nss-softokn-3.71.0-7.el9.x86_64                                                             4/15 
  Installing       : pcp-conf-5.3.5-8.el9.x86_64                                                                 5/15 
  Installing       : lm_sensors-libs-3.6.0-10.el9.x86_64                                                         6/15 
  Installing       : libuv-1:1.42.0-1.el9.x86_64                                                                 7/15 
  Installing       : xz-5.2.5-7.el9.x86_64                                                                       8/15 
  Installing       : libevent-2.1.12-6.el9.x86_64                                                                9/15 
  Installing       : avahi-libs-0.8-11.el9.x86_64                                                               10/15 
  Installing       : crypto-policies-scripts-20220223-1.git5203b41.el9.noarch                                   11/15 
  Installing       : nss-sysinit-3.71.0-7.el9.x86_64                                                            12/15 
  Installing       : nss-3.71.0-7.el9.x86_64                                                                    13/15 
  Running scriptlet: nss-3.71.0-7.el9.x86_64                                                                    13/15 
  Installing       : pcp-libs-5.3.5-8.el9.x86_64                                                                14/15 
  Installing       : sysstat-12.5.4-3.el9.x86_64                                                                15/15 
  Running scriptlet: sysstat-12.5.4-3.el9.x86_64                                                                15/15 
Created symlink /etc/systemd/system/multi-user.target.wants/sysstat.service → /usr/lib/systemd/system/sysstat.service.
Created symlink /etc/systemd/system/sysstat.service.wants/sysstat-collect.timer → /usr/lib/systemd/system/sysstat-collect.timer.
Created symlink /etc/systemd/system/sysstat.service.wants/sysstat-summary.timer → /usr/lib/systemd/system/sysstat-summary.timer.

  Running scriptlet: crypto-policies-scripts-20220223-1.git5203b41.el9.noarch                                   15/15 
  Running scriptlet: nss-3.71.0-7.el9.x86_64                                                                    15/15 
  Running scriptlet: sysstat-12.5.4-3.el9.x86_64                                                                15/15 
  Verifying        : avahi-libs-0.8-11.el9.x86_64                                                                1/15 
  Verifying        : crypto-policies-scripts-20220223-1.git5203b41.el9.noarch                                    2/15 
  Verifying        : libevent-2.1.12-6.el9.x86_64                                                                3/15 
  Verifying        : xz-5.2.5-7.el9.x86_64                                                                       4/15 
  Verifying        : libuv-1:1.42.0-1.el9.x86_64                                                                 5/15 
  Verifying        : lm_sensors-libs-3.6.0-10.el9.x86_64                                                         6/15 
  Verifying        : nspr-4.32.0-9.el9.x86_64                                                                    7/15 
  Verifying        : nss-3.71.0-7.el9.x86_64                                                                     8/15 
  Verifying        : nss-softokn-3.71.0-7.el9.x86_64                                                             9/15 
  Verifying        : nss-softokn-freebl-3.71.0-7.el9.x86_64                                                     10/15 
  Verifying        : nss-sysinit-3.71.0-7.el9.x86_64                                                            11/15 
  Verifying        : nss-util-3.71.0-7.el9.x86_64                                                               12/15 
  Verifying        : pcp-conf-5.3.5-8.el9.x86_64                                                                13/15 
  Verifying        : pcp-libs-5.3.5-8.el9.x86_64                                                                14/15 
  Verifying        : sysstat-12.5.4-3.el9.x86_64                                                                15/15 

Installed:
  avahi-libs-0.8-11.el9.x86_64                     crypto-policies-scripts-20220223-1.git5203b41.el9.noarch          
  libevent-2.1.12-6.el9.x86_64                     libuv-1:1.42.0-1.el9.x86_64                                       
  lm_sensors-libs-3.6.0-10.el9.x86_64              nspr-4.32.0-9.el9.x86_64                                          
  nss-3.71.0-7.el9.x86_64                          nss-softokn-3.71.0-7.el9.x86_64                                   
  nss-softokn-freebl-3.71.0-7.el9.x86_64           nss-sysinit-3.71.0-7.el9.x86_64                                   
  nss-util-3.71.0-7.el9.x86_64                     pcp-conf-5.3.5-8.el9.x86_64                                       
  pcp-libs-5.3.5-8.el9.x86_64                      sysstat-12.5.4-3.el9.x86_64                                       
  xz-5.2.5-7.el9.x86_64                           

Complete!

You can also use a connect time metric to find the fastest available mirror.

$ echo fastestmirror=True | sudo tee -a /etc/dnf/dnf.conf 

Install a package.

$ sudo dnf install sysstat
determining the fastest mirror (38 hosts).. done.==                                 ] ---  B/s |   0  B     --:-- ETA
CentOS Stream 9 - BaseOS                                                              614 kB/s | 5.6 MB     00:09    
CentOS Stream 9 - AppStream                                                           4.1 MB/s |  13 MB     00:03    
CentOS Stream 9 - Extras packages                                                     7.5 kB/s | 6.8 kB     00:00    
Dependencies resolved.
======================================================================================================================
 Package                            Architecture      Version                              Repository            Size
======================================================================================================================
Installing:
 sysstat                            x86_64            12.5.4-3.el9                         appstream            480 k
Installing dependencies:
 avahi-libs                         x86_64            0.8-11.el9                           baseos                68 k
 crypto-policies-scripts            noarch            20220223-1.git5203b41.el9            baseos                95 k
 libevent                           x86_64            2.1.12-6.el9                         baseos               263 k
 libuv                              x86_64            1:1.42.0-1.el9                       appstream            150 k
 lm_sensors-libs                    x86_64            3.6.0-10.el9                         appstream             42 k
 nspr                               x86_64            4.32.0-9.el9                         appstream            137 k
 nss                                x86_64            3.71.0-7.el9                         appstream            699 k
 nss-softokn                        x86_64            3.71.0-7.el9                         appstream            363 k
 nss-softokn-freebl                 x86_64            3.71.0-7.el9                         appstream            332 k
 nss-sysinit                        x86_64            3.71.0-7.el9                         appstream             22 k
 nss-util                           x86_64            3.71.0-7.el9                         appstream             91 k
 pcp-conf                           x86_64            5.3.5-8.el9                          appstream             31 k
 pcp-libs                           x86_64            5.3.5-8.el9                          appstream            602 k
 xz                                 x86_64            5.2.5-7.el9                          baseos               226 k

Transaction Summary
======================================================================================================================
Install  15 Packages

Total download size: 3.5 M
Installed size: 9.7 M
Is this ok [y/N]: y
Downloading Packages:
CentOS Stream 9 - AppStream            228% [=========================================================================done.===========]  10 kB/s | 6.9 kB     --:-- ETA
(1/15): lm_sensors-libs-3.6.0-10.el9.x86_64.rpm                                        60 kB/s |  42 kB     00:00    
(2/15): avahi-libs-0.8-11.el9.x86_64.rpm                                               95 kB/s |  68 kB     00:00    
(3/15): crypto-policies-scripts-20220223-1.git5203b41.el9.noarch.rpm                  133 kB/s |  95 kB     00:00    
(4/15): nss-sysinit-3.71.0-7.el9.x86_64.rpm                                           503 kB/s |  22 kB     00:00    
(5/15): libevent-2.1.12-6.el9.x86_64.rpm                                              291 kB/s | 263 kB     00:00    
(6/15): libuv-1.42.0-1.el9.x86_64.rpm                                                 165 kB/s | 150 kB     00:00    
(7/15): nspr-4.32.0-9.el9.x86_64.rpm                                                  150 kB/s | 137 kB     00:00    
(8/15): xz-5.2.5-7.el9.x86_64.rpm                                                     224 kB/s | 226 kB     00:01    
(9/15): nss-3.71.0-7.el9.x86_64.rpm                                                   634 kB/s | 699 kB     00:01    
(10/15): nss-softokn-freebl-3.71.0-7.el9.x86_64.rpm                                   294 kB/s | 332 kB     00:01    
(11/15): pcp-conf-5.3.5-8.el9.x86_64.rpm                                               71 kB/s |  31 kB     00:00    
(12/15): nss-softokn-3.71.0-7.el9.x86_64.rpm                                          308 kB/s | 363 kB     00:01    
(13/15): nss-util-3.71.0-7.el9.x86_64.rpm                                             161 kB/s |  91 kB     00:00    
(14/15): pcp-libs-5.3.5-8.el9.x86_64.rpm                                              1.0 MB/s | 602 kB     00:00    
(15/15): sysstat-12.5.4-3.el9.x86_64.rpm                                              846 kB/s | 480 kB     00:00    
----------------------------------------------------------------------------------------------------------------------
Total                                                                                 1.6 MB/s | 3.5 MB     00:02     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                              1/1 
  Installing       : nspr-4.32.0-9.el9.x86_64                                                                    1/15 
  Installing       : nss-util-3.71.0-7.el9.x86_64                                                                2/15 
  Installing       : nss-softokn-freebl-3.71.0-7.el9.x86_64                                                      3/15 
  Installing       : nss-softokn-3.71.0-7.el9.x86_64                                                             4/15 
  Installing       : pcp-conf-5.3.5-8.el9.x86_64                                                                 5/15 
  Installing       : lm_sensors-libs-3.6.0-10.el9.x86_64                                                         6/15 
  Installing       : libuv-1:1.42.0-1.el9.x86_64                                                                 7/15 
  Installing       : xz-5.2.5-7.el9.x86_64                                                                       8/15 
  Installing       : libevent-2.1.12-6.el9.x86_64                                                                9/15 
  Installing       : avahi-libs-0.8-11.el9.x86_64                                                               10/15 
  Installing       : crypto-policies-scripts-20220223-1.git5203b41.el9.noarch                                   11/15 
  Installing       : nss-sysinit-3.71.0-7.el9.x86_64                                                            12/15 
  Installing       : nss-3.71.0-7.el9.x86_64                                                                    13/15 
  Running scriptlet: nss-3.71.0-7.el9.x86_64                                                                    13/15 
  Installing       : pcp-libs-5.3.5-8.el9.x86_64                                                                14/15 
  Installing       : sysstat-12.5.4-3.el9.x86_64                                                                15/15 
  Running scriptlet: sysstat-12.5.4-3.el9.x86_64                                                                15/15 
Created symlink /etc/systemd/system/multi-user.target.wants/sysstat.service → /usr/lib/systemd/system/sysstat.service.
Created symlink /etc/systemd/system/sysstat.service.wants/sysstat-collect.timer → /usr/lib/systemd/system/sysstat-collect.timer.
Created symlink /etc/systemd/system/sysstat.service.wants/sysstat-summary.timer → /usr/lib/systemd/system/sysstat-summary.timer.

  Running scriptlet: crypto-policies-scripts-20220223-1.git5203b41.el9.noarch                                   15/15 
  Running scriptlet: nss-3.71.0-7.el9.x86_64                                                                    15/15 
  Running scriptlet: sysstat-12.5.4-3.el9.x86_64                                                                15/15 
  Verifying        : avahi-libs-0.8-11.el9.x86_64                                                                1/15 
  Verifying        : crypto-policies-scripts-20220223-1.git5203b41.el9.noarch                                    2/15 
  Verifying        : libevent-2.1.12-6.el9.x86_64                                                                3/15 
  Verifying        : xz-5.2.5-7.el9.x86_64                                                                       4/15 
  Verifying        : libuv-1:1.42.0-1.el9.x86_64                                                                 5/15 
  Verifying        : lm_sensors-libs-3.6.0-10.el9.x86_64                                                         6/15 
  Verifying        : nspr-4.32.0-9.el9.x86_64                                                                    7/15 
  Verifying        : nss-3.71.0-7.el9.x86_64                                                                     8/15 
  Verifying        : nss-softokn-3.71.0-7.el9.x86_64                                                             9/15 
  Verifying        : nss-softokn-freebl-3.71.0-7.el9.x86_64                                                     10/15 
  Verifying        : nss-sysinit-3.71.0-7.el9.x86_64                                                            11/15 
  Verifying        : nss-util-3.71.0-7.el9.x86_64                                                               12/15 
  Verifying        : pcp-conf-5.3.5-8.el9.x86_64                                                                13/15 
  Verifying        : pcp-libs-5.3.5-8.el9.x86_64                                                                14/15 
  Verifying        : sysstat-12.5.4-3.el9.x86_64                                                                15/15 

Installed:
  avahi-libs-0.8-11.el9.x86_64                     crypto-policies-scripts-20220223-1.git5203b41.el9.noarch          
  libevent-2.1.12-6.el9.x86_64                     libuv-1:1.42.0-1.el9.x86_64                                       
  lm_sensors-libs-3.6.0-10.el9.x86_64              nspr-4.32.0-9.el9.x86_64                                          
  nss-3.71.0-7.el9.x86_64                          nss-softokn-3.71.0-7.el9.x86_64                                   
  nss-softokn-freebl-3.71.0-7.el9.x86_64           nss-sysinit-3.71.0-7.el9.x86_64                                   
  nss-util-3.71.0-7.el9.x86_64                     pcp-conf-5.3.5-8.el9.x86_64                                       
  pcp-libs-5.3.5-8.el9.x86_64                      sysstat-12.5.4-3.el9.x86_64                                       
  xz-5.2.5-7.el9.x86_64                           

Complete!

Inspect fastest mirror data.

$ cat /var/cache/dnf/fastestmirror.cache 
[:_librepo_:]
version=1

[https://centos-stream.ip-connect.info]
ts=1649547103
connectime=0.033501000000000003

[https://centos-stream.mirror.wearetriple.com]
ts=1649547103
connectime=0.037987999999999966

[https://mirror.in2p3.fr]
ts=1649547103
connectime=0.059638999999999998

[http://mirror.in2p3.fr]
ts=1649547103
connectime=0.059686000000000017

[https://semirror.lonyai.com]
ts=1649547103
connectime=0.059727000000000086

[http://semirror.lonyai.com]
ts=1649547103
connectime=0.059734999999999983

[https://mirror.netsite.dk]
ts=1649547103
connectime=0.094035000000000007

[http://mirror.netsite.dk]
ts=1649547103
connectime=0.094073000000000004

[https://linuxsoft.cern.ch]
ts=1649547103
connectime=0.098521999999999998

[http://ftp.plusline.net]
ts=1649547103
connectime=0.11206700000000003

[https://ftp.plusline.net]
ts=1649547103
connectime=0.11221199999999998

[https://mirror.lanet.network]
ts=1649547103
connectime=0.147588

[https://mirror.netzwerge.de]
ts=1649547103
connectime=0.14893299999999998

[https://ftp.nsc.ru]
ts=1649547103
connectime=0.164489

[https://mirror.alwyzon.net]
ts=1649547103
connectime=0.198935

[http://mirror.alwyzon.net]
ts=1649547103
connectime=0.19900100000000001

[http://centos-stream.ip-connect.info]
ts=1649547103
connectime=0.19936899999999999

[https://ftp.fi.muni.cz]
ts=1649547103
connectime=0.20128799999999997

[http://centos-stream.mirror.wearetriple.com]
ts=1649547103
connectime=0.20130199999999998

[http://ftp.nsc.ru]
ts=1649547103
connectime=0.21273199999999992

[http://mirror.karneval.cz]
ts=1649547103
connectime=0.25092599999999998

[https://mirror.karneval.cz]
ts=1649547103
connectime=0.25274600000000003

[http://linuxsoft.cern.ch]
ts=1649547103
connectime=0.26011199999999995

[http://mirror.netzwerge.de]
ts=1649547103
connectime=0.26015500000000003

[http://ftp.fi.muni.cz]
ts=1649547103
connectime=0.26373599999999997

[http://centos-stream.koyanet.lv]
ts=1649547103
connectime=-1

[http://mirror.im.jku.at]
ts=1649547103
connectime=-1

[http://mirror.lanet.network]
ts=1649547103
connectime=-1

[http://fr2.rpmfind.net]
ts=1649547103
connectime=-1

[https://fr2.rpmfind.net]
ts=1649547103
connectime=-1

[http://lon.mirror.rackspace.com]
ts=1649547103
connectime=-1

[https://centos-stream.koyanet.lv]
ts=1649547103
connectime=-1

[http://humirror.lonyai.com]
ts=1649547103
connectime=-1

[http://mirror1.hs-esslingen.de]
ts=1649547103
connectime=-1

[https://mirror.im.jku.at]
ts=1649547103
connectime=-1

[https://humirror.lonyai.com]
ts=1649547103
connectime=-1

[https://lon.mirror.rackspace.com]
ts=1649547103
connectime=-1

[https://mirror1.hs-esslingen.de]
ts=1649547103
connectime=-1

Delete fastest mirror data to recreate it on next run.

$ sudo rm /var/cache/dnf/fastestmirror.cache