[dokuwiki] Sleeping vs. trolling

  • From: "Joe Lapp" <joe.lapp@xxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Wed, 17 May 2006 11:05:33 -0500 (CDT)

I was looking at Dokuwiki's file locking mechanism and noticed that it trolls 
rather than sleeps.  I was expecting a call to usleep() for a random number of 
microsecs so that the thread isn't hogging clock cycles and reducing overall 
server performance.  (It would be random to help de-sync and spread out 
multiple simultaneous attempts to access the already-locked file.)

Is there a reason why io_lock() trolls rather than sleeps?  Is there some other 
sort of blocking going on in the loop that I'm not noticing?  Here's the 
relevant portion of io_lock() (in file inc/io.php):

  $timeStart = time();
  do {
    //waited longer than 3 seconds? -> stale lock
    if ((time() - $timeStart) > 3) break;
    $locked = @mkdir($lockDir, $conf['dmode']);
    if($locked && $conf['dperm']) chmod($lockDir, $conf['dperm']);
  } while ($locked === false);

I wasn't able to find discussion of this issue in the archives.

Thinking that maybe usleep() wasn't sufficiently cross-platform, I did notice 
that some Windows systems won't heed a microsecond resolution, but they'll 
still heed usleep() to the nearest resolution, which is in the tens of 
microsecs.  Also, I noticed that Dokuwiki does use usleep in 
lib/exe/indexer.php.

If we can use usleep() here, are there any other places where we might do the 
same?

~joe
--
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: