root@pgload05g ~/tmp/postgresql # git branch
* master
root@pgload05g ~/tmp/postgresql # git rev-parse HEAD
2195c5afaabd4d794c8bbf1bf10d8e4fe54b6145
root@pgload05g ~/tmp/postgresql # cat bisect_test.sh
#!/bin/bash

su - postgres -c "/usr/lib/postgresql/9.6/bin/pg_ctl -D /dev/shm/pg/9.6/ stop -m fast" >/dev/null 2>&1 || true
rm -rf /dev/shm/pg/9.6/*

./configure --prefix=/usr/lib/postgresql/9.6 --enable-debug >/dev/null || exit 125
make clean >/dev/null || exit 125
make -j 32 >/dev/null 2>&1 || exit 125
make install >/dev/null || exit 125
make -j 32 -C contrib >/dev/null 2>&1 || exit 125
make -C contrib install >/dev/null || exit 125

su - postgres -c "/usr/lib/postgresql/9.6/bin/initdb -D /dev/shm/pg/9.6/" >/dev/null 2>&1 || exit 125
echo "local   all             all                                     trust" >/dev/shm/pg/9.6/pg_hba.conf
echo "host    all             all             127.0.0.1/32            trust" >>/dev/shm/pg/9.6/pg_hba.conf
echo "host    all             all             ::1/128                 trust" >>/dev/shm/pg/9.6/pg_hba.conf

su - postgres -c '/usr/lib/postgresql/9.6/bin/pg_ctl -D /dev/shm/pg/9.6/ -o "-p 5434" start' >/dev/null 2>&1 || exit 125
sleep 3
su - postgres -c "/usr/lib/postgresql/9.6/bin/pgbench -i -s 100 'host=localhost port=6432 dbname=pg96'" >/dev/null 2>&1 || exit 125
sleep 3
TPS=`su - postgres -c "/usr/lib/postgresql/9.5/bin/pgbench -U postgres -T 60 -j 64 -c 64 -S -n 'host=localhost port=6432 dbname=pg96'" | awk '/excluding connections establishing/ {print $3}' | cut -f1 -d\.`
REV=`git rev-parse --short HEAD`
echo "$REV $TPS" >>/tmp/bisect96.log

if [ "$TPS" -lt 55000 ]; then
    exit 0
else
    exit 1
fi
root@pgload05g ~/tmp/postgresql # git bisect run ./bisect_test.sh
running ./bisect_test.sh
Bisecting: 455 revisions left to test after this (roughly 9 steps)
[7caaeaf3607fae91318f24debce3dc017ca299a3] Link libpq after libpgfeutils to satisfy Windows linker.
running ./bisect_test.sh
Bisecting: 227 revisions left to test after this (roughly 8 steps)
[9def031bd2821f35b5f506260d922482648a8bb0] Add more tests for commit_timestamp feature
running ./bisect_test.sh
Bisecting: 113 revisions left to test after this (roughly 7 steps)
[e01157500f26342bf4f067a4eb1e45ab9a3cd410] Include portability/mem.h into fd.c for MAP_FAILED.
running ./bisect_test.sh
Bisecting: 56 revisions left to test after this (roughly 6 steps)
[61d2ebdbf9155d80f83281d8c5729c8f8f0949bc] Fix a typo
running ./bisect_test.sh
Bisecting: 28 revisions left to test after this (roughly 5 steps)
[b6afae71aaf6d2df76d0a0a77c8b630220a01ec1] Use %option bison-bridge in psql/pgbench lexers.
running ./bisect_test.sh
Bisecting: 14 revisions left to test after this (roughly 4 steps)
[384dfbde19330541f7fb487f9352949aa06c812e] Fix unsafe use of strtol() on a non-null-terminated Text datum.
running ./bisect_test.sh
Bisecting: 6 revisions left to test after this (roughly 3 steps)
[92b7902deb3155f6975f33e8b6c8be4d9d066172] Clean up some Coverity complaints about commit 0bf3ae88af330496.
running ./bisect_test.sh
Bisecting: 6 revisions left to test after this (roughly 3 steps)
[98a64d0bd713cb89e61bef6432befc4b7b5da59e] Introduce WaitEventSet API.
running ./bisect_test.sh
Bisecting: 1 revision left to test after this (roughly 1 step)
[326d73c86fda407a810675c3b5a48e0a0cc992f5] Second attempt at fixing MSVC build for 68ab8e8ba4a471d9.
running ./bisect_test.sh
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[72e2d21c1249b674496f97cd6009c0bda62f6b4d] Combine win32 and unix latch implementations.
running ./bisect_test.sh
98a64d0bd713cb89e61bef6432befc4b7b5da59e is the first bad commit
commit 98a64d0bd713cb89e61bef6432befc4b7b5da59e
Author: Andres Freund <andres@anarazel.de>
Date:   Mon Mar 21 09:56:39 2016 +0100

    Introduce WaitEventSet API.

    Commit ac1d794 ("Make idle backends exit if the postmaster dies.")
    introduced a regression on, at least, large linux systems. Constantly
    adding the same postmaster_alive_fds to the OSs internal datastructures
    for implementing poll/select can cause significant contention; leading
    to a performance regression of nearly 3x in one example.

    This can be avoided by using e.g. linux' epoll, which avoids having to
    add/remove file descriptors to the wait datastructures at a high rate.
    Unfortunately the current latch interface makes it hard to allocate any
    persistent per-backend resources.

    Replace, with a backward compatibility layer, WaitLatchOrSocket with a
    new WaitEventSet API. Users can allocate such a Set across multiple
    calls, and add more than one file-descriptor to wait on. The latter has
    been added because there's upcoming postgres features where that will be
    helpful.

    In addition to the previously existing poll(2), select(2),
    WaitForMultipleObjects() implementations also provide an epoll_wait(2)
    based implementation to address the aforementioned performance
    problem. Epoll is only available on linux, but that is the most likely
    OS for machines large enough (four sockets) to reproduce the problem.

    To actually address the aforementioned regression, create and use a
    long-lived WaitEventSet for FE/BE communication.  There are additional
    places that would benefit from a long-lived set, but that's a task for
    another day.

    Thanks to Amit Kapila, who helped make the windows code I blindly wrote
    actually work.

    Reported-By: Dmitry Vasilyev Discussion:
    CAB-SwXZh44_2ybvS5Z67p_CDz=XFn4hNAD=CnMEF+QqkXwFrGg@mail.gmail.com
    20160114143931.GG10941@awork2.anarazel.de

:100755 100755 c10d9549a40951293f16ff058bf077bcddd0bb99 24655dc09614ee72f882abad90a0d071a1e5f51e M  configure
:100644 100644 47d0f584deda36025cdf0f83252e5976986531e9 c564a7695fa917e664f5c5676c8dc95468fad4e5 M  configure.in
:040000 040000 3e57535f13f005a4b8e4e606cab91b1f93cad048 b9d1d96a88cd9cfd0ad0a6f98cd36938762bfb57 M  src
bisect run success
root@pgload05g ~/tmp/postgresql # cat /tmp/bisect96.log
65c5fcd 35783
7caaeaf 71532
9def031 36279
e011575 36386
61d2ebd 35791
b6afae7 35288
384dfbd 71557
98a64d0 70223
326d73c 35029
72e2d21 33649
root@pgload05g ~/tmp/postgresql #
