/ Check-in [8c3b06c2]
Login

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

Overview
Comment:Merge into the trunk the experimental enhancements to sqlite3_db_status() for measuring lookaside memory allocator performance.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8c3b06c299554759b67437e09ee7ef6420dacafc
User & Date: drh 2010-12-21 20:36:46
Context
2010-12-21
21:28
Add test cases for the new lookaside hit and miss status outputs. Add the output of lookaside hit and miss to the command-line shell statistics. check-in: b0888047 user: drh tags: trunk
20:36
Merge into the trunk the experimental enhancements to sqlite3_db_status() for measuring lookaside memory allocator performance. check-in: 8c3b06c2 user: drh tags: trunk
00:20
Remove the obsolete compile-time option SQLITE_THREAD_OVERRIDE_LOCK from the autoconf makefile. Needed only for LinuxThreads, which we no longer support. check-in: 09f6c053 user: drh tags: trunk
2010-12-20
15:51
Add additional DBSTATUS options for measuring the hit and miss rates against the lookaside memory pool - information useful in tuning the lookaside size. Currently experimental pending analysis of performance impact. Closed-Leaf check-in: 34613f1d user: drh tags: experimental
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/malloc.c.

   612    612     assert( db==0 || db->pnBytesFreed==0 );
   613    613   #ifndef SQLITE_OMIT_LOOKASIDE
   614    614     if( db ){
   615    615       LookasideSlot *pBuf;
   616    616       if( db->mallocFailed ){
   617    617         return 0;
   618    618       }
   619         -    if( db->lookaside.bEnabled && n<=db->lookaside.sz
   620         -         && (pBuf = db->lookaside.pFree)!=0 ){
   621         -      db->lookaside.pFree = pBuf->pNext;
   622         -      db->lookaside.nOut++;
   623         -      if( db->lookaside.nOut>db->lookaside.mxOut ){
   624         -        db->lookaside.mxOut = db->lookaside.nOut;
          619  +    if( db->lookaside.bEnabled ){
          620  +      if( n>db->lookaside.sz ){
          621  +        db->lookaside.anStat[1]++;
          622  +      }else if( (pBuf = db->lookaside.pFree)==0 ){
          623  +        db->lookaside.anStat[2]++;
          624  +      }else{
          625  +        db->lookaside.pFree = pBuf->pNext;
          626  +        db->lookaside.nOut++;
          627  +        db->lookaside.anStat[0]++;
          628  +        if( db->lookaside.nOut>db->lookaside.mxOut ){
          629  +          db->lookaside.mxOut = db->lookaside.nOut;
          630  +        }
          631  +        return (void*)pBuf;
   625    632         }
   626         -      return (void*)pBuf;
   627    633       }
   628    634     }
   629    635   #else
   630    636     if( db && db->mallocFailed ){
   631    637       return 0;
   632    638     }
   633    639   #endif

Changes to src/sqlite.h.in.

  5505   5505   ** The [sqlite3_db_status()] interface will return a non-zero error code
  5506   5506   ** if a discontinued or unsupported verb is invoked.
  5507   5507   **
  5508   5508   ** <dl>
  5509   5509   ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
  5510   5510   ** <dd>This parameter returns the number of lookaside memory slots currently
  5511   5511   ** checked out.</dd>)^
         5512  +**
         5513  +** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
         5514  +** <dd>This parameter returns the number malloc attempts that were 
         5515  +** satisfied using lookaside memory. Only the high-water value is meaningful;
         5516  +** the current value is always zero.
         5517  +** checked out.</dd>)^
         5518  +**
         5519  +** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
         5520  +** <dd>This parameter returns the number malloc attempts that might have
         5521  +** been satisfied using lookaside memory but failed due to the amount of
         5522  +** memory requested being larger than the lookaside slot size.
         5523  +** Only the high-water value is meaningful;
         5524  +** the current value is always zero.
         5525  +** checked out.</dd>)^
         5526  +**
         5527  +** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
         5528  +** <dd>This parameter returns the number malloc attempts that might have
         5529  +** been satisfied using lookaside memory but failed due to all lookaside
         5530  +** memory already being in use.
         5531  +** Only the high-water value is meaningful;
         5532  +** the current value is always zero.
         5533  +** checked out.</dd>)^
  5512   5534   **
  5513   5535   ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
  5514   5536   ** <dd>This parameter returns the approximate number of of bytes of heap
  5515   5537   ** memory used by all pager caches associated with the database connection.)^
  5516   5538   ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
  5517   5539   **
  5518   5540   ** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
