Having recently switched to a setup with only nginx (and no apache), I found myself wanting to run some tests. As nice as
siege is, I rather like ApacheBench (
ab). However, I really didn’t want to install all of Apache just to get ab.
Quick and Easy Way
On Amazon’s Linux, the ab binary can be found in the
httpd-tools package, if you don’t mind a few extra items installed, then the install is quite simple (and really, it isn’t very large). The few dependencies are needed whether or not you install all of httpd-tools, or only ab.
yum install httpd-tools
The total installed size of this approach is about 125kb (httpd-tools) + 480kb (dependencies).
The Bare Minimum
Initially, however, I didn’t realize that ab was a part of httpd-tools, and thought, instead, that it was part of
httpd itself. So, the approach I took, was to extract the binary from the package and simply copy it to the desired location, applying this to httpd-tools, we can add the single binary to our system without any extra components from the httpd-tools package.
mkdir /usr/local/src/ab && cd $_ yumdownloader httpd-tools rpm2cpio httpd-tools-*.amzn1.i686.rpm | cpio -idmv ./usr/bin/ab mv usr/bin/ab /usr/bin/ rm -rf /usr/local/src/ab yum install apr-util
A quick explaination of the above:
- I like to use /usr/local/src as my temporary directory for code related things, but any folder will work. We also create an ab folder as our working directory, since cpio will create all intermediate directories.
- The yumdownloader command will download the rpm corresponding to the package specified.
- We now convert the rpm to a cpio archive and pipe that to the cpio program.
- The arguments used are the following:
- i: extract the files
- d: create the needed directories
- m: retain modification times (optional)
- v: verbose (optional)
- We also specify the path (within the archive) to the ab binary, so that only that one file is extracted).
- This command could have been run from the directory root (/), and would have just added the one file to /usr/bin – eliminating the need for most of the other steps – however, doing so can be a rather risky.
- Finally, we move the ab binary to a suitable location, delete the now unnecessary ab directory we created, and satisfy the necessary dependencies (the only one of which is
apr-util, which in turn depends on
If you get the following error, when trying to run ab, you probably didn’t install
ab: error while loading shared libraries: libaprutil-1.so.0: cannot open shared object file: No such file or directory
The total installed size of this approach is about 50kb (ab) + 480kb (dependencies). Not exactly a lot of savings in this case, but potentially more useful when used on other packages.