Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bc7fcab

Browse files
committed
Read from the same worker repeatedly until it returns no tuple.
The original coding read tuples from workers in round-robin fashion, but performance testing shows that it works much better to read enough to empty one queue before moving on to the next. I believe the reason for this is that, with the old approach, we could easily wake up a worker repeatedly to write only one new tuple into the shm_mq each time. With this approach, by the time the process gets scheduled, it has a decent chance of being able to fill the entire buffer in one go. Patch by me. Dilip Kumar helped with performance testing.
1 parent 51d152f commit bc7fcab

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/backend/executor/nodeGather.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,20 @@ gather_readnext(GatherState *gatherstate)
359359
continue;
360360
}
361361

362-
/* Advance nextreader pointer in round-robin fashion. */
363-
gatherstate->nextreader =
364-
(gatherstate->nextreader + 1) % gatherstate->nreaders;
365-
366362
/* If we got a tuple, return it. */
367363
if (tup)
368364
return tup;
369365

366+
/*
367+
* Advance nextreader pointer in round-robin fashion. Note that we
368+
* only reach this code if we weren't able to get a tuple from the
369+
* current worker. We used to advance the nextreader pointer after
370+
* every tuple, but it turns out to be much more efficient to keep
371+
* reading from the same queue until that would require blocking.
372+
*/
373+
gatherstate->nextreader =
374+
(gatherstate->nextreader + 1) % gatherstate->nreaders;
375+
370376
/* Have we visited every TupleQueueReader? */
371377
if (gatherstate->nextreader == waitpos)
372378
{

0 commit comments

Comments
 (0)