On Tue, 2007-09-11 at 10:42 +0100, Simon Riggs wrote:
> 2. CountActiveBackends() searches the whole of the proc array, even
> though it could stop when it gets to commit_siblings. Stopping once the
> heuristic has been determined seems like the best thing to do. A small
> patch to implement this is attached.
backend/access/transam/xact.c | 2 !!
backend/storage/ipc/procarray.c | 11 !!!!!!!!!!!
include/storage/procarray.h | 2 !!
3 files changed, 15 modifications(!)
--
Simon Riggs
2ndQuadrant http://www.2ndQuadrant.com
Index: src/backend/access/transam/xact.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/access/transam/xact.c,v
retrieving revision 1.250
diff -c -r1.250 xact.c
*** src/backend/access/transam/xact.c 8 Sep 2007 20:31:14 -0000 1.250
--- src/backend/access/transam/xact.c 11 Sep 2007 13:11:33 -0000
***************
*** 886,892 ****
* active transactions.
*/
if (CommitDelay > 0 && enableFsync &&
! CountActiveBackends() >= CommitSiblings)
pg_usleep(CommitDelay);
XLogFlush(XactLastRecEnd);
--- 886,892 ----
* active transactions.
*/
if (CommitDelay > 0 && enableFsync &&
! NumActiveBackendsIsAtLeast(CommitSiblings))
pg_usleep(CommitDelay);
XLogFlush(XactLastRecEnd);
Index: src/backend/storage/ipc/procarray.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/storage/ipc/procarray.c,v
retrieving revision 1.33
diff -c -r1.33 procarray.c
*** src/backend/storage/ipc/procarray.c 8 Sep 2007 20:31:15 -0000 1.33
--- src/backend/storage/ipc/procarray.c 11 Sep 2007 13:11:35 -0000
***************
*** 1016,1030 ****
/*
! * CountActiveBackends --- count backends (other than myself) that are in
* active transactions. This is used as a heuristic to decide if
* a pre-XLOG-flush delay is worthwhile during commit.
*
* Do not count backends that are blocked waiting for locks, since they are
* not going to get to run until someone else commits.
*/
! int
! CountActiveBackends(void)
{
ProcArrayStruct *arrayP = procArray;
int count = 0;
--- 1016,1030 ----
/*
! * NumActiveBackendsIsAtLeast --- count backends (other than myself) that are in
* active transactions. This is used as a heuristic to decide if
* a pre-XLOG-flush delay is worthwhile during commit.
*
* Do not count backends that are blocked waiting for locks, since they are
* not going to get to run until someone else commits.
*/
! bool
! NumActiveBackendsIsAtLeast(int MinBackends)
{
ProcArrayStruct *arrayP = procArray;
int count = 0;
***************
*** 1047,1056 ****
continue; /* do not count if no XID assigned */
if (proc->waitLock != NULL)
continue; /* do not count if blocked on a lock */
! count++;
}
! return count;
}
/*
--- 1047,1057 ----
continue; /* do not count if no XID assigned */
if (proc->waitLock != NULL)
continue; /* do not count if blocked on a lock */
! if (++count >= MinBackends)
! return true;
}
! return false;
}
/*
Index: src/include/storage/procarray.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/storage/procarray.h,v
retrieving revision 1.17
diff -c -r1.17 procarray.h
*** src/include/storage/procarray.h 8 Sep 2007 20:31:15 -0000 1.17
--- src/include/storage/procarray.h 11 Sep 2007 13:11:38 -0000
***************
*** 38,44 ****
extern VirtualTransactionId *GetCurrentVirtualXIDs(TransactionId limitXmin,
bool allDbs);
! extern int CountActiveBackends(void);
extern int CountDBBackends(Oid databaseid);
extern int CountUserBackends(Oid roleid);
extern bool CheckOtherDBBackends(Oid databaseId);
--- 38,44 ----
extern VirtualTransactionId *GetCurrentVirtualXIDs(TransactionId limitXmin,
bool allDbs);
! extern bool NumActiveBackendsIsAtLeast(int MinBackends);
extern int CountDBBackends(Oid databaseid);
extern int CountUserBackends(Oid roleid);
extern bool CheckOtherDBBackends(Oid databaseId);
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq