Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9c99365

Browse files
committed
Implement COMMIT_SIBLINGS parameter to allow pre-commit delay to occur
only if at least N other backends currently have open transactions. Thisis not a great deal of intelligence about whether a delay might beprofitable ... but it beats no intelligence at all. Note that the defaultCOMMIT_DELAY is still zero --- this new code does nothing unless thatsetting is changed.Also, mark ENABLEFSYNC as a system-wide setting. It's no longer safe toallow that to be set per-backend, since we may be relying on some otherbackend's fsync to have synced the WAL log.
1 parent60774e8 commit9c99365

File tree

10 files changed

+94
-31
lines changed

10 files changed

+94
-31
lines changed

‎doc/src/sgml/wal.sgml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/wal.sgml,v 1.2 2001/02/18 04:50:43 tgl Exp $ -->
1+
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/wal.sgml,v 1.3 2001/02/26 00:50:07 tgl Exp $ -->
22

33
<chapter id="wal">
44
<title>Write-Ahead Logging (<acronym>WAL</acronym>)</title>
@@ -295,10 +295,13 @@
295295
record to the log with <function>LogInsert</function> but before
296296
performing a <function>LogFlush</function>. This delay allows other
297297
backends to add their commit records to the log so as to have all
298-
of them flushed with a single log sync. Unfortunately, this
299-
mechanism is not fully implemented at release 7.1, so there is at
300-
present usually no benefit to be gained from increasing this parameter
301-
above its default value of zero.
298+
of them flushed with a single log sync. No sleep will occur if fsync
299+
is not enabled or if fewer than <varname>COMMIT_SIBLINGS</varname>
300+
other backends are not currently in active transactions; this avoids
301+
sleeping when it's unlikely that any other backend will commit soon.
302+
Note that on most platforms, the resolution of a sleep request is
303+
ten milliseconds, so that any nonzero <varname>COMMIT_DELAY</varname>
304+
setting between 1 and 10000 microseconds will have the same effect.
302305
</para>
303306
</sect1>
304307
</chapter>

‎src/backend/access/transam/xact.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.97 2001/02/18 04:50:43 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.98 2001/02/26 00:50:07 tgl Exp $
1212
*
1313
* NOTES
1414
*Transaction aborts can now occur two ways:
@@ -157,6 +157,7 @@
157157
#include<sys/time.h>
158158

159159
#include"access/nbtree.h"
160+
#include"access/xact.h"
160161
#include"catalog/heap.h"
161162
#include"catalog/index.h"
162163
#include"commands/async.h"
@@ -177,8 +178,6 @@
177178

178179
externboolSharedBufferChanged;
179180

