mirror of
https://github.com/postgres/postgres.git
synced 2025-06-01 14:21:49 +03:00
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.
This commit is contained in:
parent
51d152f18e
commit
bc7fcab5e3
@ -359,14 +359,20 @@ gather_readnext(GatherState *gatherstate)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Advance nextreader pointer in round-robin fashion. */
|
|
||||||
gatherstate->nextreader =
|
|
||||||
(gatherstate->nextreader + 1) % gatherstate->nreaders;
|
|
||||||
|
|
||||||
/* If we got a tuple, return it. */
|
/* If we got a tuple, return it. */
|
||||||
if (tup)
|
if (tup)
|
||||||
return tup;
|
return tup;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Advance nextreader pointer in round-robin fashion. Note that we
|
||||||
|
* only reach this code if we weren't able to get a tuple from the
|
||||||
|
* current worker. We used to advance the nextreader pointer after
|
||||||
|
* every tuple, but it turns out to be much more efficient to keep
|
||||||
|
* reading from the same queue until that would require blocking.
|
||||||
|
*/
|
||||||
|
gatherstate->nextreader =
|
||||||
|
(gatherstate->nextreader + 1) % gatherstate->nreaders;
|
||||||
|
|
||||||
/* Have we visited every TupleQueueReader? */
|
/* Have we visited every TupleQueueReader? */
|
||||||
if (gatherstate->nextreader == waitpos)
|
if (gatherstate->nextreader == waitpos)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user