New benchmark, fixed for PROFILE_LATCHES.

This commit is contained in:
Sears Russell 2004-10-20 21:55:00 +00:00
parent e05286c9c5
commit aead6a5a83
5 changed files with 111 additions and 11 deletions

View file

@ -1,7 +1,7 @@
LDADD=$(top_builddir)/src/2pc/lib2pc.a $(top_builddir)/src/libdfa/libdfa.a \
$(top_builddir)/src/lladd/liblladd.a $(top_builddir)/src/pbl/libpbl.a \
$(top_builddir)/src/libdfa/librw.a
bin_PROGRAMS=naiveHash logicalHash readLogicalHash naiveMultiThreaded logicalMultThreaded rawSet arrayListSet
bin_PROGRAMS=naiveHash logicalHash readLogicalHash naiveMultiThreaded logicalMultThreaded rawSet arrayListSet logicalMultiReaders
AM_CFLAGS= -g -Wall -pedantic -std=gnu99
SUBDIRS=berkeleyDB

View file

@ -69,5 +69,5 @@ int main(int argc, char** argv) {
}
/* Tdeinit() */
Tdeinit();
}

View file

@ -0,0 +1,85 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <lladd/transactional.h>
#include <unistd.h>
#include <pthread.h>
//static pthread_mutex_t hash_mutex = PTHREAD_MUTEX_INITIALIZER;
static int count;
static recordid hash;
static void * go (void * arg_ptr) {
// pthread_mutex_lock(&hash_mutex);
int k = *(int*)arg_ptr;
int j;
int xid = Tbegin();
unsigned int seed = k;
for(j = 0; j < count ; j++) {
unsigned int r = rand_r(&seed) % 10000;
int tmp;
TlogicalHashLookup(xid, hash, &r, sizeof(int), &tmp, sizeof(int));
assert(r == tmp);
}
// for(j = k * count; j < (k+1) *(count) ; j++) {
// TlogicalHashInsert(xid, hash, &j, sizeof(int), &j, sizeof(int));
// printf("(%d)", k);
//}
Tcommit(xid);
/*
for(j = k * count; j < (k+1) *(count) ; j++) {
int tmp = -100;
TlogicalHashLookup(xid, hash, &j, sizeof(int), &tmp, sizeof(int));
assert(j == tmp);
} */
// pthread_mutex_unlock(&hash_mutex);
return NULL;
}
int main(int argc, char** argv) {
assert(argc == 3);
int thread_count = atoi(argv[1]);
count = atoi(argv[2]);
/* unlink("storefile.txt");
unlink("logfile.txt");
unlink("blob0_file.txt");
unlink("blob1_file.txt");*/
pthread_t * workers = malloc(sizeof(pthread_t) * thread_count);
Tinit();
int xid = Tbegin();
hash = ThashAlloc(xid, sizeof(int), sizeof(int));
int k;
for(k = 0; k < 20000; k++) {
TlogicalHashInsert(xid, hash, &k, sizeof(int), &k, sizeof(int));
}
Tcommit(xid);
for(k = 0; k < thread_count; k++) {
int * k_copy = malloc(sizeof(int));
*k_copy = k ;
pthread_create(&workers[k], NULL, go, k_copy);
}
for(k = 0; k < thread_count; k++) {
pthread_join(workers[k],NULL);
}
Tdeinit();
}

View file

@ -32,8 +32,8 @@ typedef struct {
void instant_expand (int xid, recordid hash, int next_split, int i, int keySize, int valSize);
pthread_mutex_t linearHashMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t bucketUnlocked = PTHREAD_COND_INITIALIZER;
extern pthread_mutex_t linearHashMutex;// = PTHREAD_MUTEX_INITIALIZER;
extern pthread_cond_t bucketUnlocked;// = PTHREAD_COND_INITIALIZER;
extern pblHashTable_t * openHashes ;
/*pblHashTable_t * openHashes = NULL; */
@ -224,27 +224,29 @@ void instant_expand (int xid, recordid hash, int next_split, int i, int keySize,
}
}*/
extern pthread_mutex_t exp_mutex, exp_slow_mutex;
/** you must hold linearHashMutex to call this function, which will release, and reaquire the mutex for you, as apprpriate. */
void instant_expand (int xid, recordid hash, int next_split, int i, int keySize, int valSize) {
/* Total hack; need to do this better, by storing stuff in the hash table headers.*/
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t slow_mutex = PTHREAD_MUTEX_INITIALIZER;
/* static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t slow_mutex = PTHREAD_MUTEX_INITIALIZER; */
static int count = 4096 * .25;
pthread_mutex_lock(&mutex);
pthread_mutex_lock(&exp_mutex);
count --;
int mycount = count;
pthread_mutex_unlock(&mutex);
pthread_mutex_unlock(&exp_mutex);
#define AMORTIZE 1000
#define FF_AM 750
if(mycount <= 0 && !(mycount * -1) % FF_AM) {
pthread_mutex_lock(&slow_mutex);
pthread_mutex_lock(&exp_slow_mutex);
int j;
TarrayListInstantExtend(xid, hash, AMORTIZE);
@ -287,7 +289,7 @@ void instant_expand (int xid, recordid hash, int next_split, int i, int keySize,
instant_update_hash_header(xid, hash, i, next_split);
// pthread_mutex_unlock(&linearHashMutex);
pthread_mutex_unlock(&slow_mutex);
pthread_mutex_unlock(&exp_slow_mutex);
pthread_cond_broadcast(&bucketUnlocked);

View file

@ -2,6 +2,7 @@
#include <lladd/hash.h>
#include <limits.h>
#include <assert.h>
#include <pthread.h>
/**
A from-scratch implementation of linear hashing. Uses the
@ -488,9 +489,21 @@ recordid ThashAlloc(int xid, int keySize, int valSize) {
return rid;
}
pthread_mutex_t exp_mutex;
pthread_mutex_t exp_slow_mutex;
pthread_mutex_t linearHashMutex;
pthread_cond_t bucketUnlocked;
void ThashInit() {
openHashes = pblHtCreate();
lockedBuckets = pblHtCreate();
pthread_mutex_init(&linearHashMutex , NULL);
pthread_cond_init(&bucketUnlocked , NULL);
pthread_mutex_init(&exp_mutex, NULL);
pthread_mutex_init(&exp_slow_mutex, NULL);
}
void ThashDeinit() {