180-
voidRecordTransactionCommit(void);
181-
182181
staticvoidAbortTransaction(void);
183182
staticvoidAtAbort_Cache(void);
184183
staticvoidAtAbort_Locks(void);
@@ -216,12 +215,14 @@ TransactionStateData CurrentTransactionStateData = {
216215

217216
TransactionStateCurrentTransactionState=&CurrentTransactionStateData;
218217

218+
/*
219+
* User-tweakable parameters
220+
*/
219221
intDefaultXactIsoLevel=XACT_READ_COMMITTED;
220222
intXactIsoLevel;
221223

222-
#include"access/xlogutils.h"
223-
224-
intCommitDelay=0;/* in microseconds */
224+
intCommitDelay=0;/* precommit delay in microseconds */
225+
intCommitSiblings=5;/* number of concurrent xacts needed to sleep */
225226

226227
staticvoid (*_RollbackFunc)(void*)=NULL;
227228
staticvoid*_RollbackData=NULL;
@@ -687,10 +688,15 @@ RecordTransactionCommit()
687688
* Sleep before commit! So we can flush more than one
688689
* commit records per single fsync. (The idea is some other
689690
* backend may do the XLogFlush while we're sleeping. This
690-
* needs workhowever, because on most Unixen, the minimum
691+
* needs workstill, because on most Unixen, the minimum
691692
* select() delay is 10msec or more, which is way too long.)
693+
*
694+
* We do not sleep if enableFsync is not turned on, nor if there
695+
* are fewer than CommitSiblings other backends with active
696+
* transactions.
692697
*/
693-
if (CommitDelay>0)
698+
if (CommitDelay>0&&enableFsync&&
699+
CountActiveBackends() >=CommitSiblings)
694700
{
695701
structtimevaldelay;
696702

‎src/backend/access/transam/xlog.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.54 2001/02/18 04:39:42 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.55 2001/02/26 00:50:07 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -2096,8 +2096,6 @@ ShutdownXLOG()
20962096
elog(LOG,"database system is shut down");
20972097
}
20982098

2099-
externXLogRecPtrGetUndoRecPtr(void);
2100-
21012099
void
21022100
CreateCheckPoint(boolshutdown)
21032101
{

‎src/backend/storage/ipc/sinval.c

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.25 2001/01/24 19:43:07momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.26 2001/02/26 00:50:07tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
15-
/* #define INVALIDDEBUG 1 */
15+
#include"postgres.h"
1616

1717
#include<sys/types.h>
1818

19-
#include"postgres.h"
20-
2119
#include"storage/backendid.h"
2220
#include"storage/proc.h"
2321
#include"storage/sinval.h"
@@ -348,10 +346,53 @@ GetSnapshotData(bool serializable)
348346
}
349347

350348
/*
351-
* GetUndoRecPtr -- returns oldest PROC->logRec.
349+
* CountActiveBackends --- count backends (other than myself) that are in
350+
*active transactions. This is used as a heuristic to decide if
351+
*a pre-XLOG-flush delay is worthwhile during commit.
352+
*
353+
* An active transaction is something that has written at least one XLOG
354+
* record; read-only transactions don't count. Also, do not count backends
355+
* that are blocked waiting for locks, since they are not going to get to
356+
* run until someone else commits.
352357
*/
353-
XLogRecPtrGetUndoRecPtr(void);
358+
int
359+
CountActiveBackends(void)
360+
{
361+
SISeg*segP=shmInvalBuffer;
362+
ProcState*stateP=segP->procState;
363+
intcount=0;
364+
intindex;
354365

366+
/*
367+
* Note: for speed, we don't acquire SInvalLock. This is a little bit
368+
* bogus, but since we are only testing xrecoff for zero or nonzero,
369+
* it should be OK. The result is only used for heuristic purposes
370+
* anyway...
371+
*/
372+
for (index=0;index<segP->lastBackend;index++)
373+
{
374+
SHMEM_OFFSETpOffset=stateP[index].procStruct;
375+
376+
if (pOffset!=INVALID_OFFSET)
377+
{
378+
PROC*proc= (PROC*)MAKE_PTR(pOffset);
379+
380+
if (proc==MyProc)
381+
continue;/* do not count myself */
382+
if (proc->logRec.xrecoff==0)
383+
continue;/* do not count if not in a transaction */
384+
if (proc->waitLock!=NULL)
385+
continue;/* do not count if blocked on a lock */
386+
count++;
387+
}
388+
}
389+
390+
returncount;
391+
}
392+
393+
/*
394+
* GetUndoRecPtr -- returns oldest PROC->logRec.
395+
*/
355396
XLogRecPtr
356397
GetUndoRecPtr(void)
357398
{

‎src/backend/utils/misc/guc.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Support for grand unified configuration scheme, including SET
55
* command, configuration file, and command line options.
66
*
7-
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.30 2001/02/18 04:50:43 tgl Exp $
7+
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.31 2001/02/26 00:50:07 tgl Exp $
88
*
99
* Copyright 2000 by PostgreSQL Global Development Group
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
@@ -41,6 +41,7 @@ extern int XLOGbuffers;
4141
externintXLOGfiles;
4242
externintXLOG_DEBUG;
4343
externintCommitDelay;
44+
externintCommitSiblings;
4445

4546
externboolFixBTree;
4647

@@ -181,7 +182,7 @@ ConfigureNamesBool[] =
181182

182183
{"tcpip_socket",PGC_POSTMASTER,&NetServer, false},
183184
{"ssl",PGC_POSTMASTER,&EnableSSL, false},
184-
{"fsync",PGC_USERSET,&enableFsync, true},
185+
{"fsync",PGC_SIGHUP,&enableFsync, true},
185186
{"silent_mode",PGC_POSTMASTER,&SilentMode, false},
186187

187188
{"log_connections",PGC_SIGHUP,&Log_connections, false},
@@ -279,7 +280,7 @@ ConfigureNamesInt[] =
279280
0777,0000,0777},
280281

281282
{"checkpoint_timeout",PGC_POSTMASTER,&CheckPointTimeout,
282-
300,30,1800},
283+
300,30,3600},
283284

