Обсуждение: HaveNFreeProcs() iterates through entire freeProcs list

Поиск
Список
Период
Сортировка

HaveNFreeProcs() iterates through entire freeProcs list

От
Jim Nasby
Дата:
Current HaveNFreeProcs() iterates through the entire freeProcs list 
(while holding ProcStructLock) just to determine if there's a small 
number (superuser_reserved_connections) of free slots available. For the 
common case, presumably it'd be faster to put the n<=0 test inside the 
loop and return as soon as that's true, instead of waiting until the end?

BTW, the comment certainly doesn't seem accurate for the current code, 
since performance will be determined entirely by the number of procs on 
freeProcs...

/* * Check whether there are at least N free PGPROC objects. * * Note: this is designed on the assumption that N will
generallybe small. */
 
bool
HaveNFreeProcs(int n)
{PGPROC       *proc;
SpinLockAcquire(ProcStructLock);
proc = ProcGlobal->freeProcs;
while (n > 0 && proc != NULL){    proc = (PGPROC *) proc->links.next;    n--;}
SpinLockRelease(ProcStructLock);
return (n <= 0);
}
-- 
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
855-TREBLE2 (855-873-2532)



Re: HaveNFreeProcs() iterates through entire freeProcs list

От
Tom Lane
Дата:
Jim Nasby <Jim.Nasby@BlueTreble.com> writes:
> Current HaveNFreeProcs() iterates through the entire freeProcs list 
> (while holding ProcStructLock) just to determine if there's a small 
> number (superuser_reserved_connections) of free slots available.

I think you misread it.  Note the "n > 0" part of the while condition.
        regards, tom lane



Re: HaveNFreeProcs() iterates through entire freeProcs list

От
Jim Nasby
Дата:
On 12/2/16 12:52 PM, Tom Lane wrote:
> I think you misread it.  Note the "n > 0" part of the while condition.

*facepalm*

Sorry for the noise...
-- 
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
855-TREBLE2 (855-873-2532)