2014-12-08 18:05:44 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
# Benchmark EncFS against eCryptfs
|
|
|
|
|
|
|
|
use File::Temp;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
require("tests/common.pl");
|
|
|
|
|
|
|
|
# Create a new empty working directory
|
|
|
|
sub newWorkingDir {
|
|
|
|
my $prefix = shift;
|
|
|
|
my $workingDir = mkdtemp("$prefix/encfs-performance-XXXX")
|
|
|
|
|| die("Could not create temporary directory");
|
|
|
|
|
|
|
|
return $workingDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub cleanup {
|
|
|
|
print "cleaning up...";
|
|
|
|
my $workingDir = shift;
|
|
|
|
system("umount $workingDir/ecryptfs_plaintext");
|
|
|
|
system("fusermount -u $workingDir/encfs_plaintext");
|
|
|
|
system("rm -Rf $workingDir");
|
|
|
|
print "done\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mount_encfs {
|
|
|
|
my $workingDir = shift;
|
|
|
|
|
|
|
|
my $c = "$workingDir/encfs_ciphertext";
|
|
|
|
my $p = "$workingDir/encfs_plaintext";
|
|
|
|
|
|
|
|
mkdir($c);
|
|
|
|
mkdir($p);
|
|
|
|
|
|
|
|
delete $ENV{"ENCFS6_CONFIG"};
|
2015-11-12 19:08:52 +01:00
|
|
|
system("./build/encfs --extpass=\"echo test\" --standard $c $p > /dev/null");
|
2014-12-08 18:05:44 +01:00
|
|
|
waitForFile("$c/.encfs6.xml") or die("Control file not created");
|
|
|
|
|
|
|
|
print "# encfs mounted on $p\n";
|
|
|
|
|
|
|
|
return $p;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mount_ecryptfs {
|
2014-12-14 16:59:47 +01:00
|
|
|
|
|
|
|
if(system("which mount.ecryptfs > /dev/null") != 0) {
|
|
|
|
print "skipping ecryptfs\n";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2014-12-08 18:05:44 +01:00
|
|
|
my $workingDir = shift;
|
|
|
|
|
|
|
|
my $c = "$workingDir/ecryptfs_ciphertext";
|
|
|
|
my $p = "$workingDir/ecryptfs_plaintext";
|
|
|
|
|
|
|
|
mkdir($c);
|
|
|
|
mkdir($p);
|
|
|
|
|
|
|
|
system("expect -c \"spawn mount -t ecryptfs $c $p\" ./tests/mount-ecryptfs.expect > /dev/null") == 0
|
|
|
|
or die("ecryptfs mount failed - are you root?");
|
|
|
|
|
|
|
|
print "# ecryptfs mounted on $p\n";
|
|
|
|
|
|
|
|
return $p;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub benchmark {
|
|
|
|
my $dir = shift;
|
|
|
|
our $linuxgz;
|
|
|
|
|
|
|
|
my @results = ();
|
|
|
|
|
|
|
|
system("sync");
|
2014-12-14 16:59:47 +01:00
|
|
|
stopwatch_start("stream_write");
|
|
|
|
writeZeroes( "$dir/zero", 1024 * 1024 * 100 );
|
|
|
|
system("sync");
|
|
|
|
stopwatch_stop(\@results);
|
2014-12-08 18:05:44 +01:00
|
|
|
unlink("$dir/zero");
|
|
|
|
|
|
|
|
system("sync");
|
|
|
|
system("cat $linuxgz > /dev/null");
|
2014-12-14 16:59:47 +01:00
|
|
|
stopwatch_start("extract");
|
|
|
|
system("tar xzf $linuxgz -C $dir");
|
|
|
|
system("sync");
|
|
|
|
stopwatch_stop(\@results);
|
2014-12-08 18:05:44 +01:00
|
|
|
|
|
|
|
$du = qx(du -sm $dir | cut -f1);
|
2014-12-14 16:59:47 +01:00
|
|
|
push( @results, [ 'du', $du, 'MiB' ] );
|
|
|
|
printf( "# disk space used: %d MiB\n", $du );
|
2014-12-08 18:05:44 +01:00
|
|
|
|
|
|
|
system("echo 3 > /proc/sys/vm/drop_caches");
|
2014-12-14 16:59:47 +01:00
|
|
|
stopwatch_start("rsync");
|
2014-12-27 14:52:32 +01:00
|
|
|
system("rsync -an $dir $dir/empty-rsync-target");
|
2014-12-14 16:59:47 +01:00
|
|
|
stopwatch_stop(\@results);
|
2014-12-08 18:05:44 +01:00
|
|
|
|
|
|
|
system("echo 3 > /proc/sys/vm/drop_caches");
|
|
|
|
system("sync");
|
2014-12-14 16:59:47 +01:00
|
|
|
stopwatch_start("rm");
|
|
|
|
system("rm -Rf $dir/*");
|
|
|
|
system("sync");
|
|
|
|
stopwatch_stop(\@results);
|
2014-12-08 18:05:44 +01:00
|
|
|
|
|
|
|
return \@results;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub tabulate {
|
|
|
|
my $r;
|
|
|
|
|
|
|
|
$r = shift;
|
|
|
|
my @encfs = @{$r};
|
|
|
|
$r = shift;
|
2014-12-14 16:59:47 +01:00
|
|
|
my @ecryptfs;
|
|
|
|
if($r) {
|
|
|
|
@ecryptfs = @{$r};
|
|
|
|
}
|
2014-12-08 18:05:44 +01:00
|
|
|
|
2014-12-08 19:34:50 +01:00
|
|
|
print " Test | EncFS | eCryptfs | EncFS advantage\n";
|
|
|
|
print ":---------------|-------------:|-------------:|---------------:\n";
|
2014-12-08 18:05:44 +01:00
|
|
|
|
|
|
|
for ( my $i = 0 ; $i <= $#encfs ; $i++ ) {
|
|
|
|
my $test = $encfs[$i][0];
|
|
|
|
my $unit = $encfs[$i][2];
|
|
|
|
|
|
|
|
my $en = $encfs[$i][1];
|
2014-12-14 16:59:47 +01:00
|
|
|
my $ec = 0;
|
|
|
|
my $ratio = 0;
|
|
|
|
|
|
|
|
if( @ecryptfs ) {
|
|
|
|
$ec = $ecryptfs[$i][1];
|
|
|
|
$ratio = $ec / $en;
|
|
|
|
if ( $unit =~ m!/s! ) {
|
|
|
|
$ratio = $en / $ec;
|
|
|
|
}
|
2014-12-08 18:05:44 +01:00
|
|
|
}
|
2014-12-14 16:59:47 +01:00
|
|
|
|
2014-12-08 18:05:44 +01:00
|
|
|
printf( "%-15s | %6d %-5s | %6d %-5s | %2.2f\n",
|
|
|
|
$test, $en, $unit, $ec, $unit, $ratio );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub main {
|
|
|
|
if ( $#ARGV < 0 ) {
|
2014-12-27 14:52:32 +01:00
|
|
|
print "Usage: test/benchmark.pl DIR1 [DIR2] [...]\n";
|
|
|
|
print "\n";
|
|
|
|
print "Arguments:\n";
|
|
|
|
print " DIRn ... Working directory. This is where the encrypted files\n";
|
|
|
|
print " are stored. Specifying multiple directories will run\n";
|
|
|
|
print " the benchmark in each.\n";
|
|
|
|
print "\n";
|
|
|
|
print "For details about the testcases see PERFORMANCE.md.\n";
|
|
|
|
|
2014-12-08 18:05:44 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $> != 0 ) {
|
|
|
|
print("This test must be run as root!\n");
|
|
|
|
}
|
|
|
|
|
2015-03-22 15:53:25 +01:00
|
|
|
dl_linuxgz();
|
2014-12-08 18:05:44 +01:00
|
|
|
my $workingDir;
|
|
|
|
my $mountpoint;
|
|
|
|
my $prefix;
|
|
|
|
|
|
|
|
while ( $prefix = shift(@ARGV) ) {
|
|
|
|
$workingDir = newWorkingDir($prefix);
|
|
|
|
|
|
|
|
print "# mounting encfs\n";
|
|
|
|
$mountpoint = mount_encfs($workingDir);
|
|
|
|
my $encfs_results = benchmark($mountpoint);
|
|
|
|
|
|
|
|
print "# mounting ecryptfs\n";
|
|
|
|
$mountpoint = mount_ecryptfs($workingDir);
|
2014-12-14 16:59:47 +01:00
|
|
|
my $ecryptfs_results;
|
|
|
|
if($mountpoint) {
|
|
|
|
$ecryptfs_results = benchmark($mountpoint);
|
|
|
|
}
|
2014-12-08 18:05:44 +01:00
|
|
|
|
|
|
|
cleanup($workingDir);
|
|
|
|
|
|
|
|
print "\nResults for $prefix\n";
|
|
|
|
print "==============================\n\n";
|
|
|
|
tabulate( $encfs_results, $ecryptfs_results );
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|