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

Commit5c71362

Browse files
author
Amit Kapila
committed
Allow parallel create index to accumulate buffer usage stats.
Currently, we don't account for buffer usage incurred by parallel workersfor parallel create index.  This commit allows each worker to record thebuffer usage stats and leader backend to accumulate that stats at theend of the operation.  This will allow pg_stat_statements to displaycorrect buffer usage stats for (parallel) create index command.Reported-by: Julien RouhaudAuthor: Sawada MasahikoReviewed-by: Dilip Kumar, Julien Rouhaud and Amit KapilaBackpatch-through: 11, where this was introducedDiscussion:https://postgr.es/m/20200328151721.GB12854@nol
1 parent58ad961 commit5c71362

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

‎src/backend/access/nbtree/nbtsort.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#definePARALLEL_KEY_TUPLESORT_SPOOL2UINT64CONST(0xA000000000000003)
7272
#definePARALLEL_KEY_QUERY_TEXTUINT64CONST(0xA000000000000004)
7373
#definePARALLEL_KEY_WAL_USAGEUINT64CONST(0xA000000000000005)
74+
#definePARALLEL_KEY_BUFFER_USAGEUINT64CONST(0xA000000000000006)
7475

7576
/*
7677
* DISABLE_LEADER_PARTICIPATION disables the leader's participation in
@@ -194,6 +195,7 @@ typedef struct BTLeader
194195
Sharedsort*sharedsort2;
195196
Snapshotsnapshot;
196197
WalUsage*walusage;
198+
BufferUsage*bufferusage;
197199
}BTLeader;
198200

199201
/*
@@ -1457,6 +1459,7 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
14571459
BTSpool*btspool=buildstate->spool;
14581460
BTLeader*btleader= (BTLeader*)palloc0(sizeof(BTLeader));
14591461
WalUsage*walusage;
1462+
BufferUsage*bufferusage;
14601463
boolleaderparticipates= true;
14611464
char*sharedquery;
14621465
intquerylen;
@@ -1510,16 +1513,19 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
15101513
}
15111514

15121515
/*
1513-
* Estimate space for WalUsage -- PARALLEL_KEY_WAL_USAGE
1516+
* Estimate space for WalUsage and BufferUsage -- PARALLEL_KEY_WAL_USAGE
1517+
* and PARALLEL_KEY_BUFFER_USAGE.
15141518
*
1515-
* WalUsage during execution of maintenance command can be used by an
1516-
* extension that reports the WAL usage, such as pg_stat_statements. We
1517-
* have no way of knowing whether anyone's looking at pgWalUsage, so do it
1518-
* unconditionally.
1519+
* If there are no extensions loaded that care, we could skip this. We
1520+
* have no way of knowing whether anyone's looking at pgWalUsage or
1521+
* pgBufferUsage, so do it unconditionally.
15191522
*/
15201523
shm_toc_estimate_chunk(&pcxt->estimator,
15211524
mul_size(sizeof(WalUsage),pcxt->nworkers));
15221525
shm_toc_estimate_keys(&pcxt->estimator,1);
1526+
shm_toc_estimate_chunk(&pcxt->estimator,
1527+
mul_size(sizeof(BufferUsage),pcxt->nworkers));
1528+
shm_toc_estimate_keys(&pcxt->estimator,1);
15231529

15241530
/* Finally, estimate PARALLEL_KEY_QUERY_TEXT space */
15251531
querylen=strlen(debug_query_string);
@@ -1592,10 +1598,16 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
15921598
memcpy(sharedquery,debug_query_string,querylen+1);
15931599
shm_toc_insert(pcxt->toc,PARALLEL_KEY_QUERY_TEXT,sharedquery);
15941600

1595-
/* Allocate space for each worker's WalUsage; no need to initialize */
1601+
/*
1602+
* Allocate space for each worker's WalUsage and BufferUsage; no need to
1603+
* initialize.
1604+
*/
15961605
walusage=shm_toc_allocate(pcxt->toc,
15971606
mul_size(sizeof(WalUsage),pcxt->nworkers));
15981607
shm_toc_insert(pcxt->toc,PARALLEL_KEY_WAL_USAGE,walusage);
1608+
bufferusage=shm_toc_allocate(pcxt->toc,
1609+
mul_size(sizeof(BufferUsage),pcxt->nworkers));
1610+
shm_toc_insert(pcxt->toc,PARALLEL_KEY_BUFFER_USAGE,bufferusage);
15991611

16001612
/* Launch workers, saving status for leader/caller */
16011613
LaunchParallelWorkers(pcxt);
@@ -1608,6 +1620,7 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
16081620
btleader->sharedsort2=sharedsort2;
16091621
btleader->snapshot=snapshot;
16101622
btleader->walusage=walusage;
1623+
btleader->bufferusage=bufferusage;
16111624

16121625
/* If no workers were successfully launched, back out (do serial build) */
16131626
if (pcxt->nworkers_launched==0)
@@ -1646,7 +1659,7 @@ _bt_end_parallel(BTLeader *btleader)
16461659
* or we might get incomplete data.)
16471660
*/
16481661
for (i=0;i<btleader->pcxt->nworkers_launched;i++)
1649-
InstrAccumParallelQuery(NULL,&btleader->walusage[i]);
1662+
InstrAccumParallelQuery(&btleader->bufferusage[i],&btleader->walusage[i]);
16501663

16511664
/* Free last reference to MVCC snapshot, if one was used */
16521665
if (IsMVCCSnapshot(btleader->snapshot))
@@ -1779,6 +1792,7 @@ _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc)
17791792
LOCKMODEheapLockmode;
17801793
LOCKMODEindexLockmode;
17811794
WalUsage*walusage;
1795+
BufferUsage*bufferusage;
17821796
intsortmem;
17831797

17841798
#ifdefBTREE_BUILD_STATS
@@ -1848,9 +1862,11 @@ _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc)
18481862
_bt_parallel_scan_and_sort(btspool,btspool2,btshared,sharedsort,
18491863
sharedsort2,sortmem, false);
18501864

1851-
/* Report WAL usage during parallel execution */
1865+
/* Report WAL/buffer usage during parallel execution */
1866+
bufferusage=shm_toc_lookup(toc,PARALLEL_KEY_BUFFER_USAGE, false);
18521867
walusage=shm_toc_lookup(toc,PARALLEL_KEY_WAL_USAGE, false);
1853-
InstrEndParallelQuery(NULL,&walusage[ParallelWorkerNumber]);
1868+
InstrEndParallelQuery(&bufferusage[ParallelWorkerNumber],
1869+
&walusage[ParallelWorkerNumber]);
18541870

18551871
#ifdefBTREE_BUILD_STATS
18561872
if (log_btree_build_stats)

‎src/backend/executor/instrument.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,8 @@ InstrStartParallelQuery(void)
188188
void
189189
InstrEndParallelQuery(BufferUsage*bufusage,WalUsage*walusage)
190190
{
191-
if (bufusage)
192-
{
193-
memset(bufusage,0,sizeof(BufferUsage));
194-
BufferUsageAccumDiff(bufusage,&pgBufferUsage,&save_pgBufferUsage);
195-
}
191+
memset(bufusage,0,sizeof(BufferUsage));
192+
BufferUsageAccumDiff(bufusage,&pgBufferUsage,&save_pgBufferUsage);
196193
memset(walusage,0,sizeof(WalUsage));
197194
WalUsageAccumDiff(walusage,&pgWalUsage,&save_pgWalUsage);
198195
}
@@ -201,8 +198,7 @@ InstrEndParallelQuery(BufferUsage *bufusage, WalUsage *walusage)
201198
void
202199
InstrAccumParallelQuery(BufferUsage*bufusage,WalUsage*walusage)
203200
{
204-
if (bufusage)
205-
BufferUsageAdd(&pgBufferUsage,bufusage);
201+
BufferUsageAdd(&pgBufferUsage,bufusage);
206202
WalUsageAdd(&pgWalUsage,walusage);
207203
}
208204

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp