/ Check-in [a726d981]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add code to this branch to emit a log message after each cumulative second that the WRITER lock has been held.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | server-edition
Files: files | file ages | folders
SHA3-256: a726d98122704e1e702cfa7ae61d680497df6a826d98082161e0823e115d40a5
User & Date: dan 2017-05-22 08:01:58
Context
2017-06-07
15:55
Add too/tserver.c - the implementation of a simple multi-threaded server designed for interactive testing of concurrency between connections used by different threads of the same process. check-in: 05b4fc43 user: dan tags: server-edition
2017-05-22
08:01
Add code to this branch to emit a log message after each cumulative second that the WRITER lock has been held. check-in: a726d981 user: dan tags: server-edition
2017-05-15
19:32
Avoid writer starvation by adding a RESERVED state to page locks. check-in: 9b7f8024 user: dan tags: server-edition
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

  7546   7546       /* Close any rollback journal previously open */
  7547   7547       sqlite3OsClose(pPager->jfd);
  7548   7548   
  7549   7549       rc = pagerOpenWal(pPager);
  7550   7550       if( rc==SQLITE_OK ){
  7551   7551         pPager->journalMode = PAGER_JOURNALMODE_WAL;
  7552   7552         pPager->eState = PAGER_OPEN;
         7553  +#ifdef SQLITE_SERVER_EDITION
  7553   7554         sqlite3WalServer(pPager->pWal, pPager->pServer);
         7555  +#endif
  7554   7556       }
  7555   7557     }else{
  7556   7558       *pbOpen = 1;
  7557   7559     }
  7558   7560   
  7559   7561     return rc;
  7560   7562   }

Changes to src/server.c.

    89     89     ino_t st_ino;
    90     90   };
    91     91   
    92     92   struct Server {
    93     93     ServerHMA *pHma;                /* Hma file object */
    94     94     int iClient;                    /* Client id */
    95     95     Pager *pPager;                  /* Associated pager object */
    96         -
           96  +  i64 nUsWrite;                   /* Cumulative us holding WRITER lock */
           97  +  i64 iUsWrite;                   /* Time WRITER lock was taken */
    97     98     int nAlloc;                     /* Allocated size of aLock[] array */
    98     99     int nLock;                      /* Number of entries in aLock[] */
    99    100     u32 *aLock;                     /* Mapped lock file */
   100    101   };
   101    102   
   102    103   #define SERVER_WRITE_LOCK 3
   103    104   #define SERVER_READ_LOCK  2
................................................................................
   450    451         u32 n = v;
   451    452         if( (v>>HMA_CLIENT_SLOTS)==p->iClient+1 ){
   452    453           n = n & ((1 << HMA_CLIENT_SLOTS)-1);
   453    454         }
   454    455         n = n & ~(1 << p->iClient);
   455    456         if( __sync_val_compare_and_swap(pSlot, v, n)==v ) break;
   456    457       }
          458  +    if( p->aLock[i]==0 ){
          459  +      struct timeval t2;
          460  +      i64 nUs;
          461  +      gettimeofday(&t2, 0);
          462  +      nUs = (i64)t2.tv_sec * 1000000 + t2.tv_usec - p->iUsWrite; 
          463  +      p->nUsWrite += nUs;
          464  +      if( (p->nUsWrite / 1000000)!=((p->nUsWrite + nUs)/1000000) ){
          465  +        sqlite3_log(SQLITE_WARNING, 
          466  +            "Cumulative WRITER time: %lldms\n", p->nUsWrite/1000
          467  +        );
          468  +      }
          469  +    }
   457    470     }
   458    471     p->nLock = 0;
   459    472   #if 1
   460    473     return posixLock(p->pHma->fd, p->iClient+1, SERVER_READ_LOCK, 0);
   461    474   #endif
   462    475     return SQLITE_OK;
   463    476   }
................................................................................
   564    577       do{
   565    578         v = *pSlot;
   566    579         assert( serverWriteLocker(v)==p->iClient );
   567    580         n = v & ((1<<HMA_CLIENT_SLOTS)-1);
   568    581       }while( __sync_val_compare_and_swap(pSlot, v, n)!=v );
   569    582     }
   570    583   
          584  +  if( pgno==0 ){
          585  +    struct timeval t1;
          586  +    gettimeofday(&t1, 0);
          587  +    p->iUsWrite = ((i64)t1.tv_sec * 1000000) + (i64)t1.tv_usec;
          588  +  }
   571    589     assert( rc!=SQLITE_OK || sqlite3ServerHasLock(p, pgno, bWrite) );
   572    590     return rc;
   573    591   }
   574    592   
   575    593   int sqlite3ServerHasLock(Server *p, Pgno pgno, int bWrite){
   576    594     u32 v = *serverPageLockSlot(p, pgno);
   577    595     if( bWrite ){
   578    596       return (v>>HMA_CLIENT_SLOTS)==(p->iClient+1);
   579    597     }
   580    598     return (v & (1 << p->iClient))!=0;
   581    599   }
   582    600   
   583    601   #endif /* ifdef SQLITE_SERVER_EDITION */