................................................................................
  5528   5550   ** <dd>This parameter returns the approximate number of of bytes of heap
  5529   5551   ** and lookaside memory used by all prepared statements associated with
  5530   5552   ** the database connection.)^
  5531   5553   ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
  5532   5554   ** </dd>
  5533   5555   ** </dl>
  5534   5556   */
  5535         -#define SQLITE_DBSTATUS_LOOKASIDE_USED     0
  5536         -#define SQLITE_DBSTATUS_CACHE_USED         1
  5537         -#define SQLITE_DBSTATUS_SCHEMA_USED        2
  5538         -#define SQLITE_DBSTATUS_STMT_USED          3
  5539         -#define SQLITE_DBSTATUS_MAX                3   /* Largest defined DBSTATUS */
         5557  +#define SQLITE_DBSTATUS_LOOKASIDE_USED       0
         5558  +#define SQLITE_DBSTATUS_CACHE_USED           1
         5559  +#define SQLITE_DBSTATUS_SCHEMA_USED          2
         5560  +#define SQLITE_DBSTATUS_STMT_USED            3
         5561  +#define SQLITE_DBSTATUS_LOOKASIDE_HIT        4
         5562  +#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE  5
         5563  +#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL  6
         5564  +#define SQLITE_DBSTATUS_MAX                  6   /* Largest defined DBSTATUS */
  5540   5565   
  5541   5566   
  5542   5567   /*
  5543   5568   ** CAPI3REF: Prepared Statement Status
  5544   5569   **
  5545   5570   ** ^(Each prepared statement maintains various
  5546   5571   ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number

Changes to src/sqliteInt.h.

   733    733   */
   734    734   struct Lookaside {
   735    735     u16 sz;                 /* Size of each buffer in bytes */
   736    736     u8 bEnabled;            /* False to disable new lookaside allocations */
   737    737     u8 bMalloced;           /* True if pStart obtained from sqlite3_malloc() */
   738    738     int nOut;               /* Number of buffers currently checked out */
   739    739     int mxOut;              /* Highwater mark for nOut */
          740  +  int anStat[3];          /* 0: hits.  1: size misses.  2: full misses */
   740    741     LookasideSlot *pFree;   /* List of available buffers */
   741    742     void *pStart;           /* First byte of available memory space */
   742    743     void *pEnd;             /* First byte past end of available space */
   743    744   };
   744    745   struct LookasideSlot {
   745    746     LookasideSlot *pNext;    /* Next buffer in the list of free buffers */
   746    747   };

Changes to src/status.c.

   111    111         *pCurrent = db->lookaside.nOut;
   112    112         *pHighwater = db->lookaside.mxOut;
   113    113         if( resetFlag ){
   114    114           db->lookaside.mxOut = db->lookaside.nOut;
   115    115         }
   116    116         break;
   117    117       }
          118  +
          119  +    case SQLITE_DBSTATUS_LOOKASIDE_HIT:
          120  +    case SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE:
          121  +    case SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL: {
          122  +      testcase( op==SQLITE_DBSTATUS_LOOKASIDE_HIT );
          123  +      testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE );
          124  +      testcase( op==SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL );
          125  +      assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)>=0 );
          126  +      assert( (op-SQLITE_DBSTATUS_LOOKASIDE_HIT)<3 );
          127  +      *pCurrent = 0;
          128  +      *pHighwater = db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT];
          129  +      if( resetFlag ){
          130  +        db->lookaside.anStat[op - SQLITE_DBSTATUS_LOOKASIDE_HIT] = 0;
          131  +      }
          132  +      break;
          133  +    }
   118    134   
   119    135       /* 
   120    136       ** Return an approximation for the amount of memory currently used
   121    137       ** by all pagers associated with the given database connection.  The
   122    138       ** highwater mark is meaningless and is returned as zero.
   123    139       */
   124    140       case SQLITE_DBSTATUS_CACHE_USED: {