Commit 6367cdd5 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Merge branch 'slow-fs-simulator' into 'master'

Added shell script for simulating slow filesystems

This is Linux only as I'm not familiar with traffic shaping on other platforms (e.g. OS X).

See merge request !120
parents 0737c143 13c73960
......@@ -49,6 +49,8 @@ sockets to avoid port conflicts.
- ['bundle install' fails while compiling eventmachine gem](#bundle-install-fails-while-compiling-eventmachine-gem)
- ['Invalid reference name' when creating a new tag](#invalid-reference-name-when-creating-a-new-tag)
- [Other problems](#other-problems)
- [Executables](#executables)
- [mount-slow-fs](#mount-slow-fs)
- [License](#license)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
......@@ -645,6 +647,39 @@ git commit --allow-empty -m 'I can commit'
Please open an issue on the [GDK issue tracker](https://gitlab.com/gitlab-org/gitlab-development-kit/issues).
## Executables
A collection of executables can be found in the `bin/` directory. You can use
these executables by adding this directory to your shell's executable path. For
example, when using Bash:
export PATH="${PATH}:path/to/gdk/bin"
### mount-slow-fs
This script can be used to mount a source directory at a given mount point via
SSHFS and slow down network traffic as a way of replicating a slow NFS. Usage of
this script is as following:
mount-slow-fs path/to/actual/repositories /path/to/mountpoint
As an example, we'll use the following directories:
* Source directory: ~/Projects/repositories
* Mountpoint: /mnt/repositories
First create the mountpoint and set the correct permissions:
sudo mkdir /mnt/repositories
sudo chown $USER /mnt/repositories
Now we can run the script:
mount-slow-fs ~/Projects/repositories /mnt/repositories
Terminating the script (using ^C) will automatically unmount the repositories
and remove the created traffic shaping rules.
## License
The GitLab Development Kit is distributed under the MIT license,
......
#!/usr/bin/env bash
# This script mounts a given path at a given location using SSHFS while slowing
# down traffic on the loopback interface. This combination can be used to
# replicate a slow file system without having to set up an entire NFS cluster.
#
# Requirements:
#
# * Bash 4 or newer
# * Linux
# * sshfs (https://github.com/libfuse/sshfs)
# * sshd running locally
# * pgrep
function print_usage {
echo 'Usage: mount-slow-fs [SOURCE DIRECTORY] [MOUNTPOINT]'
exit 1
}
function main {
local os
local source_dir
local mountpoint
os="$(uname -s)"
source_dir="${1}"
mountpoint="${2}"
if [[ "${source_dir}" == "" || "${mountpoint}" == "" ]]
then
print_usage
fi
if [[ "${os,,}" != "linux" ]]
then
echo 'Only Linux is supported'
exit 1
fi
if ! test -d "${source_dir}"
then
print_usage
fi
if ! test -d "${mountpoint}"
then
print_usage
fi
if ! hash sshfs 2>/dev/null
then
echo 'sshfs is not installed'
exit 1
fi
if ! hash tc 2>/dev/null
then
echo 'The "tc" command could not be found'
exit 1
fi
if ! hash sudo 2>/dev/null
then
echo 'The "sudo" command could not be found'
exit 1
fi
if ! hash pgrep 2>/dev/null
then
echo 'The "pgrep" command could not be found'
exit 1
fi
if [[ "$(pgrep sshd)" == "" ]]
then
echo 'sshd does not appear to be running locally'
exit 1
fi
echo 'Delaying loopback interface, you may be prompted for your password...'
# This command may fail if no existing rules are present, in that case we'll
# just ignore the output.
sudo tc qdisc del dev lo root 2>/dev/null
sudo tc qdisc add dev lo root netem delay 2ms
echo "Mounting under ${mountpoint}, exit with ^C"
sshfs -o cache=no -f "${USER}@localhost:${source_dir}" "${mountpoint}"
echo 'Removing loopback delay, you may be prompted for your password...'
sudo tc qdisc del dev lo root
}
main "$@"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment