static int accord_init(const char *option, uint8_t *myaddr) { if (!option) { eprintf("specify one of the accord servers.\n"); eprintf("e.g. sheep /store -c accord:127.0.0.1\n"); return -1; } pthread_mutex_lock(&start_lock); ahandle = acrd_init(option, 9090, acrd_join_fn, acrd_leave_fn, NULL); if (!ahandle) { eprintf("failed to connect to accrd server %s\n", option); return -1; } if (get_addr(myaddr) < 0) return -1; efd = eventfd(0, EFD_NONBLOCK); if (efd < 0) { eprintf("failed to create an event fd: %m\n"); return -1; } acrd_wq = init_work_queue(1); if (!acrd_wq) eprintf("failed to create accord workqueue: %m\n"); return -1; }
static int accord_init(const char *option) { int ret; if (!option) { eprintf("specify one of the accord servers.\n"); eprintf("e.g. sheep /store -c accord:127.0.0.1\n"); return -1; } pthread_mutex_lock(&start_lock); ahandle = acrd_init(option, 9090, acrd_join_fn, acrd_leave_fn, NULL); if (!ahandle) { eprintf("failed to connect to accrd server %s\n", option); return -1; } efd = eventfd(0, EFD_NONBLOCK); if (efd < 0) { eprintf("failed to create an event fd: %m\n"); return -1; } acrd_wq = init_work_queue("accord", true); if (!acrd_wq) { eprintf("failed to create accord workqueue: %m\n"); return -1; } pthread_cond_wait(&start_cond, &start_lock); pthread_mutex_unlock(&start_lock); if (need_cleanup) for_each_acrd_file(ahandle, BASE_FILE, __acrd_del, NULL); else { queue_start_pos = -1; queue_end_pos = -1; for_each_acrd_file(ahandle, QUEUE_FILE, find_queue_end, &queue_end_pos); } acrd_add_watch(ahandle, QUEUE_FILE, ACRD_EVENT_PREFIX | ACRD_EVENT_ALL, acrd_watch_fn, NULL); ret = register_event(efd, acrd_handler, NULL); if (ret) { eprintf("failed to register accord event handler (%d)\n", ret); return -1; } return 0; }
/* test code */ int main(int argc, char *argv[]) { struct acrd_handle *bh; uint32_t mask = ACRD_EVENT_ALL | ACRD_EVENT_PREFIX; char *hostname; struct acrd_watch_info *info; if (argc < 2) { printf("usage: watch_nodes [hostname]\n"); return 1; } hostname = argv[1]; bh = acrd_init(hostname, 9090, NULL, NULL, NULL); info = acrd_add_watch(bh, "", mask, watch_cb, NULL); while (1) sleep(1); acrd_close(bh); return 0; }
int main(int argc, char *argv[]) { int i; // FILE *fp; // fp=fopen("results.csv","w"); struct timeval start, end, total; char buffer[10]; double throughput; char prefix[256], url[256]; char *buf; char *readbuf; int ret = -1, prefix_len; int tm; struct acrd_aiocb *acb; struct request_info *ri; buf = calloc(1, msg_size); readbuf = calloc(1, msg_size); memset(buf, 0xFF, msg_size); tm = (unsigned)time(NULL); prefix_len = sprintf(prefix, "/tmp/%s/", localhost); strcpy(url, prefix); total_n_handled = 0; total_n_launched = 0; total_n_bytes = 0; if (argc < 6) { printf("usage: acrdbench [host] [n_threads] [n_reqs] " "[msg_size] [sync_mode]\n"); return 1; } gethostname(localhost, sizeof(localhost)); setvbuf(stdout, NULL, _IONBF, 0); remotehost = argv[1]; n_threads = atoi(argv[2]); n_requests = atoi(argv[3]); msg_size = atoi(argv[4]); if (!strcasecmp(argv[5], "nosync")) sync_mode = 0; else if (!strcasecmp(argv[5], "sync")) sync_mode = ACRD_FLAG_SYNC; else { fprintf(stderr, "sync mode must be \"nosync\" or \"sync\"\n"); return 1; } gettimeofday(&start, NULL); ri = malloc(sizeof(*ri)); ri->bh = acrd_init(remotehost, 9090, NULL, NULL, NULL); if (!ri->bh) { eprintf("failed to initialize library\n"); pthread_exit(NULL); } printf("%d",n_requests); for (i = 0; i < n_requests; i++) { printf("%d\n",i); sprintf(url + prefix_len, "%d", __sync_add_and_fetch(&total_n_launched, 1)); acb = acrd_aio_setup(ri->bh, acrdbench_aio_cb, NULL); again: ret = acrd_aio_write(ri->bh, url, buf, msg_size, 0, ACRD_FLAG_CREATE | sync_mode,acb); if (ret != ACRD_SUCCESS) { if (ret == ACRD_ERR_AGAIN) { usleep(100000); //printf("going to again"); goto again; } eprintf("err, %d\n", ret); exit(1); } againred: ret=acrd_aio_read(ri->bh,url,&readbuf,&read_msg_size,0,NULL,acb); printf("%d",ret); printf("readmessage %s\n",&readbuf); if (ret != ACRD_SUCCESS) { if (ret == ACRD_ERR_AGAIN) { usleep(100000); //printf("going to again"); goto againred; } eprintf("err, %d\n", ret); exit(1); } againdel: ret=acrd_aio_del(ri->bh,url,NULL,acb); if (ret != ACRD_SUCCESS) { if (ret == ACRD_ERR_AGAIN) { usleep(100000); //printf("going to again"); goto againdel; } eprintf("err, %d\n", ret); exit(1); } } //acrd_aio_flush(ri->bh); gettimeofday(&end, NULL); timersub(&end, &start, &total); throughput = n_requests / (total.tv_sec + ((double)total.tv_usec)/1000000.0); printf("%d,%d.%06d,%.2f\n",n_requests, (int)total.tv_sec, (int)total.tv_usec,throughput); free(buf); free(readbuf); return 0; }