284285
{"wal_buffers",PGC_POSTMASTER,&XLOGbuffers,
285286
8,4,INT_MAX},
@@ -293,6 +294,9 @@ ConfigureNamesInt[] =
293294
{"commit_delay",PGC_USERSET,&CommitDelay,
294295
0,0,100000},
295296

297+
{"commit_siblings",PGC_USERSET,&CommitSiblings,
298+
5,1,1000},
299+
296300
{NULL,0,NULL,0,0,0}
297301
};
298302

‎src/backend/utils/misc/postgresql.conf.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@
109109
#wal_files = 0 # range 0-64
110110
#wal_debug = 0 # range 0-16
111111
#commit_delay = 0 # range 0-100000
112-
#checkpoint_timeout = 300 # range 30-1800
112+
#commit_siblings = 5 # range 1-1000
113+
#checkpoint_timeout = 300 # in seconds, range 30-3600
113114

114115

115116
#

‎src/bin/psql/tab-complete.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.26 2001/02/10 02:31:28 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.27 2001/02/26 00:50:07 tgl Exp $
77
*/
88

99
/*----------------------------------------------------------------------
@@ -241,6 +241,7 @@ psql_completion(char *text, int start, int end)
241241
"debug_level",
242242
"max_expr_depth",
243243
"commit_delay",
244+
"commit_siblings",
244245

245246
"effective_cache_size",
246247
"random_page_cost",

‎src/include/access/xlog.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* PostgreSQL transaction log manager
55
*
6-
* $Header: /cvsroot/pgsql/src/include/access/xlog.h,v 1.17 2001/01/14 05:08:16 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/include/access/xlog.h,v 1.18 2001/02/26 00:50:07 tgl Exp $
77
*/
88
#ifndefXLOG_H
99
#defineXLOG_H
@@ -146,4 +146,9 @@ extern void ShutdownXLOG(void);
146146
externvoidCreateCheckPoint(boolshutdown);
147147
externvoidSetThisStartUpID(void);
148148

149+
/* in storage/ipc/sinval.c, but don't want to declare in sinval.h because
150+
* we'd have to include xlog.h into that ...
151+
*/
152+
externXLogRecPtrGetUndoRecPtr(void);
153+
149154
#endif/* XLOG_H */

‎src/include/storage/proc.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: proc.h,v 1.39 2001/01/25 03:31:16 tgl Exp $
10+
* $Id: proc.h,v 1.40 2001/02/26 00:50:08 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -50,6 +50,10 @@ struct proc
5050
* were starting our xact: vacuum must not
5151
* remove tuples deleted by xid >= xmin ! */
5252

53+
/* XLOG location of first XLOG record written by this backend's current
54+
* transaction. If backend is not in a transaction or hasn't yet modified
55+
* anything, logRec.xrecoff is zero.
56+
*/
5357
XLogRecPtrlogRec;
5458

5559
/* Info about lock the process is currently waiting for, if any. */

‎src/include/storage/sinval.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: sinval.h,v 1.17 2001/01/24 19:43:28 momjian Exp $
10+
* $Id: sinval.h,v 1.18 2001/02/26 00:50:08 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -30,6 +30,6 @@ extern void InvalidateSharedInvalid(void (*invalFunction) (),
3030
externboolDatabaseHasActiveBackends(OiddatabaseId,boolignoreMyself);
3131
externboolTransactionIdIsInProgress(TransactionIdxid);
3232
externvoidGetXmaxRecent(TransactionId*XmaxRecent);
33-
33+
externintCountActiveBackends(void);
3434

3535
#endif/* SINVAL_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp