PGWORKSPACE=/home/ubuntu/postgres/inst/bin
echo $PGWORKSPACE

killall -9 postgres
$PGWORKSPACE/pg_ctl -D $PGWORKSPACE/data -l $PGWORKSPACE/logfile stop
rm -rf inst/
make distclean
./configure --prefix=$PWD/inst/ CFLAGS="-O3" > install.log && make -j 8 install > install.log 2>&1 &

free -m
sudo su -c 'sync; echo 3 > /proc/sys/vm/drop_caches'
free -m

$PGWORKSPACE/initdb -D $PGWORKSPACE/data

cat << EOF >> $PGWORKSPACE/data/postgresql.conf
max_wal_size=64GB
checkpoint_timeout=1d
shared_buffers=8GB
max_connections=5000
EOF

ulimit -S -n 5000

$PGWORKSPACE/pg_ctl -D $PGWORKSPACE/data -l $PGWORKSPACE/logfile start

rm -rf $PGWORKSPACE/wiscript.sql
cat << EOF >> $PGWORKSPACE/wiscript.sql
SELECT pg_logical_emit_message(true, 'mymessage', repeat('d', 16));
EOF

for c in 1 2 4 8 16 32 64 128 256 512 768 1024 2048 4096; do echo -n "$c ";$PGWORKSPACE/pgbench -n postgres -c$c -j$c -t1000 -f $PGWORKSPACE/wiscript.sql 2>&1|grep '^tps'|awk '{print $3}';done




