/ Check-in [34613f1d]
Login

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

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1:34613f1dc54c638531ca2f5907b71fbe8841233e
User & Date: drh 2010-12-20 15:51:59
Original Comment: 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.
Context
2010-12-21
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
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
2010-12-17
14:03
Add the "-heap" option to the command-line shell - to allocate a fixed heap for use with SQLITE_ENABLE_MEMSYS5. check-in: 74fff692 user: drh tags: trunk
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.

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