Re: Adjustment of spinlock sleep delays

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Rod Taylor <rbt(at)rbt(dot)ca>
Cc: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Adjustment of spinlock sleep delays
Date: 2003-08-06 16:56:34
Message-ID: 27392.1060188994@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I said:
> The random component should already help to scatter the wakeups pretty
> well, so I'm thinking about just
> if (oldtime > 1 sec)
> time = 10msec
> else
> time = oldtime + oldtime * rand()
> ie random growth of a maximum of 2x per try, and reset to minimum delay
> when you get past 1 sec. This would guarantee at least as many tries
> as I'm getting currently with the deterministic algorithm (which is
> effectively this if rand() always returned 1).

Eventually it occurred to me that when using random delays, we should
set the timeout to occur after a fixed number of tries, not after a
fixed total time spent. This is because the probability of unwanted
failure (ie, the spinlock isn't really stuck, you just managed to always
look when someone else had it) depends directly on the number of tries.

I've committed code that does the above with a limit of 1000 iterations;
timeout seems to take about 3.5 minutes on average. (In the prior code
we would make 6000 attempts over a period of 1 minute.)

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message ohp 2003-08-06 17:14:49 7.4beta1 on unixware 713
Previous Message Larry Rosenman 2003-08-06 16:18:06 Re: 7.4Beta1: Compile Failure: UnixWare 7.1.3UP2