/ Check-in [29c5e8a7]
Login

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

Overview
Comment:Query or change the maximum number of worker threads allowed on each database connection separately using the "PRAGMA threads" command.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | threads
Files: files | file ages | folders
SHA1: 29c5e8a7c9d7ce349a1e1d72082d23450e877b45
User & Date: drh 2014-08-25 15:13:22
Context
2014-08-25
22:43
Merge the CAST operator enhancements from trunk. check-in: 6c8f86e4 user: drh tags: threads
15:13
Query or change the maximum number of worker threads allowed on each database connection separately using the "PRAGMA threads" command. check-in: 29c5e8a7 user: drh tags: threads
13:27
Merge the recent performance enhancements implemented on trunk into the threads branch. check-in: dfdc900f user: drh tags: threads
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/pragma.c.

    57     57   #define PragTyp_SHRINK_MEMORY                 26
    58     58   #define PragTyp_SOFT_HEAP_LIMIT               27
    59     59   #define PragTyp_STATS                         28
    60     60   #define PragTyp_SYNCHRONOUS                   29
    61     61   #define PragTyp_TABLE_INFO                    30
    62     62   #define PragTyp_TEMP_STORE                    31
    63     63   #define PragTyp_TEMP_STORE_DIRECTORY          32
    64         -#define PragTyp_WAL_AUTOCHECKPOINT            33
    65         -#define PragTyp_WAL_CHECKPOINT                34
    66         -#define PragTyp_ACTIVATE_EXTENSIONS           35
    67         -#define PragTyp_HEXKEY                        36
    68         -#define PragTyp_KEY                           37
    69         -#define PragTyp_REKEY                         38
    70         -#define PragTyp_LOCK_STATUS                   39
    71         -#define PragTyp_PARSER_TRACE                  40
           64  +#define PragTyp_THREADS                       33
           65  +#define PragTyp_WAL_AUTOCHECKPOINT            34
           66  +#define PragTyp_WAL_CHECKPOINT                35
           67  +#define PragTyp_ACTIVATE_EXTENSIONS           36
           68  +#define PragTyp_HEXKEY                        37
           69  +#define PragTyp_KEY                           38
           70  +#define PragTyp_REKEY                         39
           71  +#define PragTyp_LOCK_STATUS                   40
           72  +#define PragTyp_PARSER_TRACE                  41
    72     73   #define PragFlag_NeedSchema           0x01
    73     74   static const struct sPragmaNames {
    74     75     const char *const zName;  /* Name of pragma */
    75     76     u8 ePragTyp;              /* PragTyp_XXX value */
    76     77     u8 mPragFlag;             /* Zero or more PragFlag_XXX values */
    77     78     u32 iArg;                 /* Extra argument */
    78     79   } aPragmaNames[] = {
................................................................................
   414    415       /* ePragFlag: */ 0,
   415    416       /* iArg:      */ 0 },
   416    417     { /* zName:     */ "temp_store_directory",
   417    418       /* ePragTyp:  */ PragTyp_TEMP_STORE_DIRECTORY,
   418    419       /* ePragFlag: */ 0,
   419    420       /* iArg:      */ 0 },
   420    421   #endif
          422  +  { /* zName:     */ "threads",
          423  +    /* ePragTyp:  */ PragTyp_THREADS,
          424  +    /* ePragFlag: */ 0,
          425  +    /* iArg:      */ 0 },
   421    426   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   422    427     { /* zName:     */ "user_version",
   423    428       /* ePragTyp:  */ PragTyp_HEADER_VALUE,
   424    429       /* ePragFlag: */ 0,
   425    430       /* iArg:      */ 0 },
   426    431   #endif
   427    432   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
................................................................................
   461    466   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   462    467     { /* zName:     */ "writable_schema",
   463    468       /* ePragTyp:  */ PragTyp_FLAG,
   464    469       /* ePragFlag: */ 0,
   465    470       /* iArg:      */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
   466    471   #endif
   467    472   };
   468         -/* Number of pragmas: 56 on by default, 69 total. */
          473  +/* Number of pragmas: 57 on by default, 70 total. */
   469    474   /* End of the automatically generated pragma table.
   470    475   ***************************************************************************/
   471    476   
   472    477   /*
   473    478   ** Interpret the given string as a safety level.  Return 0 for OFF,
   474    479   ** 1 for ON or NORMAL and 2 for FULL.  Return 1 for an empty or 
   475    480   ** unrecognized string argument.  The FULL option is disallowed
................................................................................
  2268   2273       sqlite3_int64 N;
  2269   2274       if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
  2270   2275         sqlite3_soft_heap_limit64(N);
  2271   2276       }
  2272   2277       returnSingleInt(pParse, "soft_heap_limit",  sqlite3_soft_heap_limit64(-1));
  2273   2278       break;
  2274   2279     }
         2280  +
         2281  +  /*
         2282  +  **   PRAGMA threads
         2283  +  **   PRAGMA threads = N
         2284  +  **
         2285  +  ** Configure the maximum number of worker threads.  Return the new
         2286  +  ** maximum, which might be less than requested.
         2287  +  */
         2288  +  case PragTyp_THREADS: {
         2289  +    sqlite3_int64 N;
         2290  +    if( sqlite3GlobalConfig.bCoreMutex
         2291  +     && zRight
         2292  +     && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
         2293  +     && N>=0
         2294  +    ){
         2295  +      if( N>sqlite3GlobalConfig.nWorker ) N = sqlite3GlobalConfig.nWorker;
         2296  +      db->mxWorker = N&0xff;
         2297  +    }
         2298  +    returnSingleInt(pParse, "soft_heap_limit",  db->mxWorker);
         2299  +    break;
         2300  +  }
  2275   2301   
  2276   2302   #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
  2277   2303     /*
  2278   2304     ** Report the current state of file logs for all databases
  2279   2305     */
  2280   2306     case PragTyp_LOCK_STATUS: {
  2281   2307       static const char *const azLockName[] = {

Changes to src/shell.c.

  3813   3813     memset(data, 0, sizeof(*data));
  3814   3814     data->mode = MODE_List;
  3815   3815     memcpy(data->separator,"|", 2);
  3816   3816     memcpy(data->newline,"\r\n", 3);
  3817   3817     data->showHeader = 0;
  3818   3818     sqlite3_config(SQLITE_CONFIG_URI, 1);
  3819   3819     sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
         3820  +  sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
         3821  +  sqlite3_config(SQLITE_CONFIG_WORKER_THREADS, 64);
  3820   3822     sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> ");
  3821   3823     sqlite3_snprintf(sizeof(continuePrompt), continuePrompt,"   ...> ");
  3822         -  sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
  3823         -  sqlite3_config(SQLITE_CONFIG_WORKER_THREADS, 4);
  3824   3824   }
  3825   3825   
  3826   3826   /*
  3827   3827   ** Output text to the console in a font that attracts extra attention.
  3828   3828   */
  3829   3829   #ifdef _WIN32
  3830   3830   static void printBold(const char *zText){

Changes to src/sqliteInt.h.

  1008   1008     u8 temp_store;                /* 1: file 2: memory 0: default */
  1009   1009     u8 mallocFailed;              /* True if we have seen a malloc failure */
  1010   1010     u8 dfltLockMode;              /* Default locking-mode for attached dbs */
  1011   1011     signed char nextAutovac;      /* Autovac setting after VACUUM if >=0 */
  1012   1012     u8 suppressErr;               /* Do not issue error messages if true */
  1013   1013     u8 vtabOnConflict;            /* Value to return for s3_vtab_on_conflict() */
  1014   1014     u8 isTransactionSavepoint;    /* True if the outermost savepoint is a TS */
         1015  +  u8 mxWorker;                  /* Maximum number of worker threads */
  1015   1016     int nextPagesize;             /* Pagesize after VACUUM if >0 */
  1016   1017     u32 magic;                    /* Magic number for detect library misuse */
  1017   1018     int nChange;                  /* Value returned by sqlite3_changes() */
  1018   1019     int nTotalChange;             /* Value returned by sqlite3_total_changes() */
  1019   1020     int aLimit[SQLITE_N_LIMIT];   /* Limits */
  1020   1021     int nMaxSorterMmap;           /* Maximum size of regions mapped by sorter */
  1021   1022     struct sqlite3InitInfo {      /* Information used during initialization */

Changes to src/vdbesort.c.

   791    791     VdbeSorter *pSorter;            /* The new sorter */
   792    792     KeyInfo *pKeyInfo;              /* Copy of pCsr->pKeyInfo with db==0 */
   793    793     int szKeyInfo;                  /* Size of pCsr->pKeyInfo in bytes */
   794    794     int sz;                         /* Size of pSorter in bytes */
   795    795     int rc = SQLITE_OK;
   796    796   #if SQLITE_MAX_WORKER_THREADS==0
   797    797   # define nWorker 0
          798  +#elif SQLITE_MAX_WORKER_THREADS>=SORTER_MAX_MERGE_COUNT
          799  +  int nWorker = MIN(SORTER_MAX_MERGE_COUNT-1, db->mxWorker);
   798    800   #else
   799         -  int nWorker = (sqlite3GlobalConfig.bCoreMutex?sqlite3GlobalConfig.nWorker:0);
          801  +  int nWorker = db->mxWorker;
   800    802   #endif
   801    803   
   802    804     assert( pCsr->pKeyInfo && pCsr->pBt==0 );
   803    805     szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nField-1)*sizeof(CollSeq*);
   804    806     sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
   805    807   
   806    808     pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);

Changes to tool/mkpragmatab.tcl.

   290    290     TYPE: HEXKEY
   291    291     IF:   defined(SQLITE_HAS_CODEC)
   292    292   
   293    293     NAME: activate_extensions
   294    294     IF:   defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
   295    295   
   296    296     NAME: soft_heap_limit
          297  +
          298  +  NAME: threads
   297    299   }
   298    300   fconfigure stdout -translation lf
   299    301   set name {}
   300    302   set type {}
   301    303   set if {}
   302    304   set flags {}
   303    305   set arg 0