2005-03-12 22:11:18 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
// if we're using linux's crazy version of the pthread header,
|
|
|
|
// it probably forgot to include PTHREAD_STACK_MIN
|
|
|
|
|
|
|
|
#ifndef PTHREAD_STACK_MIN
|
|
|
|
#include <limits.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <db.h>
|
|
|
|
|
|
|
|
#define ENV_DIRECTORY "TXNAPP"
|
|
|
|
|
2005-03-20 05:17:25 +00:00
|
|
|
//#define DEBUG_BDB 1
|
|
|
|
|
2005-03-18 23:26:25 +00:00
|
|
|
#include "genericBerkeleyDBCode.c"
|
|
|
|
|
2005-03-20 05:17:25 +00:00
|
|
|
|
2005-03-12 22:11:18 +00:00
|
|
|
int activeThreads = 0;
|
|
|
|
int max_active = 0;
|
|
|
|
|
|
|
|
pthread_mutex_t mutex;
|
2005-03-18 23:26:25 +00:00
|
|
|
|
2005-03-20 05:17:25 +00:00
|
|
|
//int alwaysCommit;
|
2005-03-12 22:11:18 +00:00
|
|
|
int num_xact;
|
|
|
|
int insert_per_xact;
|
|
|
|
void * runThread(void * arg);
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
extern int optind;
|
2005-03-20 05:17:25 +00:00
|
|
|
|
2005-03-12 22:11:18 +00:00
|
|
|
int ch, ret;
|
|
|
|
|
2005-03-20 05:17:25 +00:00
|
|
|
// assert(argc == 3 || argc == 4);
|
|
|
|
assert(argc == 5);
|
|
|
|
|
|
|
|
int alwaysCommit = atoi(argv[3]); // 1; // (argc >= 4);
|
2005-03-19 20:28:30 +00:00
|
|
|
|
2005-03-20 05:17:25 +00:00
|
|
|
int type = atoi(argv[4]) == 1 ? DB_HASH : DB_RECNO;
|
2005-03-17 04:38:55 +00:00
|
|
|
|
2005-03-20 05:17:25 +00:00
|
|
|
printf("type: %d always commit: %d\n", type, alwaysCommit);
|
2005-03-19 20:28:30 +00:00
|
|
|
|
2005-03-20 05:17:25 +00:00
|
|
|
/* threads have static thread sizes. Ughh. */
|
2005-03-12 22:11:18 +00:00
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_attr_setstacksize (&attr, 4 * PTHREAD_STACK_MIN);
|
2005-03-20 05:17:25 +00:00
|
|
|
|
|
|
|
pthread_mutex_init(&mutex, NULL);
|
2005-03-12 22:11:18 +00:00
|
|
|
|
2005-03-20 05:17:25 +00:00
|
|
|
|
2005-03-12 22:11:18 +00:00
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
|
2005-03-20 05:17:25 +00:00
|
|
|
initDB(&attr, type);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-03-12 22:11:18 +00:00
|
|
|
|
|
|
|
int r;
|
2005-03-19 20:28:30 +00:00
|
|
|
int num_threads = atoi(argv[1]);
|
|
|
|
|
2005-03-17 04:38:55 +00:00
|
|
|
if(alwaysCommit) {
|
2005-03-19 20:28:30 +00:00
|
|
|
num_xact = atoi(argv[2]);
|
2005-03-17 04:38:55 +00:00
|
|
|
insert_per_xact = 1;
|
|
|
|
} else {
|
|
|
|
num_xact = 1;
|
|
|
|
insert_per_xact = atoi(argv[2]);
|
|
|
|
}
|
2005-03-20 05:17:25 +00:00
|
|
|
// @todo the test has been crashing for multi-threaded long transactions.
|
|
|
|
assert(num_threads == 1 || alwaysCommit == 1);
|
|
|
|
|
|
|
|
#ifdef DEBUG_BDB
|
|
|
|
printf("num_xact = %d\n insert_per_xact=%d\n", num_xact, insert_per_xact);
|
|
|
|
#endif
|
2005-03-12 22:11:18 +00:00
|
|
|
|
|
|
|
pthread_t * threads = malloc(num_threads * sizeof(pthread_t));
|
|
|
|
int i ;
|
|
|
|
for(i = 0; i < num_threads; i++) {
|
|
|
|
if ((ret = pthread_create(&(threads[i]), &attr, runThread, (void *)i)) != 0){
|
|
|
|
fprintf(stderr,
|
|
|
|
"txnapp: failed spawning worker thread: %s\n",
|
|
|
|
strerror(ret));
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
|
|
|
for(i = 0; i < num_threads; i++) {
|
|
|
|
pthread_join(threads[i], NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(threads);
|
|
|
|
|
2005-03-20 05:17:25 +00:00
|
|
|
db->close(db, 0);
|
|
|
|
dbenv->close(dbenv, 0);
|
|
|
|
|
2005-03-12 22:11:18 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void * runThread(void * arg) {
|
|
|
|
int offset = (int) arg;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
activeThreads++;
|
|
|
|
if(activeThreads > max_active) {
|
|
|
|
max_active = activeThreads;
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
|
|
|
int r;
|
|
|
|
|
|
|
|
for(r = 0; r < num_xact; r ++) {
|
|
|
|
run_xact(dbenv, db_cats, offset*(1+r)*insert_per_xact, insert_per_xact);
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
activeThreads--;
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|