Skip to content
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

Improve APT package check in the Assistant #2983

Closed
4 tasks done
davidcr01 opened this issue Jun 5, 2024 · 0 comments · Fixed by #3004
Closed
4 tasks done

Improve APT package check in the Assistant #2983

davidcr01 opened this issue Jun 5, 2024 · 0 comments · Fixed by #3004
Assignees
Labels
level/task Subtask issue type/change Change requested

Comments

@davidcr01
Copy link
Contributor

davidcr01 commented Jun 5, 2024

Context

Working on #2879, I noticed that the installation in the RPM system was significantly faster than the installation in the APT system. This behavior could be normal as they are different OSs.

However, I noticed that the Installation assistant in the APT systems is slowed by the APT package manager, specifically while checking the installed packages.

Currently:

  • In APT systems, we use apt list --installed | grep <package_name> to check if a package is installed.
  • In RPM systems, we used yum list installed | grep <package_name> to check if a package is installed until 4.8.2. In this PR, the command was changed to rpm -q <package_name> because the original command was causing trouble with the YUM lock. Besides, the new command was faster than the original command.

Description

The aim of this issue is to try to improve the performance of the APT packages check. I've done some research about the consumed time of these commands:

  • We can see that to check if a package is installed using the apt list option, the CPU consumes about 0.5 seconds (considering user+sys times).
root@ip-172-31-71-48:/home/ubuntu# time apt list --installed | grep -E ^"curl"

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

curl/jammy-updates,jammy-security,now 7.81.0-1ubuntu1.16 amd64 [installed]

real    0m0.506s
user    0m0.497s
sys     0m0.011s
  • Using another option, for example dpkg filtering with the ii string (check if it's actually installed), the time consumed is significantly lower, taking 0.32 seconds:
root@ip-172-31-71-48:/home/ubuntu# time dpkg -l curl | grep -E '^ii\s'
ii  curl           7.81.0-1ubuntu1.16 amd64        command line tool for transferring data with URL syntax

real    0m0.030s
user    0m0.014s
sys     0m0.018s

To reaffirm this hypothesis, I created a simple script to chronometer the time consumed checking a package list. I used the following script:

#!/bin/bash

# List of packages to check
packages=(systemd grep tar coreutils sed gawk curl lsof openssl)

dpkg_total_time=0
apt_total_time=0

# Measure total time for dpkg
dpkg_start_time=$(date +%s%3N)
for package in "${packages[@]}"; do
    dpkg -l $package | grep -E '^ii\s' > /dev/null
done
dpkg_end_time=$(date +%s%3N)
dpkg_total_time=$((dpkg_end_time - dpkg_start_time))

# Measure total time for apt
apt_start_time=$(date +%s%3N)
for package in "${packages[@]}"; do
    apt list --installed 2>/dev/null | grep -q -E ^"${package}" > /dev/null
done
apt_end_time=$(date +%s%3N)
apt_total_time=$((apt_end_time - apt_start_time))

# Output the results
echo "Total time for dpkg: $dpkg_total_time ms"
echo "Total time for apt: $apt_total_time ms"

The results were the following:

root@ip-172-31-71-48:/home/ubuntu# bash measure.sh 
Total time for dpkg: 135 ms
Total time for apt: 5240 ms

Note

With the new option, the package list check is 38.81 times faster, in other words, 97,42% faster.

Changes

The involved changes are the following:

See all changes

Tasks

  • Validate if the dpkg proposed option fits the requirements.
  • If so, change the apt occurrences with the dpkg.
  • Check if the packages are correctly checked.
  • Perform several installations to enhance the testing.
@davidcr01 davidcr01 added level/task Subtask issue type/change Change requested labels Jun 5, 2024
@davidcr01 davidcr01 changed the title Improve APT package check Improve APT package check in the Assistant Jun 5, 2024
@Enaraque Enaraque self-assigned this Jun 13, 2024
@Enaraque Enaraque linked a pull request Jun 13, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
level/task Subtask issue type/change Change requested
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants