Speeding up dpkg

In this first post, we will speed up dpkg, in a later post, we shall speed up apt.

I don’t know about you, but for a long time I have been frustrated with both dpkg and apt’s speed (or should that be lack thereof), however recently I stumbled along some information that should increase the speed of installing, removing, updating etc.

NOTE: Although on my system this all went well, I can accept no responsibility for this going wrong, it may be wise to experiment in a virtual machine first.

The main bottleneck in dpkg’s speed, is reading from its database. This database is inefficient as it is made up of hundreds of individual files, rather than a proper database. To solve this, we are going to use a program called tdpkg; it does this by storing the dpkg database in either an sqlite or a tokyocabinet database.

  1. Open up a Terminal (Applications>Accessories>Terminal) and get ready!
  2. (Optional) Backup your dpkg database incase anything goes wrong (this could take a while)
    cp -r /var/lib/dpkg/info ~/dpkg-backup
  3. Download the libraries necessary to compile tdpkg
    sudo apt-get install build-essential libsqlite3-dev libtokyocabinet-dev
  4. Download the latest source of tdpkg and navigate into the source
    git clone http://git.gitorious.org/lethal-works/tdpkg.git && cd tdpkg
  5. Now you must compile tdpkg, using the database library you want. TokyoCabinet is faster than sqlite, however sqlite can handle multiple requests better. If you are like me and shallow, and want pure speed, pick TokyoCabinet🙂
    TokyoCabinet

    make
    SQLite

    make CACHE=sqlite

  6. tdpkg should now compile into a shared library file called libtdpkg.so. We are now going to move this file into /usr/lib and edit the system-wide bash file, so that when dpkg is called, this library is loaded at the same time.
  7. To do this, run the command
    sudo su
    And then
    cp libtdpkg.so /usr/lib/libtdpkg.so

    And then

    echo alias dpkg="LD_PRELOAD=/usr/lib/libtdpkg.so /usr/bin/dpkg" >> /etc/bash.bashrc

  8. You should now be done! Reboot your computer and dpkg should be a lot quicker!

To undo changes:

  1. Run the command
    sudo rm /usr/lib/tdpkg.so tdpkg
  2. Run the command
    gksudo gedit /etc/bash.bashrc
    and delete the line at the bottom that says:

    alias dpkg="LD_PRELOAD=/usr/lib/libtdpkg.so /usr/bin/dpkg"
Sources

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: