stasis-aries-wal/benchmarks/bufferManager.c
Gregory Burd 3a559a3b3c merge in changes from svn[r1572..r1601]
------------------------------------------------------------------------
r1601 | sears.russell@gmail.com | 2012-03-20 18:43:00 -0400 (Tue, 20
Mar 2012) | 1 line

commit bLSM bloom filter to stasis/util, which is where it really
belongs
------------------------------------------------------------------------
r1600 | sears.russell@gmail.com | 2012-03-04 01:58:38 -0500 (Sun, 04
Mar 2012) | 1 line

fix memory leak in skiplist unit test (now it is valgrind clean)
------------------------------------------------------------------------
r1599 | sears.russell@gmail.com | 2012-03-04 01:58:05 -0500 (Sun, 04
Mar 2012) | 1 line

fix typo in finalize type
------------------------------------------------------------------------
r1598 | sears.russell@gmail.com | 2012-03-04 00:59:59 -0500 (Sun, 04
Mar 2012) | 1 line

add comparator and finalizer parameters to skiplist constructor
------------------------------------------------------------------------
r1597 | sears.russell@gmail.com | 2012-03-03 18:23:16 -0500 (Sat, 03
Mar 2012) | 1 line

bugfixes for skiplist
------------------------------------------------------------------------
r1596 | sears.russell@gmail.com | 2012-03-02 15:05:07 -0500 (Fri, 02
Mar 2012) | 1 line

updated concurrentSkipList.  Seeing strange crashes
------------------------------------------------------------------------
r1595 | sears.russell@gmail.com | 2012-03-01 16:51:59 -0500 (Thu, 01
Mar 2012) | 1 line

add progress reports
------------------------------------------------------------------------
r1594 | sears.russell@gmail.com | 2012-02-28 13:17:05 -0500 (Tue, 28
Feb 2012) | 1 line

experimental support for automatic logfile preallocation
------------------------------------------------------------------------
r1593 | sears.russell@gmail.com | 2012-02-28 12:10:01 -0500 (Tue, 28
Feb 2012) | 1 line

add histogram reporting to rawIOPS benchmark
------------------------------------------------------------------------
r1592 | sears.russell@gmail.com | 2012-02-24 16:31:36 -0500 (Fri, 24
Feb 2012) | 1 line

userspace raid 0 implementation
------------------------------------------------------------------------
r1591 | sears.russell@gmail.com | 2012-02-12 01:47:25 -0500 (Sun, 12
Feb 2012) | 1 line

add skiplist unit test, fix compile warnings
------------------------------------------------------------------------
r1590 | sears.russell@gmail.com | 2012-02-12 00:52:52 -0500 (Sun, 12
Feb 2012) | 1 line

fix compile error
------------------------------------------------------------------------
r1589 | sears.russell@gmail.com | 2012-02-12 00:50:21 -0500 (Sun, 12
Feb 2012) | 1 line

fix some bugs in hazard.h surrounding thread list management and
overruns of R under high contention
------------------------------------------------------------------------
r1588 | sears.russell@gmail.com | 2012-02-11 14:23:10 -0500 (Sat, 11
Feb 2012) | 1 line

add hazard pointer for get_lock.  It was implicitly blowing away the
hazard pointer protecting y in the caller
------------------------------------------------------------------------
r1587 | sears.russell@gmail.com | 2012-02-10 18:51:25 -0500 (Fri, 10
Feb 2012) | 1 line

fix null pointer bug
------------------------------------------------------------------------
r1586 | sears.russell@gmail.com | 2012-02-10 18:03:39 -0500 (Fri, 10
Feb 2012) | 1 line

add simple refcounting scheme to concurrentSkipList.  This solves the
problem where a deleted node points to another deleted node, and we
only have a hazard pointer for the first node.
------------------------------------------------------------------------
r1585 | sears.russell@gmail.com | 2012-02-10 14:19:14 -0500 (Fri, 10
Feb 2012) | 1 line

add hazard pointers for update using the smallest free slot first.  The
old method left a race condition, since hazard_scan stops at the first
null pointer.
------------------------------------------------------------------------
r1584 | sears.russell@gmail.com | 2012-02-10 02:45:30 -0500 (Fri, 10
Feb 2012) | 1 line

add hazard pointers for update array
------------------------------------------------------------------------
r1583 | sears.russell@gmail.com | 2012-02-10 00:04:50 -0500 (Fri, 10
Feb 2012) | 1 line

skiplist update: concurrent, but broken
------------------------------------------------------------------------
r1582 | sears.russell@gmail.com | 2012-02-09 17:44:27 -0500 (Thu, 09
Feb 2012) | 1 line

skip list implementation.  Not concurrent yet.
------------------------------------------------------------------------
r1581 | sears.russell@gmail.com | 2012-02-08 13:33:29 -0500 (Wed, 08
Feb 2012) | 1 line

Commit of a bunch of new, unused code: KISS random number generator,
Hazard Pointers, SUX latches (untested) and bit twiddling for
concurrent b-tree
------------------------------------------------------------------------
r1580 | sears.russell@gmail.com | 2012-01-17 19:17:37 -0500 (Tue, 17
Jan 2012) | 1 line

fix typo
------------------------------------------------------------------------
r1579 | sears.russell@gmail.com | 2012-01-11 18:33:31 -0500 (Wed, 11
Jan 2012) | 1 line

static build fixes for linux.  hopefully these do not break macos...
------------------------------------------------------------------------
r1578 | sears.russell@gmail.com | 2012-01-09 19:13:34 -0500 (Mon, 09
Jan 2012) | 1 line

fix cmake under linux
------------------------------------------------------------------------
r1577 | sears.russell@gmail.com | 2012-01-09 18:37:15 -0500 (Mon, 09
Jan 2012) | 1 line

fix linux static binary compilation bugs
------------------------------------------------------------------------
r1576 | sears.russell | 2012-01-09 18:00:08 -0500 (Mon, 09 Jan 2012) |
1 line

port to macos x
------------------------------------------------------------------------
r1575 | sears.russell | 2012-01-09 17:39:43 -0500 (Mon, 09 Jan 2012) |
1 line

add missing _ from sync call name
------------------------------------------------------------------------
r1574 | sears.russell@gmail.com | 2012-01-09 14:26:31 -0500 (Mon, 09
Jan 2012) | 1 line

add -rt flag to static builds
------------------------------------------------------------------------
r1573 | sears.russell@gmail.com | 2011-12-20 23:38:29 -0500 (Tue, 20
Dec 2011) | 1 line

Simple makefile geared toward building libstasis.so and libstasis.a
(and nothing else)
------------------------------------------------------------------------
r1572 | sears.russell@gmail.com | 2011-12-20 22:37:54 -0500 (Tue, 20
Dec 2011) | 1 line

add some missing #include<config.h> lines
2012-04-21 12:52:31 -04:00

184 lines
5.4 KiB
C

