int main(int argc, char** argv) { assert(argc == 3 || argc == 4); int thread_count = atoi(argv[1]); count = atoi(argv[2]); alwaysCommit = (argc==4); unlink("storefile.txt"); unlink("logfile.txt"); unlink("blob0_file.txt"); unlink("blob1_file.txt"); pthread_t * workers = stasis_malloc(thread_count, pthread_t); Tinit(); int xid = Tbegin(); // hash = ThashCreate(xid, sizeof(int), sizeof(int)); hash = ThashCreate(xid, VARIABLE_LENGTH, VARIABLE_LENGTH); Tcommit(xid); int k; /* threads have static thread sizes. Ughh. */ pthread_attr_t attr; pthread_attr_init(&attr); pthread_mutex_init(&mutex, NULL); pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN); // pthread_attr_setschedpolicy(&attr, SCHED_FIFO); pthread_mutex_lock(&mutex); for(k = 0; k < thread_count; k++) { int * k_copy = stasis_alloc(int); *k_copy = k ; pthread_create(&workers[k], &attr, go, k_copy); } pthread_mutex_unlock(&mutex); for(k = 0; k < thread_count; k++) { pthread_join(workers[k],NULL); } Tdeinit(); printf("Committed %d times, put %d times.\n", commitCount, putCount); }
int ReferentialDDL_CreateTable(int xid, ReferentialAlgebra_context_t*context, create *q) { recordid newTable = ThashCreate(xid, VARIABLE_LENGTH, VARIABLE_LENGTH); // XXX assumes first col is a string! tuple_t ridtpl = tupleRid(newTable); tuple_t union_typ_tup = tupleUnion_typ(q->schema); assert(union_typ_tup.count); assert(union_typ_tup.col[0].int64 == string_typ); // XXX ridtpl = tupleCatTuple(ridtpl,union_typ_tup); tupleFree(union_typ_tup); size_t tplLen; byte * tplBytes = byteTuple(ridtpl,&tplLen); ThashInsert(xid,context->hash,(byte*)q->tbl,strlen(q->tbl)+1,tplBytes,tplLen); free(tplBytes); return 1; }
int runSubject(void) { pthread_t* threads; pthread_attr_t attr; intptr_t k; int xid, fd; /* Need the following sleep call for debugging. */ //sleep(45); printf("\tRunning Subject Process\n"); fflush(stdout); readGlobalsFromSharedBuffer(); initHashTable = 1; Tinit(); if (iteration == 0) { /* Create the transactional hash table data structure. */ xid = Tbegin(); hashTable = ThashCreate(xid, sizeof(int), sizeof(int)); Tcommit(xid); /* Write the hash table recordid to a file, so it can be * reloaded during subsequent iterations. */ fd = open("recordid.txt", O_CREAT | O_WRONLY | O_SYNC, 0777); write(fd, (char*) &hashTable, sizeof(recordid)); close(fd); } else { /* Otherwise, read in the hash table from disk. */ fd = open("recordid.txt", O_RDONLY, 0777); read(fd, (char*) &hashTable, sizeof(recordid)); close(fd); } initHashTable = 0; /* Open the insert and commit log files. The insert-log keeps track of all insertions * that were made to the hash-table, not all of which may have been committed. The * commit-log keeps track of all insertions that were definitely committed. */ insertLog = open("inserts.txt", O_CREAT | O_RDWR | O_APPEND, 0777); commitLog = open("commits.txt", O_CREAT | O_RDWR | O_APPEND, 0777); /* Allocate the worker threads. */ threads = stasis_malloc(numThreads, pthread_t); pthread_attr_init(&attr); pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN); pthread_mutex_init(&hashTableMutex, NULL); for (k = 0; k < numThreads; k++) { pthread_create(&threads[k], &attr, threadFunc, (void*) k); } for (k = 0; k < numThreads; k++) { pthread_join(threads[k], NULL); } /* Close the insert and commit log files. */ close(insertLog); close(commitLog); Tdeinit(); printf("\t\tSubject Process Exiting Normally\n"); fflush(stdout); return 0; }
JNIEXPORT jlongArray JNICALL Java_stasis_jni_Stasis_hash_1create (JNIEnv *e, jclass c, jlong xid) { return jlongArray_recordid(e,ThashCreate(xid, VARIABLE_LENGTH, VARIABLE_LENGTH)); }
int main(int argc, char** argv) { assert(argc == 4); int thread_count = atoi(argv[1]) ; // count = atoi(argv[2]); thread_requests_per_sec = (double)(atoi(argv[2])); count = 10.0 * thread_requests_per_sec; alwaysCommit = atoi(argv[3]); printf("%d %f\n", thread_count, thread_requests_per_sec); /* unlink("storefile.txt"); unlink("logfile.txt"); unlink("blob0_file.txt"); unlink("blob1_file.txt"); */ int l; for(l = 0; l < COUNTER_RESOLUTION; l++) { buckets[l] = 0; } pthread_t * workers = stasis_malloc(thread_count, pthread_t); Tinit(); int xid = Tbegin(); hash = ThashCreate(xid, sizeof(int), sizeof(int)); Tcommit(xid); int k; /* threads have static thread sizes. Ughh. */ pthread_attr_t attr; pthread_attr_init(&attr); pthread_mutex_init(&mutex, NULL); pthread_cond_init(&never, NULL); pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN); // pthread_attr_setschedpolicy(&attr, SCHED_FIFO); pthread_mutex_lock(&mutex); for(k = 0; k < thread_count; k++) { int * k_copy = stasis_alloc(int); *k_copy = k ; pthread_create(&workers[k], &attr, go, k_copy); } pthread_mutex_unlock(&mutex); for(k = 0; k < thread_count; k++) { pthread_join(workers[k],NULL); } double log_multiplier = (COUNTER_RESOLUTION / log(MAX_SECONDS * 1000000000.0)); int total = 0; for(k = 0; k < COUNTER_RESOLUTION; k++) { printf("%3.4f\t%d\n", exp(((double)k)/log_multiplier)/1000000000.0, buckets[k]); total += buckets[k]; } printf("Total requests %d\n", total); /* printf("mean: (max, avg) %f, %f\n", max_mean, avg_mean / (double)thread_count); printf("variance: (max, avg) %f, %f\n", max_var, avg_var / (double)thread_count); */ Tdeinit(); }