Skip site navigation (1) Skip section navigation (2)

Re: stuck spin lock with many concurrent users

From: Tatsuo Ishii <t-ishii(at)sra(dot)co(dot)jp>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: Inoue(at)tpf(dot)co(dot)jp, pgsql-hackers(at)postgresql(dot)org
Subject: Re: stuck spin lock with many concurrent users
Date: 2001-07-05 07:28:24
Message-ID: 20010705162824D.t-ishii@sra.co.jp (view raw or flat)
Thread:
Lists: pgsql-hackers
> >> Hm.  It doesn't seem that DeadLockCheck is taking very much of the time.
> 
> > Isn't the real time big ?
> 
> Yes, it sure is, but remember that the guy getting useful work done
> (DeadLockCheck) is having to share the CPU with 999 other processes
> that are waking up on every clock tick for just long enough to fail
> to get the spinlock.  I think it's those useless process wakeups that
> are causing the problem.
> 
> If you estimate that a process dispatch cycle is ~ 10 microseconds,
> then waking 999 useless processes every 10 msec is just about enough
> to consume 100% of the CPU doing nothing useful... so what should be
> a few-millisecond check takes a long time, which makes things worse
> because the 999 wannabees are spinning for that much more time.

If so, what about increase the dead lock timer proportional to the
length of the waiting holder queue?

Here are the patches against current to increase the dealock timer by
queue_length secconds.

*** proc.c.orig	Thu Jul  5 16:12:32 2001
--- proc.c	Thu Jul  5 16:20:22 2001
***************
*** 506,511 ****
--- 506,512 ----
  	int			myHeldLocks = MyProc->heldLocks;
  	PROC	   *proc;
  	int			i;
+ 	int	msec;
  
  #ifndef __BEOS__
  	struct itimerval timeval,
***************
*** 625,638 ****
  	 * Need to zero out struct to set the interval and the microseconds
  	 * fields to 0.
  	 */
  #ifndef __BEOS__
  	MemSet(&timeval, 0, sizeof(struct itimerval));
! 	timeval.it_value.tv_sec = DeadlockTimeout / 1000;
! 	timeval.it_value.tv_usec = (DeadlockTimeout % 1000) * 1000;
  	if (setitimer(ITIMER_REAL, &timeval, &dummy))
  		elog(FATAL, "ProcSleep: Unable to set timer for process wakeup");
  #else
! 	time_interval = DeadlockTimeout * 1000000;	/* usecs */
  	if (set_alarm(time_interval, B_ONE_SHOT_RELATIVE_ALARM) < 0)
  		elog(FATAL, "ProcSleep: Unable to set timer for process wakeup");
  #endif
--- 626,642 ----
  	 * Need to zero out struct to set the interval and the microseconds
  	 * fields to 0.
  	 */
+ 
+ 	msec = DeadlockTimeout + waitQueue->size * 1000;
+ 
  #ifndef __BEOS__
  	MemSet(&timeval, 0, sizeof(struct itimerval));
! 	timeval.it_value.tv_sec = msec / 1000;
! 	timeval.it_value.tv_usec = (msec % 1000) * 1000;
  	if (setitimer(ITIMER_REAL, &timeval, &dummy))
  		elog(FATAL, "ProcSleep: Unable to set timer for process wakeup");
  #else
! 	time_interval = msec * 1000000;	/* usecs */
  	if (set_alarm(time_interval, B_ONE_SHOT_RELATIVE_ALARM) < 0)
  		elog(FATAL, "ProcSleep: Unable to set timer for process wakeup");
  #endif

In response to

Responses

pgsql-hackers by date

Next:From: Alessio BragadiniDate: 2001-07-05 07:32:47
Subject: Re: [OT] Any major users of postgresql?
Previous:From: Hiroshi InoueDate: 2001-07-05 04:45:13
Subject: Re: Re: Buffer access rules, and a probable bug

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group