/*
* bufferManager.c
*
* Created on: Sep 23, 2010
* Author: sears
*/
#include <stasis/flags.h>
#include <stasis/io/handle.h>
#include <stasis/transactional.h>
#include <stasis/util/histogram.h>
#include <stasis/page/fixed.h>
#include <string.h>
#include <assert.h>
#include <pthread.h>
#include <math.h>
#include <stdlib.h>
DECLARE_HISTOGRAM_64(load_hist)
DECLARE_HISTOGRAM_64(release_hist)
struct thread_arg {
unsigned int seed;
unsigned long long num_ops;
double write_frac;
stasis_histogram_64_t * load_hist;
stasis_histogram_64_t * release_hist;
pageid_t page_count;
unsigned long long target_ops;
};
int do_load(pageid_t page_count) {
for(int i = 1; i < page_count; i++) {
Page * p = loadUninitializedPage(-1, i);
stasis_page_fixed_initialize_page(p, sizeof(i), 1);
recordid rid = {i, 0, sizeof(i)};
stasis_record_write(-1, p, rid,(byte*) &i);
stasis_page_lsn_write(-1, p, p->LSN + 1);
releasePage(p);
}
return 0;
}
int do_scan(pageid_t page_count) {
for(int i = 1; i < page_count; i++) {
Page * p = loadPage(-1, i);
recordid rid = {i, 0, sizeof(i)};
stasis_record_write(-1, p, rid,(byte*) &i);
assert(i == rid.page);
releasePage(p);
}
return 0;
}
void * random_op_thread(void * argp) {
struct thread_arg * a = argp;
struct timeval start_time;
gettimeofday(&start_time,0);
int xid = Tbegin();
stasis_log_t * l = stasis_log();
lsn_t lsn = l->next_available_lsn(l);
for(int i = 0; i < a->num_ops; i++) {
pageid_t pid = rand_r(&a->seed) % a->page_count;
int op = (rand_r(&a->seed) < (int)(a->write_frac * (double)RAND_MAX));
struct timeval start;
gettimeofday(&start,0);
double elapsed = stasis_timeval_to_double(stasis_subtract_timeval(start, start_time));
while(a->target_ops &&
elapsed < ((double)i) / (double)a->target_ops) {
struct timespec ts = stasis_double_to_timespec(0.001);
nanosleep(&ts, 0);
gettimeofday(&start,0);
elapsed = stasis_timeval_to_double(stasis_subtract_timeval(start, start_time));
}
stasis_histogram_tick(a->load_hist);
Page * p = loadPage(xid, pid);
stasis_histogram_tock(a->load_hist);
if(op) { // Do write
stasis_page_lsn_write(xid, p, lsn);
}
stasis_histogram_tick(a->release_hist);
releasePage(p);
stasis_histogram_tock(a->release_hist);
}
Tcommit(xid);
free(argp);
return 0;
}
int do_operations(pageid_t page_count, int num_threads, unsigned long long num_ops, double write_frac, int target_ops) {
unsigned long long ops_per_thread = ceil(((double)num_ops) / (double)num_threads);
unsigned long long ops_remaining = num_ops;
pthread_t * threads = malloc(sizeof(threads[0]) * num_threads);
struct timeval tv;
gettimeofday(&tv,0);
uint64_t base_seed = tv.tv_usec;
for(int i = 0; i < num_threads ; i++) {
if(ops_remaining <= 0) { num_threads = i; break; }
struct thread_arg *a = malloc(sizeof(*a));
a->seed = base_seed + i;
a->num_ops = ops_remaining < ops_per_thread ? ops_remaining : ops_per_thread;
a->write_frac = write_frac;
a->load_hist = &load_hist;
a->release_hist = &release_hist;
a->page_count = page_count;
a->target_ops = target_ops / num_threads;
if(i == num_threads - 1) {
a->target_ops = target_ops - (a->target_ops * (num_threads-1));
}
pthread_create(&threads[i], 0, random_op_thread, a);
ops_remaining -= ops_per_thread;
}
for(int i = 0 ; i < num_threads; i++) {
pthread_join(threads[i], 0);
}
return 0;
}
int main(int argc, char * argv[]) {
pageid_t file_size = 1024 * 128;
int load = 0;
int scan = 0;
int threads = 1;
unsigned long long num_ops = 0;
int target_ops = 0;
double write_frac = 0.5;
stasis_buffer_manager_hint_writes_are_sequential = 1;
for(int i = 1; i < argc; i++) {
if(!strcmp(argv[i], "--mem-size")) {
i++;
stasis_buffer_manager_size = atoll(argv[i]) * 1024 * 1024 / PAGE_SIZE;
} else if(!strcmp(argv[i], "--file-size")) {
i++;
file_size = (atoll(argv[i]) * 1024 * 1024) / PAGE_SIZE;
} else if(!strcmp(argv[i], "--load")) {
load = 1;
} else if(!strcmp(argv[i], "--threads")) {
i++;
threads = atoi(argv[i]);
} else if(!strcmp(argv[i], "--scan")) {
scan = 1;
} else if(!strcmp(argv[i], "--numops")) {
i++;
num_ops = atoll(argv[i]);
} else if(!strcmp(argv[i], "--write-frac")) {
i++;
write_frac = atof(argv[i]);
} else if(!strcmp(argv[i], "--target-ops")) {
i++;
target_ops = atoi(argv[i]);
} else if(!strcmp(argv[i], "--raid1")) {
stasis_handle_factory = stasis_handle_raid1_factory;
} else if(!strcmp(argv[i], "--raid0")) {
stasis_handle_factory = stasis_handle_raid0_factory;
} else {
fprintf(stderr, "unknown argument: %s\n", argv[i]);
abort();
}
}
printf("Calling Tinit().\n");
Tinit();
printf("Tinit() done.\n");
if(load) {
printf("Loading %lld pages (%lld megabytes)\n", file_size, (file_size * PAGE_SIZE)/(1024*1024));
do_load(file_size);
}
if(scan) {
printf("Scanning %lld pages (%lld megabytes)\n", file_size, (file_size * PAGE_SIZE)/(1024*1024));
do_scan(file_size);
}
if(num_ops) {
printf("Performing %lld uniform random operations\n", num_ops);
do_operations(file_size, threads, num_ops, write_frac, target_ops);
}
printf("Calling Tdeinit().\n");
Tdeinit();
printf("Tdeinit() done\n");
stasis_histograms_auto_dump();
return 0;
}