/ Check-in [5648af96]
Login

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

Overview
Comment:Changes to threadtest3 so that "stress2" is more similar to the SDS stress test.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | threadtest3
Files: files | file ages | folders
SHA1:5648af96d8e2521c5b0cca19f1358374d032394d
User & Date: dan 2014-12-15 20:49:26
Context
2014-12-16
00:20
Enhanced "stress2" testing in the threadtest3.c test program. check-in: ae43539e user: drh tags: trunk
2014-12-15
20:49
Changes to threadtest3 so that "stress2" is more similar to the SDS stress test. Closed-Leaf check-in: 5648af96 user: dan tags: threadtest3
16:27
Add new test file e_walauto.test. check-in: 62ef4514 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/threadtest3.c.

   117    117   #  define uint32 unsigned int
   118    118   #endif
   119    119   
   120    120   struct MD5Context {
   121    121     int isInit;
   122    122     uint32 buf[4];
   123    123     uint32 bits[2];
   124         -  unsigned char in[64];
          124  +  union {
          125  +    unsigned char in[64];
          126  +    uint32 in32[16];
          127  +  } u;
   125    128   };
   126    129   typedef struct MD5Context MD5Context;
   127    130   
   128    131   /*
   129    132    * Note: this code is harmless on little-endian machines.
   130    133    */
   131    134   static void byteReverse (unsigned char *buf, unsigned longs){
................................................................................
   266    269     ctx->bits[1] += len >> 29;
   267    270   
   268    271     t = (t >> 3) & 0x3f;    /* Bytes already in shsInfo->data */
   269    272   
   270    273     /* Handle any leading odd-sized chunks */
   271    274   
   272    275     if ( t ) {
   273         -    unsigned char *p = (unsigned char *)ctx->in + t;
          276  +    unsigned char *p = (unsigned char *)ctx->u.in + t;
   274    277   
   275    278       t = 64-t;
   276    279       if (len < t) {
   277    280         memcpy(p, buf, len);
   278    281         return;
   279    282       }
   280    283       memcpy(p, buf, t);
   281         -    byteReverse(ctx->in, 16);
   282         -    MD5Transform(ctx->buf, (uint32 *)ctx->in);
          284  +    byteReverse(ctx->u.in, 16);
          285  +    MD5Transform(ctx->buf, (uint32 *)ctx->u.in);
   283    286       buf += t;
   284    287       len -= t;
   285    288     }
   286    289   
   287    290     /* Process data in 64-byte chunks */
   288    291   
   289    292     while (len >= 64) {
   290         -    memcpy(ctx->in, buf, 64);
   291         -    byteReverse(ctx->in, 16);
   292         -    MD5Transform(ctx->buf, (uint32 *)ctx->in);
          293  +    memcpy(ctx->u.in, buf, 64);
          294  +    byteReverse(ctx->u.in, 16);
          295  +    MD5Transform(ctx->buf, (uint32 *)ctx->u.in);
   293    296       buf += 64;
   294    297       len -= 64;
   295    298     }
   296    299   
   297    300     /* Handle any remaining bytes of data. */
   298    301   
   299         -  memcpy(ctx->in, buf, len);
          302  +  memcpy(ctx->u.in, buf, len);
   300    303   }
   301    304   
   302    305   /*
   303    306    * Final wrapup - pad to 64-byte boundary with the bit pattern 
   304    307    * 1 0* (64-bit count of bits processed, MSB-first)
   305    308    */
   306    309   static void MD5Final(unsigned char digest[16], MD5Context *ctx){
................................................................................
   308    311     unsigned char *p;
   309    312   
   310    313     /* Compute number of bytes mod 64 */
   311    314     count = (ctx->bits[0] >> 3) & 0x3F;
   312    315   
   313    316     /* Set the first char of padding to 0x80.  This is safe since there is
   314    317        always at least one byte free */
   315         -  p = ctx->in + count;
          318  +  p = ctx->u.in + count;
   316    319     *p++ = 0x80;
   317    320   
   318    321     /* Bytes of padding needed to make 64 bytes */
   319    322     count = 64 - 1 - count;
   320    323   
   321    324     /* Pad out to 56 mod 64 */
   322    325     if (count < 8) {
   323    326       /* Two lots of padding:  Pad the first block to 64 bytes */
   324    327       memset(p, 0, count);
   325         -    byteReverse(ctx->in, 16);
   326         -    MD5Transform(ctx->buf, (uint32 *)ctx->in);
          328  +    byteReverse(ctx->u.in, 16);
          329  +    MD5Transform(ctx->buf, (uint32 *)ctx->u.in);
   327    330   
   328    331       /* Now fill the next block with 56 bytes */
   329         -    memset(ctx->in, 0, 56);
          332  +    memset(ctx->u.in, 0, 56);
   330    333     } else {
   331    334       /* Pad block to 56 bytes */
   332    335       memset(p, 0, count-8);
   333    336     }
   334         -  byteReverse(ctx->in, 14);
          337  +  byteReverse(ctx->u.in, 14);
   335    338   
   336    339     /* Append length in bits and transform */
   337         -  ((uint32 *)ctx->in)[ 14 ] = ctx->bits[0];
   338         -  ((uint32 *)ctx->in)[ 15 ] = ctx->bits[1];
          340  +  ctx->u.in32[14] = ctx->bits[0];
          341  +  ctx->u.in32[15] = ctx->bits[1];
   339    342   
   340         -  MD5Transform(ctx->buf, (uint32 *)ctx->in);
          343  +  MD5Transform(ctx->buf, (uint32 *)ctx->u.in);
   341    344     byteReverse((unsigned char *)ctx->buf, 4);
   342    345     memcpy(digest, ctx->buf, 16);
   343    346     memset(ctx, 0, sizeof(*ctx));    /* In case it is sensitive */
   344    347   }
   345    348   
   346    349   /*
   347    350   ** Convert a 128-bit MD5 digest into a 32-digit base-16 number.
................................................................................
  1441   1444       { checkpoint_starvation_1, "checkpoint_starvation_1", 10000 },
  1442   1445       { checkpoint_starvation_2, "checkpoint_starvation_2", 10000 },
  1443   1446   
  1444   1447       { create_drop_index_1, "create_drop_index_1", 10000 },
  1445   1448       { lookaside1,          "lookaside1", 10000 },
  1446   1449       { vacuum1,             "vacuum1", 10000 },
  1447   1450       { stress1,             "stress1", 10000 },
  1448         -    { stress2,             "stress2", 10000 },
         1451  +    { stress2,             "stress2", 60000 },
  1449   1452     };
  1450   1453   
  1451   1454     int i;
  1452   1455     int bTestfound = 0;
  1453   1456   
  1454   1457     sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
  1455   1458     sqlite3_config(SQLITE_CONFIG_MULTITHREAD);

Changes to test/tt3_stress.c.

   120    120         closedb(&err, &db);
   121    121         opendb(&err, &db, "test.db", 0);
   122    122       }
   123    123       execsql(&err, &db, "DELETE FROM t1 WHERE (rowid % 4)==:i", &i);
   124    124       i1++;
   125    125       if( err.rc ) i2++;
   126    126       clear_error(&err, SQLITE_LOCKED);
   127         -    clear_error(&err, SQLITE_ERROR);
   128    127     }
   129    128     closedb(&err, &db);
   130    129     print_and_free_err(&err);
   131    130     return sqlite3_mprintf("deleted from t1 %d/%d attempts", i2, i1);
   132    131   }
   133    132   
   134    133   
................................................................................
   180    179   ** 10. Big DELETE statements.
   181    180   ** 11. VACUUM.
   182    181   ** 14. Integrity-check.
   183    182   ** 17. Switch the journal mode from delete to wal and back again.
   184    183   ** 19. Open and close database connections rapidly.
   185    184   */
   186    185   
   187         -#define STRESS2_TABCNT 5
          186  +#define STRESS2_TABCNT 5          /* count1 in SDS test */
          187  +
          188  +#define STRESS2_COUNT2 200        /* count2 in SDS test */
          189  +#define STRESS2_COUNT3  57        /* count2 in SDS test */
   188    190   
   189    191   static void stress2_workload1(Error *pErr, Sqlite *pDb, int i){
   190         -  int iTab = (i % STRESS2_TABCNT);
          192  +  int iTab = (i % (STRESS2_TABCNT-1)) + 1;
   191    193     sql_script_printf(pErr, pDb, 
   192    194         "CREATE TABLE IF NOT EXISTS t%d(x PRIMARY KEY, y, z);", iTab
   193    195     );
   194    196   }
   195    197   
   196    198   static void stress2_workload2(Error *pErr, Sqlite *pDb, int i){
   197         -  int iTab = (i % STRESS2_TABCNT);
          199  +  int iTab = (i % (STRESS2_TABCNT-1)) + 1;
   198    200     sql_script_printf(pErr, pDb, "DROP TABLE IF EXISTS t%d;", iTab);
   199    201   }
   200    202   
   201    203   static void stress2_workload3(Error *pErr, Sqlite *pDb, int i){
   202         -  int iTab = (i % STRESS2_TABCNT);
   203         -  sql_script_printf(pErr, pDb, "SELECT * FROM t%d WHERE z = 'small'", iTab);
          204  +  sql_script(pErr, pDb, "SELECT * FROM t0 WHERE z = 'small'");
   204    205   }
   205    206   
   206    207   static void stress2_workload4(Error *pErr, Sqlite *pDb, int i){
   207         -  int iTab = (i % STRESS2_TABCNT);
   208         -  sql_script_printf(pErr, pDb, "SELECT * FROM t%d WHERE z = 'big'", iTab);
          208  +  sql_script(pErr, pDb, "SELECT * FROM t0 WHERE z = 'big'");
   209    209   }
   210    210   
   211    211   static void stress2_workload5(Error *pErr, Sqlite *pDb, int i){
   212         -  int iTab = (i % STRESS2_TABCNT);
   213         -  sql_script_printf(pErr, pDb,
   214         -      "INSERT INTO t%d VALUES(random(), hex(randomblob(57)), 'small');", iTab
          212  +  sql_script(pErr, pDb,
          213  +      "INSERT INTO t0 VALUES(hex(random()), hex(randomblob(200)), 'small');"
   215    214     );
   216    215   }
   217    216   
   218    217   static void stress2_workload6(Error *pErr, Sqlite *pDb, int i){
   219         -  int iTab = (i % STRESS2_TABCNT);
   220         -  sql_script_printf(pErr, pDb,
   221         -      "INSERT INTO t%d VALUES(random(), hex(randomblob(2000)), 'big');", iTab
          218  +  sql_script(pErr, pDb,
          219  +      "INSERT INTO t0 VALUES(hex(random()), hex(randomblob(57)), 'big');"
   222    220     );
   223    221   }
   224    222   
   225    223   static void stress2_workload7(Error *pErr, Sqlite *pDb, int i){
   226         -  int iTab = (i % STRESS2_TABCNT);
   227    224     sql_script_printf(pErr, pDb,
   228         -      "UPDATE t%d SET y = hex(randomblob(57)) "
   229         -      "WHERE (x %% 5)==(%d %% 5) AND z='small';"
   230         -      ,iTab, i
          225  +      "UPDATE t0 SET y = hex(randomblob(200)) "
          226  +      "WHERE x LIKE hex((%d %% 5)) AND z='small';"
          227  +      ,i
   231    228     );
   232    229   }
   233    230   static void stress2_workload8(Error *pErr, Sqlite *pDb, int i){
   234         -  int iTab = (i % STRESS2_TABCNT);
   235    231     sql_script_printf(pErr, pDb,
   236         -      "UPDATE t%d SET y = hex(randomblob(2000)) "
   237         -      "WHERE (x %% 5)==(%d %% 5) AND z='big';"
   238         -      ,iTab, i
          232  +      "UPDATE t0 SET y = hex(randomblob(57)) "
          233  +      "WHERE x LIKE hex(%d %% 5) AND z='big';"
          234  +      ,i
   239    235     );
   240    236   }
   241    237   
   242    238   static void stress2_workload9(Error *pErr, Sqlite *pDb, int i){
   243         -  int iTab = (i % STRESS2_TABCNT);
   244    239     sql_script_printf(pErr, pDb,
   245         -      "DELETE FROM t%d WHERE (x %% 5)==(%d %% 5) AND z='small';"
   246         -      ,iTab, i
          240  +      "DELETE FROM t0 WHERE x LIKE hex(%d %% 5) AND z='small';", i
   247    241     );
   248    242   }
   249    243   static void stress2_workload10(Error *pErr, Sqlite *pDb, int i){
   250         -  int iTab = (i % STRESS2_TABCNT);
   251    244     sql_script_printf(pErr, pDb,
   252         -      "DELETE FROM t%d WHERE (x %% 5)==(%d %% 5) AND z='big';"
   253         -      ,iTab, i
          245  +      "DELETE FROM t0 WHERE x LIKE hex(%d %% 5) AND z='big';", i
   254    246     );
   255    247   }
   256    248   
   257    249   static void stress2_workload11(Error *pErr, Sqlite *pDb, int i){
   258    250     sql_script(pErr, pDb, "VACUUM");
   259    251   }
   260    252   
................................................................................
   292    284   static char *stress2_thread_wrapper(int iTid, void *pArg){
   293    285     Stress2Ctx *pCtx = (Stress2Ctx*)pArg;
   294    286     Error err = {0};                /* Error code and message */
   295    287     Sqlite db = {0};                /* SQLite database connection */
   296    288     int i1 = 0;
   297    289     int i2 = 0;
   298    290   
   299         -  opendb(&err, &db, pCtx->zDb, 0);
   300    291     while( !timetostop(&err) ){
   301         -    pCtx->xProc(&err, &db, i1);
   302         -    i2 += (err.rc==SQLITE_OK);
   303         -    clear_error(&err, SQLITE_LOCKED);
   304         -    clear_error(&err, SQLITE_ERROR);
   305         -    i1++;
          292  +    int cnt;
          293  +    opendb(&err, &db, pCtx->zDb, 0);
          294  +    for(cnt=0; err.rc==SQLITE_OK && cnt<STRESS2_TABCNT; cnt++){
          295  +      pCtx->xProc(&err, &db, i1);
          296  +      i2 += (err.rc==SQLITE_OK);
          297  +      clear_error(&err, SQLITE_LOCKED);
          298  +      i1++;
          299  +    }
          300  +    closedb(&err, &db);
   306    301     }
   307    302   
   308    303     print_and_free_err(&err);
   309    304     return sqlite3_mprintf("ok %d/%d", i2, i1);
   310    305   }
   311    306   
   312    307   static void stress2_launch_thread_loop(
................................................................................
   335    330       { stress2_workload8 },
   336    331       { stress2_workload9 },
   337    332       { stress2_workload10 },
   338    333       { stress2_workload11 },
   339    334       { stress2_workload14 },
   340    335       { stress2_workload17 },
   341    336     };
   342         -  const char *azDb[] = {
   343         -    "test.db",
   344         -    "file::memory:?cache=shared"
   345         -  };
   346         -  int j;
          337  +  const char *zDb = "test.db";
          338  +
          339  +  int i;
          340  +  Error err = {0};
          341  +  Sqlite db = {0};
          342  +  Threadset threads = {0};
          343  +
          344  +  /* To make sure the db file is empty before commencing */
          345  +  opendb(&err, &db, zDb, 1);
          346  +  sql_script(&err, &db, 
          347  +      "CREATE TABLE IF NOT EXISTS t0(x PRIMARY KEY, y, z);"
          348  +      "CREATE INDEX IF NOT EXISTS i0 ON t0(y);"
          349  +  );
          350  +  closedb(&err, &db);
   347    351   
   348         -  for(j=0; j<sizeof(azDb)/sizeof(azDb[0]); j++){
   349         -    int i;
   350         -    Error err = {0};
   351         -    Sqlite db = {0};
   352         -    Threadset threads = {0};
   353         -    const char *zDb = azDb[j];
          352  +  setstoptime(&err, nMs);
          353  +  sqlite3_enable_shared_cache(1);
   354    354   
   355         -    /* To make sure the db file is empty before commencing */
   356         -    opendb(&err, &db, zDb, 1);
   357         -    closedb(&err, &db);
   358         -
   359         -    setstoptime(&err, nMs);
   360         -    sqlite3_enable_shared_cache(1);
          355  +  for(i=0; i<sizeof(aTask)/sizeof(aTask[0]); i++){
          356  +    stress2_launch_thread_loop(&err, &threads, zDb, aTask[i].x);
          357  +  }
          358  +  launch_thread(&err, &threads, stress2_workload19, (void*)zDb);
          359  +  launch_thread(&err, &threads, stress2_workload19, (void*)zDb);
   361    360   
   362         -    for(i=0; i<sizeof(aTask)/sizeof(aTask[0]); i++){
   363         -      stress2_launch_thread_loop(&err, &threads, zDb, aTask[i].x);
   364         -    }
   365         -    launch_thread(&err, &threads, stress2_workload19, (void*)zDb);
   366         -    launch_thread(&err, &threads, stress2_workload19, (void*)zDb);
   367         -
   368         -    join_all_threads(&err, &threads);
   369         -    sqlite3_enable_shared_cache(0);
   370         -    print_and_free_err(&err);
   371         -    if( j==0 ){
   372         -      printf("Running stress2 (again, with in-memory db) for %d seconds...\n",
   373         -          nMs / 1000
   374         -      );
   375         -    }
   376         -  }
          361  +  join_all_threads(&err, &threads);
          362  +  sqlite3_enable_shared_cache(0);
          363  +  print_and_free_err(&err);
   377    364   }
   378    365   
   379    366   
   380    367   
   381    368