#!/bin/bash

clients=$1
jobs=$2
duration=$3
dir=$4

for scale in 100 1000 10000; do

	dropdb --if-exists test
	createdb test

	mkdir -p $dir/$scale

	pushd $dir/$scale

	psql -c 'select * from pg_settings' > settings.log 2>&1

	pgbench -i -s $scale test > init.log 2>&1

	psql test -c checkpoint > /dev/null 2>&1

	../../collect-stats.sh &
	pid=$!

	pgbench -c $clients -j $jobs -l -N --sampling-rate=0.05 -T $duration -M prepared test > bench.log 2>&1

	kill $pid

	pigz pgbench_log.*

	popd

done
