Changes to threadtest3 so that "stress2" is more similar to the SDS stress test.
FossilOrigin-Name: 5648af96d8e2521c5b0cca19f1358374d032394d
This commit is contained in:
+20
-17
@@ -121,7 +121,10 @@ struct MD5Context {
|
||||
int isInit;
|
||||
uint32 buf[4];
|
||||
uint32 bits[2];
|
||||
unsigned char in[64];
|
||||
union {
|
||||
unsigned char in[64];
|
||||
uint32 in32[16];
|
||||
} u;
|
||||
};
|
||||
typedef struct MD5Context MD5Context;
|
||||
|
||||
@@ -270,7 +273,7 @@ void MD5Update(MD5Context *ctx, const unsigned char *buf, unsigned int len){
|
||||
/* Handle any leading odd-sized chunks */
|
||||
|
||||
if ( t ) {
|
||||
unsigned char *p = (unsigned char *)ctx->in + t;
|
||||
unsigned char *p = (unsigned char *)ctx->u.in + t;
|
||||
|
||||
t = 64-t;
|
||||
if (len < t) {
|
||||
@@ -278,8 +281,8 @@ void MD5Update(MD5Context *ctx, const unsigned char *buf, unsigned int len){
|
||||
return;
|
||||
}
|
||||
memcpy(p, buf, t);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->in);
|
||||
byteReverse(ctx->u.in, 16);
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->u.in);
|
||||
buf += t;
|
||||
len -= t;
|
||||
}
|
||||
@@ -287,16 +290,16 @@ void MD5Update(MD5Context *ctx, const unsigned char *buf, unsigned int len){
|
||||
/* Process data in 64-byte chunks */
|
||||
|
||||
while (len >= 64) {
|
||||
memcpy(ctx->in, buf, 64);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->in);
|
||||
memcpy(ctx->u.in, buf, 64);
|
||||
byteReverse(ctx->u.in, 16);
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->u.in);
|
||||
buf += 64;
|
||||
len -= 64;
|
||||
}
|
||||
|
||||
/* Handle any remaining bytes of data. */
|
||||
|
||||
memcpy(ctx->in, buf, len);
|
||||
memcpy(ctx->u.in, buf, len);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -312,7 +315,7 @@ static void MD5Final(unsigned char digest[16], MD5Context *ctx){
|
||||
|
||||
/* Set the first char of padding to 0x80. This is safe since there is
|
||||
always at least one byte free */
|
||||
p = ctx->in + count;
|
||||
p = ctx->u.in + count;
|
||||
*p++ = 0x80;
|
||||
|
||||
/* Bytes of padding needed to make 64 bytes */
|
||||
@@ -322,22 +325,22 @@ static void MD5Final(unsigned char digest[16], MD5Context *ctx){
|
||||
if (count < 8) {
|
||||
/* Two lots of padding: Pad the first block to 64 bytes */
|
||||
memset(p, 0, count);
|
||||
byteReverse(ctx->in, 16);
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->in);
|
||||
byteReverse(ctx->u.in, 16);
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->u.in);
|
||||
|
||||
/* Now fill the next block with 56 bytes */
|
||||
memset(ctx->in, 0, 56);
|
||||
memset(ctx->u.in, 0, 56);
|
||||
} else {
|
||||
/* Pad block to 56 bytes */
|
||||
memset(p, 0, count-8);
|
||||
}
|
||||
byteReverse(ctx->in, 14);
|
||||
byteReverse(ctx->u.in, 14);
|
||||
|
||||
/* Append length in bits and transform */
|
||||
((uint32 *)ctx->in)[ 14 ] = ctx->bits[0];
|
||||
((uint32 *)ctx->in)[ 15 ] = ctx->bits[1];
|
||||
ctx->u.in32[14] = ctx->bits[0];
|
||||
ctx->u.in32[15] = ctx->bits[1];
|
||||
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->in);
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->u.in);
|
||||
byteReverse((unsigned char *)ctx->buf, 4);
|
||||
memcpy(digest, ctx->buf, 16);
|
||||
memset(ctx, 0, sizeof(*ctx)); /* In case it is sensitive */
|
||||
@@ -1445,7 +1448,7 @@ int main(int argc, char **argv){
|
||||
{ lookaside1, "lookaside1", 10000 },
|
||||
{ vacuum1, "vacuum1", 10000 },
|
||||
{ stress1, "stress1", 10000 },
|
||||
{ stress2, "stress2", 10000 },
|
||||
{ stress2, "stress2", 60000 },
|
||||
};
|
||||
|
||||
int i;
|
||||
|
||||
+51
-64
@@ -124,7 +124,6 @@ static char *stress_thread_5(int iTid, void *pArg){
|
||||
i1++;
|
||||
if( err.rc ) i2++;
|
||||
clear_error(&err, SQLITE_LOCKED);
|
||||
clear_error(&err, SQLITE_ERROR);
|
||||
}
|
||||
closedb(&err, &db);
|
||||
print_and_free_err(&err);
|
||||
@@ -184,73 +183,66 @@ static void stress1(int nMs){
|
||||
** 19. Open and close database connections rapidly.
|
||||
*/
|
||||
|
||||
#define STRESS2_TABCNT 5
|
||||
#define STRESS2_TABCNT 5 /* count1 in SDS test */
|
||||
|
||||
#define STRESS2_COUNT2 200 /* count2 in SDS test */
|
||||
#define STRESS2_COUNT3 57 /* count2 in SDS test */
|
||||
|
||||
static void stress2_workload1(Error *pErr, Sqlite *pDb, int i){
|
||||
int iTab = (i % STRESS2_TABCNT);
|
||||
int iTab = (i % (STRESS2_TABCNT-1)) + 1;
|
||||
sql_script_printf(pErr, pDb,
|
||||
"CREATE TABLE IF NOT EXISTS t%d(x PRIMARY KEY, y, z);", iTab
|
||||
);
|
||||
}
|
||||
|
||||
static void stress2_workload2(Error *pErr, Sqlite *pDb, int i){
|
||||
int iTab = (i % STRESS2_TABCNT);
|
||||
int iTab = (i % (STRESS2_TABCNT-1)) + 1;
|
||||
sql_script_printf(pErr, pDb, "DROP TABLE IF EXISTS t%d;", iTab);
|
||||
}
|
||||
|
||||
static void stress2_workload3(Error *pErr, Sqlite *pDb, int i){
|
||||
int iTab = (i % STRESS2_TABCNT);
|
||||
sql_script_printf(pErr, pDb, "SELECT * FROM t%d WHERE z = 'small'", iTab);
|
||||
sql_script(pErr, pDb, "SELECT * FROM t0 WHERE z = 'small'");
|
||||
}
|
||||
|
||||
static void stress2_workload4(Error *pErr, Sqlite *pDb, int i){
|
||||
int iTab = (i % STRESS2_TABCNT);
|
||||
sql_script_printf(pErr, pDb, "SELECT * FROM t%d WHERE z = 'big'", iTab);
|
||||
sql_script(pErr, pDb, "SELECT * FROM t0 WHERE z = 'big'");
|
||||
}
|
||||
|
||||
static void stress2_workload5(Error *pErr, Sqlite *pDb, int i){
|
||||
int iTab = (i % STRESS2_TABCNT);
|
||||
sql_script_printf(pErr, pDb,
|
||||
"INSERT INTO t%d VALUES(random(), hex(randomblob(57)), 'small');", iTab
|
||||
sql_script(pErr, pDb,
|
||||
"INSERT INTO t0 VALUES(hex(random()), hex(randomblob(200)), 'small');"
|
||||
);
|
||||
}
|
||||
|
||||
static void stress2_workload6(Error *pErr, Sqlite *pDb, int i){
|
||||
int iTab = (i % STRESS2_TABCNT);
|
||||
sql_script_printf(pErr, pDb,
|
||||
"INSERT INTO t%d VALUES(random(), hex(randomblob(2000)), 'big');", iTab
|
||||
sql_script(pErr, pDb,
|
||||
"INSERT INTO t0 VALUES(hex(random()), hex(randomblob(57)), 'big');"
|
||||
);
|
||||
}
|
||||
|
||||
static void stress2_workload7(Error *pErr, Sqlite *pDb, int i){
|
||||
int iTab = (i % STRESS2_TABCNT);
|
||||
sql_script_printf(pErr, pDb,
|
||||
"UPDATE t%d SET y = hex(randomblob(57)) "
|
||||
"WHERE (x %% 5)==(%d %% 5) AND z='small';"
|
||||
,iTab, i
|
||||
"UPDATE t0 SET y = hex(randomblob(200)) "
|
||||
"WHERE x LIKE hex((%d %% 5)) AND z='small';"
|
||||
,i
|
||||
);
|
||||
}
|
||||
static void stress2_workload8(Error *pErr, Sqlite *pDb, int i){
|
||||
int iTab = (i % STRESS2_TABCNT);
|
||||
sql_script_printf(pErr, pDb,
|
||||
"UPDATE t%d SET y = hex(randomblob(2000)) "
|
||||
"WHERE (x %% 5)==(%d %% 5) AND z='big';"
|
||||
,iTab, i
|
||||
"UPDATE t0 SET y = hex(randomblob(57)) "
|
||||
"WHERE x LIKE hex(%d %% 5) AND z='big';"
|
||||
,i
|
||||
);
|
||||
}
|
||||
|
||||
static void stress2_workload9(Error *pErr, Sqlite *pDb, int i){
|
||||
int iTab = (i % STRESS2_TABCNT);
|
||||
sql_script_printf(pErr, pDb,
|
||||
"DELETE FROM t%d WHERE (x %% 5)==(%d %% 5) AND z='small';"
|
||||
,iTab, i
|
||||
"DELETE FROM t0 WHERE x LIKE hex(%d %% 5) AND z='small';", i
|
||||
);
|
||||
}
|
||||
static void stress2_workload10(Error *pErr, Sqlite *pDb, int i){
|
||||
int iTab = (i % STRESS2_TABCNT);
|
||||
sql_script_printf(pErr, pDb,
|
||||
"DELETE FROM t%d WHERE (x %% 5)==(%d %% 5) AND z='big';"
|
||||
,iTab, i
|
||||
"DELETE FROM t0 WHERE x LIKE hex(%d %% 5) AND z='big';", i
|
||||
);
|
||||
}
|
||||
|
||||
@@ -296,13 +288,16 @@ static char *stress2_thread_wrapper(int iTid, void *pArg){
|
||||
int i1 = 0;
|
||||
int i2 = 0;
|
||||
|
||||
opendb(&err, &db, pCtx->zDb, 0);
|
||||
while( !timetostop(&err) ){
|
||||
pCtx->xProc(&err, &db, i1);
|
||||
i2 += (err.rc==SQLITE_OK);
|
||||
clear_error(&err, SQLITE_LOCKED);
|
||||
clear_error(&err, SQLITE_ERROR);
|
||||
i1++;
|
||||
int cnt;
|
||||
opendb(&err, &db, pCtx->zDb, 0);
|
||||
for(cnt=0; err.rc==SQLITE_OK && cnt<STRESS2_TABCNT; cnt++){
|
||||
pCtx->xProc(&err, &db, i1);
|
||||
i2 += (err.rc==SQLITE_OK);
|
||||
clear_error(&err, SQLITE_LOCKED);
|
||||
i1++;
|
||||
}
|
||||
closedb(&err, &db);
|
||||
}
|
||||
|
||||
print_and_free_err(&err);
|
||||
@@ -339,41 +334,33 @@ static void stress2(int nMs){
|
||||
{ stress2_workload14 },
|
||||
{ stress2_workload17 },
|
||||
};
|
||||
const char *azDb[] = {
|
||||
"test.db",
|
||||
"file::memory:?cache=shared"
|
||||
};
|
||||
int j;
|
||||
const char *zDb = "test.db";
|
||||
|
||||
for(j=0; j<sizeof(azDb)/sizeof(azDb[0]); j++){
|
||||
int i;
|
||||
Error err = {0};
|
||||
Sqlite db = {0};
|
||||
Threadset threads = {0};
|
||||
const char *zDb = azDb[j];
|
||||
int i;
|
||||
Error err = {0};
|
||||
Sqlite db = {0};
|
||||
Threadset threads = {0};
|
||||
|
||||
/* To make sure the db file is empty before commencing */
|
||||
opendb(&err, &db, zDb, 1);
|
||||
closedb(&err, &db);
|
||||
/* To make sure the db file is empty before commencing */
|
||||
opendb(&err, &db, zDb, 1);
|
||||
sql_script(&err, &db,
|
||||
"CREATE TABLE IF NOT EXISTS t0(x PRIMARY KEY, y, z);"
|
||||
"CREATE INDEX IF NOT EXISTS i0 ON t0(y);"
|
||||
);
|
||||
closedb(&err, &db);
|
||||
|
||||
setstoptime(&err, nMs);
|
||||
sqlite3_enable_shared_cache(1);
|
||||
setstoptime(&err, nMs);
|
||||
sqlite3_enable_shared_cache(1);
|
||||
|
||||
for(i=0; i<sizeof(aTask)/sizeof(aTask[0]); i++){
|
||||
stress2_launch_thread_loop(&err, &threads, zDb, aTask[i].x);
|
||||
}
|
||||
launch_thread(&err, &threads, stress2_workload19, (void*)zDb);
|
||||
launch_thread(&err, &threads, stress2_workload19, (void*)zDb);
|
||||
|
||||
join_all_threads(&err, &threads);
|
||||
sqlite3_enable_shared_cache(0);
|
||||
print_and_free_err(&err);
|
||||
if( j==0 ){
|
||||
printf("Running stress2 (again, with in-memory db) for %d seconds...\n",
|
||||
nMs / 1000
|
||||
);
|
||||
}
|
||||
for(i=0; i<sizeof(aTask)/sizeof(aTask[0]); i++){
|
||||
stress2_launch_thread_loop(&err, &threads, zDb, aTask[i].x);
|
||||
}
|
||||
launch_thread(&err, &threads, stress2_workload19, (void*)zDb);
|
||||
launch_thread(&err, &threads, stress2_workload19, (void*)zDb);
|
||||
|
||||
join_all_threads(&err, &threads);
|
||||
sqlite3_enable_shared_cache(0);
|
||||
print_and_free_err(&err);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user