Ejemplo n.º 1
0
void
test_list(void)
{
    struct histogram *hist1 = histogram_create("hist1");
    struct histogram *hist2 = histogram_create("hist2");
    struct histogram *hist3 = aim_zmalloc(sizeof(*hist3));
    histogram_register(hist3, "hist3");

    AIM_ASSERT(!strcmp(hist1->name, "hist1"));
    AIM_ASSERT(!strcmp(hist2->name, "hist2"));
    AIM_ASSERT(!strcmp(hist3->name, "hist3"));

    struct list_head *head = histogram_list();

    struct list_links *cur = list_first(head);
    AIM_ASSERT(container_of(cur, links, struct histogram) == hist1);

    cur = cur->next;
    AIM_ASSERT(container_of(cur, links, struct histogram) == hist2);

    cur = cur->next;
    AIM_ASSERT(container_of(cur, links, struct histogram) == hist3);

    AIM_ASSERT(cur->next == &head->links);

    histogram_destroy(hist1);
    histogram_destroy(hist2);
    histogram_unregister(hist3);
    aim_free(hist3);
}
Ejemplo n.º 2
0
void
test_basic(void)
{
    struct histogram *hist = histogram_create("basic");

    check(hist, 0, 0);

    histogram_inc(hist, 0);
    check(hist, 0, 1);

    histogram_inc(hist, 0);
    check(hist, 0, 2);

    /* 1 is a different bucket */
    histogram_inc(hist, 1);
    check(hist, 1, 1);

    /* 32 and 33 are the same bucket */
    histogram_inc(hist, 32);
    histogram_inc(hist, 33);
    check(hist, 32, 2);
    check(hist, 33, 2);

    histogram_inc(hist, UINT32_MAX);
    check(hist, UINT32_MAX, 1);

    histogram_destroy(hist);
}
Ejemplo n.º 3
0
void
test_all(void)
{
    struct histogram *hist = histogram_create("all");
    uint32_t k;

    for (k = 0; k < UINT32_MAX; k++) {
        check(hist, k, 0);
    }
    check(hist, k, 0);

    for (k = 0; k < UINT32_MAX; k++) {
        histogram_inc(hist, k);
    }
    histogram_inc(hist, k);

    for (k = 0; k < 16; k++) {
        check(hist, k, 1);
    }

    int i;
    for (i = 4; i < 32; i++) {
        uint32_t c = (1u << i) / 16;
        for (k = 1<<i; k < (2<<i) - 1; k++) {
            check(hist, k, c);
        }
        check(hist, k, c);
    }

    histogram_destroy(hist);
}
Ejemplo n.º 4
0
int main(int argc, char **argv) {

	// use bucket size of .5
	struct histogram *h = histogram_create(.5);

	// bucket [3.0, 3.5)
	histogram_insert(h, 3.00);
	histogram_insert(h, 3.14);

	// bucket [21.5, 22.0)
	histogram_insert(h, 21.99);

	// bucket [22.0, 22.5)
	histogram_insert(h, 22.00);
	histogram_insert(h, 22.20);
	histogram_insert(h, 22.49);

	// bucket [22.5, 23.0)
	histogram_insert(h, 22.50);
	histogram_insert(h, 22.99);

	// bucket [-22.0, -21.5)
	histogram_insert(h, -21.51);
	histogram_insert(h, -22.00);

	// bucket [-21.5, -21.0)
	histogram_insert(h, -21.49);
	histogram_insert(h, -21.20);
	histogram_insert(h, -21.01);

	double *buckets = histogram_buckets(h);
	double b        = histogram_bucket_size(h);

	int expected_counts[] = {2, 3, 2, 1, 3, 2};

	int i;
	for(i = 0; i < histogram_size(h); i++) {

		double start = buckets[i];
		int count    = histogram_count(h, start);

		if(expected_counts[i] != count) {
			fprintf(stderr, "Expected a count of %d, got %d.", expected_counts[i], count);
			return -1;
		}

		fprintf(stdout, "[%6.2lf, %6.2f) count: %d\n", start, start + b, histogram_count(h, start));
	}

	fprintf(stdout, "max: %6.2lf\n",    histogram_max_value(h));
	fprintf(stdout, "min: %6.2lf\n",    histogram_min_value(h));
	fprintf(stdout, "mode: %6.2lf\n",   histogram_mode(h));
	fprintf(stdout, "mode count: %d\n", histogram_count(h, histogram_mode(h)));

	free(buckets);
	histogram_delete(h);

	return 0;
}
Ejemplo n.º 5
0
void
test_find(void)
{
    AIM_ASSERT(histogram_find("hist1") == NULL);
    AIM_ASSERT(histogram_find("hist2") == NULL);

    struct histogram *hist1 = histogram_create("hist1");
    AIM_ASSERT(histogram_find("hist1") == hist1);
    AIM_ASSERT(histogram_find("hist2") == NULL);

    struct histogram *hist2 = histogram_create("hist2");
    AIM_ASSERT(histogram_find("hist1") == hist1);
    AIM_ASSERT(histogram_find("hist2") == hist2);

    histogram_destroy(hist1);
    AIM_ASSERT(histogram_find("hist1") == NULL);
    AIM_ASSERT(histogram_find("hist2") == hist2);

    histogram_destroy(hist2);
    AIM_ASSERT(histogram_find("hist1") == NULL);
    AIM_ASSERT(histogram_find("hist2") == NULL);
}
Ejemplo n.º 6
0
int main(){
        timer_util* tu = malloc(sizeof(timer_util));
        int i, j, k;
        initialize_timer(tu);
        struct histogram* hist = histogram_create(0, 20000, 10);
        for(i = 0; i < NUM_TIMER; i++){
                timer_set_mode(tu, i, 1);
        }
        for(i = 0; i < 100; i++){
                for(j = 0; j < NUM_TIMER; j++){
                        timer_start(tu, j);
                        for(k = 0; k < 1000000; k++){}
                        timer_end_hist(tu, j, hist);
                        printf("Timer #%d min: %"PRIu64"\n", j, timer_min(tu, j));
                        printf("Timer #%d max: %"PRIu64"\n", j, timer_max(tu, j));
                        printf("Timer #%d avg: %"PRIu64"\n\n", j, timer_avg(tu, j));
                }
        }
        histogram_print(hist);
        return 0;
}
Ejemplo n.º 7
0
Archivo: act.c Proyecto: aanguss/act
int main(int argc, char* argv[]) {
	signal(SIGSEGV, as_sig_handle_segv);
	signal(SIGTERM , as_sig_handle_term);

	fprintf(stdout, "\nAerospike act - device IO test\n");
	fprintf(stdout, "Copyright 2011 by Aerospike. All rights reserved.\n\n");

	if (! configure(argc, argv)) {
		exit(-1);
	}

	set_schedulers();
	srand(time(NULL));
//	rand_seed(g_rand_64_buffer);

	salter salters[g_num_write_buffers ? g_num_write_buffers : 1];

	g_salters = salters;

	if (! create_salters()) {
		exit(-1);
	}

	device devices[g_num_devices];
	readq readqs[g_num_queues];

	g_devices = devices;
	g_readqs = readqs;

	// TODO - 'salt' drive?

	g_p_large_block_read_histogram = histogram_create();
	g_p_large_block_write_histogram = histogram_create();
	g_p_raw_read_histogram = histogram_create();
	g_p_read_histogram = histogram_create();

	g_run_start_us = cf_getus();

	uint64_t run_stop_us = g_run_start_us + g_run_us;

	g_running = 1;

	for (int n = 0; n < g_num_devices; n++) {
		device* p_device = &g_devices[n];

		p_device->name = g_device_names[n];
		p_device->p_fd_queue = cf_queue_create(sizeof(int), true);
		discover_num_blocks(p_device);
		create_large_block_read_buffer(p_device);
		p_device->p_raw_read_histogram = histogram_create();
		sprintf(p_device->histogram_tag, "%-18s", p_device->name);

		if (pthread_create(&p_device->large_block_read_thread, NULL,
				run_large_block_reads, (void*)p_device)) {
			fprintf(stdout, "ERROR: create large block read thread %d\n", n);
			exit(-1);
		}

		if (pthread_create(&p_device->large_block_write_thread, NULL,
				run_large_block_writes, (void*)p_device)) {
			fprintf(stdout, "ERROR: create write thread %d\n", n);
			exit(-1);
		}
	}

	for (int i = 0; i < g_num_queues; i++) {
		readq* p_readq = &g_readqs[i];

		p_readq->p_req_queue = cf_queue_create(sizeof(readreq*), true);
		p_readq->threads = malloc(sizeof(pthread_t) * g_threads_per_queue);

		for (int j = 0; j < g_threads_per_queue; j++) {
			if (pthread_create(&p_readq->threads[j], NULL, run_reads,
					(void*)p_readq->p_req_queue)) {
				fprintf(stdout, "ERROR: create read thread %d:%d\n", i, j);
				exit(-1);
			}
		}
	}

	pthread_t thr_add_readreqs;

	if (pthread_create(&thr_add_readreqs, NULL, run_add_readreqs, NULL)) {
		fprintf(stdout, "ERROR: create thread thr_add_readreqs\n");
		exit(-1);
	}

	fprintf(stdout, "\n");

	uint64_t now_us;
	uint64_t count = 0;

	while ((now_us = cf_getus()) < run_stop_us && g_running) {	
		count++;

		int sleep_us = (int)
			((count * g_report_interval_us) - (now_us - g_run_start_us));

		if (sleep_us > 0) {
			usleep((uint32_t)sleep_us);
		}

		fprintf(stdout, "After %" PRIu64 " sec:\n",
			(count * g_report_interval_us) / 1000000);

		fprintf(stdout, "read-reqs queued: %" PRIu64 "\n",
			cf_atomic_int_get(g_read_reqs_queued));

		histogram_dump(g_p_large_block_read_histogram,  "LARGE BLOCK READS ");
		histogram_dump(g_p_large_block_write_histogram, "LARGE BLOCK WRITES");
		histogram_dump(g_p_raw_read_histogram,          "RAW READS         ");

		for (int d = 0; d < g_num_devices; d++) {			
			histogram_dump(g_devices[d].p_raw_read_histogram,
				g_devices[d].histogram_tag);	
		}

		histogram_dump(g_p_read_histogram,              "READS             ");
		fprintf(stdout, "\n");
		fflush(stdout);
	}

	g_running = 0;

	void* pv_value;

	pthread_join(thr_add_readreqs, &pv_value);

	for (int i = 0; i < g_num_queues; i++) {
		readq* p_readq = &g_readqs[i];

		for (int j = 0; j < g_threads_per_queue; j++) {
			pthread_join(p_readq->threads[j], &pv_value);
		}

		cf_queue_destroy(p_readq->p_req_queue);
		free(p_readq->threads);
	}

	for (int d = 0; d < g_num_devices; d++) {
		device* p_device = &g_devices[d];

		pthread_join(p_device->large_block_read_thread, &pv_value);
		pthread_join(p_device->large_block_write_thread, &pv_value);

		fd_close_all(p_device);
		cf_queue_destroy(p_device->p_fd_queue);
		free(p_device->p_large_block_read_buffer);
		free(p_device->p_raw_read_histogram);
	}

	free(g_p_large_block_read_histogram);
	free(g_p_large_block_write_histogram);
	free(g_p_raw_read_histogram);
	free(g_p_read_histogram);

	destroy_salters();

	return (0);
}
Ejemplo n.º 8
0
int main(int argc, char * argv[])
{
  //============================================
  // Set input parameters
   if (argc < 4|| argc > 4){
     printf("Wrong number of inputs. You entered %d. You should enter 4\n.", argc);
     myusage();
   }
  int XLENGTH = atoi(argv[1]);
  int YLENGTH = atoi(argv[2]);
  int NCLUST = atoi(argv[3]);
  int HLENGTH;
  double px[XLENGTH];
  double py[YLENGTH];
  double beta = .00001;
  double F;
  double infocurve[4] = {1,1,1,1};
  //int modus = 0;
  // modus = 0 : use p(y|c) cluster centers as initialization
  // modus = 1 : use p(c|x) assignment ruls as initialization
  double annealingrate = 1.1;
  bool plotme = true; //some debug printing
  bool debug = false;//verbose debug printing


  FILE * histFile;
  FILE * probFile;
  histogram_t *histo;
  histogram_t *pxy;
  histogram_t *pygc;
  histogram_t *pcgx;
  histogram_t *pc;

  if(plotme)
  {
    printf("XLENGTH= %d\n", XLENGTH);
    printf("YLENGTH= %d\n", YLENGTH);
    printf("NCLUST = %d\n", NCLUST);
  }

  histFile = fopen(histoName, "r");
  if(histFile == NULL)
  {
    printf("Error: can't access %s\n", histoName);
    exit(1);
  }
  float v;
  int j,i = 0;
  int y;
  int x;
  char s [YLENGTH*20];
  char * tok;

//   //allocate memory for large cluster probability arrays
//   double** pygc;
//   //allocate pointer memory for first dimension
//   pygc = (double**)malloc(YLENGTH*sizeof(double));
//   if(NULL == pygc){free(pygc); printf("Memory allocation failed while allocating for pygc[].\n"); exit(-1);}
//
//   /*allocate memory for second dimension */
//   for(i = 0; i < YLENGTH;i++)
//   {
//     pygc[i] = (double *) malloc( NCLUST * sizeof(double) );
//     if(NULL == pygc[i]){free(pygc[i]); printf("Memory allocation failed while allocating for matrix[x][].\n"); exit(-1);}
//   }
//
//   double** pcgx;
//   //allocate pointer memory for first dimension
//   pcgx = (double**)malloc(NCLUST*sizeof(double));
//   if(NULL == pcgx){free(pcgx); printf("Memory allocation failed while allocating for pcgx[].\n"); exit(-1);}
//
//   /*allocate memory for second dimension */
//   for(i = 0; i < NCLUST;i++)
//   {
//     pcgx[i] = (double *) malloc( XLENGTH * sizeof(double) );
//     if(NULL == pcgx[i]){free(pcgx[i]); printf("Memory allocation failed while allocating for matrix[x][].\n"); exit(-1);}
//   }

  //count how many entries are actually in the histogram file -- these are only the non-zero p(y|x)
  while(fscanf(histFile, "%f", &v)!= EOF)
  {
     i++;
  }
   rewind(histFile);
   if(debug){printf("Counted %d entries in histogram file\n", i);}
   //make histogram size 1/2 number entries counted because 1/2 are the indices (y values)
   HLENGTH = i/2;
   histo = histogram_create(HLENGTH);
   x = 0;
  //make p(y|x) histogram
  //YLENGTH*20 is assuming most words are less than 20 chars long
  while(fgets(s, (YLENGTH*20), histFile)!= NULL)
  {
    tok = strtok(s,"\t");
    while(tok != NULL)
    {
      if(debug){printf("Found word: %d\n", atoi(tok));}
      y = atoi(tok);
      tok = strtok(NULL, "\t");
      if(tok != NULL) //hits null in the word
      {
	if(debug){printf("Found value: %f\n", atof(tok));}
	v = atof(tok);
	tok = strtok(NULL, "\t");
	histogram_set(histo,x,y,v);
      }
    }
    x++;
  }
  if(debug)
  {
    printf("Checking histogram\n");
    for(x = 0; x < XLENGTH; x++)
    {
      for(y = 0; y < YLENGTH; y++)
      {
	  if((v = histogram_get(histo, x, y)))
	  {
	    printf("Found doc %d - word %d in histo: %f\n",x,y,v);
	  }
      }
    }
  }
  fclose(histFile);
  // now read in the other initial probs
  probFile = fopen(probName, "r");
  if(probFile == NULL)
  {
    printf("Error: can't access %s\n", histoName);
    exit(1);
  }
//*********** p(x) is first line *******************
  printf("read in p(x)\n");
  fgets(s, (XLENGTH*20), probFile);
  //printf("s = %s\n",s);
 // printf("length of s = %d\n", strlen(s));
  tok = strtok(s,"\t");
  x = 0;
  while(tok != NULL)
  {
    //printf("tok = %s\n", tok);
    if(strcmp(tok,"\n") != 0)
    {
      px[x] = atof(tok);
      //printf("px(%d) = %f\n", x, px[x]);
      x++;
    }
    tok = strtok(NULL,"\t");
  }
  //second line is blank
  fgets(s, (YLENGTH*20), probFile);
  //************** p(y) is third line ************************
  fgets(s, (YLENGTH*20), probFile);
  printf("read in p(y)\n");
 // printf("s = %s\n",s);
 // printf("length of s = %d\n", strlen(s));
  tok = strtok(s,"\t");
  x = 0;
  while(tok != NULL)
  {
    if(strcmp(tok,"\n") != 0)
    {
      py[x] = atof(tok);
     // printf("py(%d) = %f\n", x, py[x]);
      x++;
    }
    tok = strtok(NULL,"\t");
  }
  //fourth line is blank
  fgets(s,(YLENGTH*20), probFile);
  //******************** fifth line on is p(xy)
  printf("Making p(x;y)\n");
  pxy = histogram_create(HLENGTH);
  x = 0;
  while(fgets(s, (YLENGTH*20), probFile)!= NULL)
  {
    //get line for doc
    //printf("Found %s\n", s);
    //split y and p
     tok = strtok(s,"\t");
     while(tok != NULL)
     {
      //printf("Found word: %d\n", atoi(tok));
      y = atoi(tok);
      tok = strtok(NULL, "\t");
      if(tok != NULL) //hits null in the word
      {
	//printf("Found value: %f\n", atof(tok));
	v = atof(tok);
	tok = strtok(NULL, "\t");
	histogram_set(pxy,x,y,v);
      }
    }
    x++;
  }
  fclose(probFile);
  if(debug){
   printf("Checking pxy\n");
    for(x = 0; x < XLENGTH; x++)
    {
      for(y = 0; y < YLENGTH; y++)
      {
	if((v = histogram_get(pxy, x, y)))
	{
	  printf("Found doc %d - word %d in histo: %f\n",x,y,v);
	}
      }
    }
  }
//****************** initialize cluster probs *****************************
printf("Making p(c|x)\n");
ini_pcgx(NCLUST, XLENGTH, pcgx);
printf("Now going to anneal\n");
//******************* NOW GO TO ANNEAL **************************
F = anneal(XLENGTH, YLENGTH, NCLUST, beta, pxy, histo, pcgx, pygc, pc,
		   infocurve, annealingrate, plotme);

printf("Returned from anneal\n");
  //cleanup
  histogram_destroy(pxy);
  histogram_destroy(histo);
  histogram_destroy(pygc);
  histogram_destroy(pcgx);
  histogram_destroy(pc);
//   for(i = 0; i < YLENGTH; i++)
//     free(pygc[i]);
//   free(pygc);
//   for(i = 0; i < NCLUST; i++)
//     free(pcgx[i]);
//   free(pcgx);

  exit(1);
}
Ejemplo n.º 9
0
int
main(int argc, char* argv[])
{
	signal_setup();

	fprintf(stdout, "\nACT version %s\n", VERSION);
	fprintf(stdout, "Storage device IO test\n");
	fprintf(stdout, "Copyright 2018 by Aerospike. All rights reserved.\n\n");

	if (! storage_configure(argc, argv)) {
		exit(-1);
	}

	device devices[g_scfg.num_devices];
	queue* trans_qs[g_scfg.num_queues];

	g_devices = devices;
	g_trans_qs = trans_qs;

	histogram_scale scale =
			g_scfg.us_histograms ? HIST_MICROSECONDS : HIST_MILLISECONDS;

	if (! (g_large_block_read_hist = histogram_create(scale)) ||
		! (g_large_block_write_hist = histogram_create(scale)) ||
		! (g_raw_read_hist = histogram_create(scale)) ||
		! (g_read_hist = histogram_create(scale)) ||
		! (g_raw_write_hist = histogram_create(scale)) ||
		! (g_write_hist = histogram_create(scale))) {
		exit(-1);
	}

	for (uint32_t n = 0; n < g_scfg.num_devices; n++) {
		device* dev = &g_devices[n];

		dev->name = (const char*)g_scfg.device_names[n];

		if (g_scfg.file_size == 0) { // normally 0
			set_scheduler(dev->name, g_scfg.scheduler_mode);
		}

		if (! (dev->fd_q = queue_create(sizeof(int), true)) ||
			! discover_device(dev) ||
			! (dev->raw_read_hist = histogram_create(scale)) ||
			! (dev->raw_write_hist = histogram_create(scale))) {
			exit(-1);
		}

		sprintf(dev->read_hist_tag, "%s-reads", dev->name);
		sprintf(dev->write_hist_tag, "%s-writes", dev->name);
	}

	rand_seed();

	g_run_start_us = get_us();

	uint64_t run_stop_us = g_run_start_us + g_scfg.run_us;

	g_running = true;

	if (g_scfg.write_reqs_per_sec != 0) {
		for (uint32_t n = 0; n < g_scfg.num_devices; n++) {
			device* dev = &g_devices[n];

			if (pthread_create(&dev->large_block_read_thread, NULL,
					run_large_block_reads, (void*)dev) != 0) {
				fprintf(stdout, "ERROR: create large op read thread\n");
				exit(-1);
			}

			if (pthread_create(&dev->large_block_write_thread, NULL,
					run_large_block_writes, (void*)dev) != 0) {
				fprintf(stdout, "ERROR: create large op write thread\n");
				exit(-1);
			}
		}
	}

	if (g_scfg.tomb_raider) {
		for (uint32_t n = 0; n < g_scfg.num_devices; n++) {
			device* dev = &g_devices[n];

			if (pthread_create(&dev->tomb_raider_thread, NULL,
					run_tomb_raider, (void*)dev) != 0) {
				fprintf(stdout, "ERROR: create tomb raider thread\n");
				exit(-1);
			}
		}
	}

	uint32_t n_trans_tids = g_scfg.num_queues * g_scfg.threads_per_queue;
	pthread_t trans_tids[n_trans_tids];

	for (uint32_t i = 0; i < g_scfg.num_queues; i++) {
		if (! (g_trans_qs[i] = queue_create(sizeof(trans_req), true))) {
			exit(-1);
		}

		for (uint32_t j = 0; j < g_scfg.threads_per_queue; j++) {
			if (pthread_create(&trans_tids[(i * g_scfg.threads_per_queue) + j],
					NULL, run_transactions, (void*)g_trans_qs[i]) != 0) {
				fprintf(stdout, "ERROR: create transaction thread\n");
				exit(-1);
			}
		}
	}

	// Equivalent: g_scfg.internal_read_reqs_per_sec != 0.
	bool do_reads = g_scfg.read_reqs_per_sec != 0;

	pthread_t read_req_tids[g_scfg.read_req_threads];

	if (do_reads) {
		for (uint32_t k = 0; k < g_scfg.read_req_threads; k++) {
			if (pthread_create(&read_req_tids[k], NULL, run_generate_read_reqs,
					NULL) != 0) {
				fprintf(stdout, "ERROR: create read request thread\n");
				exit(-1);
			}
		}
	}

	// Equivalent: g_scfg.internal_write_reqs_per_sec != 0.
	bool do_commits = g_scfg.commit_to_device && g_scfg.write_reqs_per_sec != 0;

	pthread_t write_req_tids[g_scfg.write_req_threads];

	if (do_commits) {
		for (uint32_t k = 0; k < g_scfg.write_req_threads; k++) {
			if (pthread_create(&write_req_tids[k], NULL,
					run_generate_write_reqs, NULL) != 0) {
				fprintf(stdout, "ERROR: create write request thread\n");
				exit(-1);
			}
		}
	}

	fprintf(stdout, "\nHISTOGRAM NAMES\n");

	if (do_reads) {
		fprintf(stdout, "reads\n");
		fprintf(stdout, "device-reads\n");

		for (uint32_t d = 0; d < g_scfg.num_devices; d++) {
			fprintf(stdout, "%s\n", g_devices[d].read_hist_tag);
		}
	}

	if (g_scfg.write_reqs_per_sec != 0) {
		fprintf(stdout, "large-block-reads\n");
		fprintf(stdout, "large-block-writes\n");
	}

	if (do_commits) {
		fprintf(stdout, "writes\n");
		fprintf(stdout, "device-writes\n");

		for (uint32_t d = 0; d < g_scfg.num_devices; d++) {
			fprintf(stdout, "%s\n", g_devices[d].write_hist_tag);
		}
	}

	fprintf(stdout, "\n");

	uint64_t now_us = 0;
	uint64_t count = 0;

	while (g_running && (now_us = get_us()) < run_stop_us) {
		count++;

		int64_t sleep_us = (int64_t)
				((count * g_scfg.report_interval_us) -
						(now_us - g_run_start_us));

		if (sleep_us > 0) {
			usleep((uint32_t)sleep_us);
		}

		fprintf(stdout, "after %" PRIu64 " sec:\n",
				(count * g_scfg.report_interval_us) / 1000000);

		fprintf(stdout, "requests-queued: %" PRIu32 "\n",
				atomic32_get(g_reqs_queued));

		if (do_reads) {
			histogram_dump(g_read_hist, "reads");
			histogram_dump(g_raw_read_hist, "device-reads");

			for (uint32_t d = 0; d < g_scfg.num_devices; d++) {
				histogram_dump(g_devices[d].raw_read_hist,
						g_devices[d].read_hist_tag);
			}
		}

		if (g_scfg.write_reqs_per_sec != 0) {
			histogram_dump(g_large_block_read_hist, "large-block-reads");
			histogram_dump(g_large_block_write_hist, "large-block-writes");
		}

		if (do_commits) {
			histogram_dump(g_write_hist, "writes");
			histogram_dump(g_raw_write_hist, "device-writes");

			for (uint32_t d = 0; d < g_scfg.num_devices; d++) {
				histogram_dump(g_devices[d].raw_write_hist,
						g_devices[d].write_hist_tag);
			}
		}

		fprintf(stdout, "\n");
		fflush(stdout);
	}

	g_running = false;

	if (do_reads) {
		for (uint32_t k = 0; k < g_scfg.read_req_threads; k++) {
			pthread_join(read_req_tids[k], NULL);
		}
	}

	if (do_commits) {
		for (uint32_t k = 0; k < g_scfg.write_req_threads; k++) {
			pthread_join(write_req_tids[k], NULL);
		}
	}

	for (uint32_t j = 0; j < n_trans_tids; j++) {
		pthread_join(trans_tids[j], NULL);
	}

	for (uint32_t i = 0; i < g_scfg.num_queues; i++) {
		queue_destroy(g_trans_qs[i]);
	}

	for (uint32_t d = 0; d < g_scfg.num_devices; d++) {
		device* dev = &g_devices[d];

		if (g_scfg.tomb_raider) {
			pthread_join(dev->tomb_raider_thread, NULL);
		}

		if (g_scfg.write_reqs_per_sec != 0) {
			pthread_join(dev->large_block_read_thread, NULL);
			pthread_join(dev->large_block_write_thread, NULL);
		}

		fd_close_all(dev);
		queue_destroy(dev->fd_q);
		free(dev->raw_read_hist);
		free(dev->raw_write_hist);
	}

	free(g_large_block_read_hist);
	free(g_large_block_write_hist);
	free(g_raw_read_hist);
	free(g_read_hist);
	free(g_raw_write_hist);
	free(g_write_hist);

	return 0;
}
Ejemplo n.º 10
0
int main(int argc, char* argv[]) {
	signal(SIGSEGV, as_sig_handle_segv);
	signal(SIGTERM, as_sig_handle_term);
	

	fprintf(stdout, "\nAerospike act - device IO test\n");
	fprintf(stdout, "Copyright 2011 by Aerospike. All rights reserved.\n\n");

	if (! configure(argc, argv)) {
		exit(-1);
	}

	set_schedulers();
	srand(time(NULL));
	//	rand_seed(g_rand_64_buffer);

	salter salters[g_num_write_buffers ? g_num_write_buffers : 1];

	g_salters = salters;

	if (! create_salters()) {
		exit(-1);
	}

	device devices[g_num_devices];
	g_devices = devices;

	g_p_large_block_read_histogram = histogram_create();
	g_p_large_block_write_histogram = histogram_create();
	g_p_raw_read_histogram = histogram_create();
	g_p_read_histogram = histogram_create();

	g_run_start_ms = cf_getms();

	uint64_t run_stop_ms = g_run_start_ms + g_run_ms;

	g_running = 1;
	int n;
	for (n = 0; n < g_num_devices; n++) 
	{
		device* p_device = &g_devices[n];
		p_device->name = g_device_names[n];
		p_device->p_fd_queue = cf_queue_create(sizeof(int), true);
		discover_num_blocks(p_device);
		create_large_block_read_buffer(p_device);
		p_device->p_raw_read_histogram = histogram_create();
		sprintf(p_device->histogram_tag, "%-18s", p_device->name);

		if (pthread_create(&p_device->large_block_read_thread, NULL,
					run_large_block_reads, (void*)p_device)) 
		{
			fprintf(stdout, "Error: create large block read thread %d\n", n);
			exit(-1);
		}

		if (pthread_create(&p_device->large_block_write_thread, NULL,
					run_large_block_writes, (void*)p_device)) 
		{
			fprintf(stdout, "Error: create write thread %d\n", n);
			exit(-1);
		}

	}

	aio_context_t aio_context = 0;
	if(io_setup(MAXEVENTS, &aio_context) != 0)
	{
		fprintf(stdout, "Error: AIO context not set up \n");
		exit(-1);
	}
	create_async_info_queue();

	/* read events generating thread */
	pthread_t read_generator;
	if (pthread_create(&read_generator, NULL, &generate_async_reads, (void*)&aio_context)) 
	{
		fprintf(stdout, "Error: create read generator thread\n");
		exit(-1);
	}
	
	/* Create the worker threads */
	pthread_t workers[g_worker_threads];
	int j;
	for (j = 0; j < g_worker_threads; j++) 
	{ 
		if (pthread_create(&workers[j], NULL, &worker_func , (void *)(&aio_context))) 
		{
			fprintf(stdout, "Error: creating worker thread %d failed\n", j);
			exit(-1);
		}	
	}
 
	fprintf(stdout, "\n");
	uint64_t now_ms;
	uint64_t time_count = 0;
	int nanosleep_ret = -1;
	struct timespec initial,remaining;
	while ((now_ms = cf_getms()) < run_stop_ms && g_running) 
	{	
		time_count++;
		int sleep_ms = (int)
			((time_count * g_report_interval_ms) - (now_ms - g_run_start_ms));
		if (sleep_ms > 0) 
		{
			initial.tv_sec = sleep_ms / 1000;
			initial.tv_nsec = (sleep_ms % 1000) * 1000000;
		retry:
			memset(&remaining, 0, sizeof(remaining));
			nanosleep_ret = nanosleep(&initial, &remaining);
			if(nanosleep_ret == -1 && errno == EINTR)
			{
				/* Interrupted by a signal */
				initial.tv_sec = remaining.tv_sec;
				initial.tv_nsec = remaining.tv_nsec;	
				goto retry;	
			}
		}

		fprintf(stdout, "After %" PRIu64 " sec:\n",
				(time_count * g_report_interval_ms) / 1000);

		fprintf(stdout, "read-reqs queued: %" PRIu64 "\n",
				cf_atomic_int_get(g_read_reqs_queued));

		histogram_dump(g_p_large_block_read_histogram,  "LARGE BLOCK READS ");
		histogram_dump(g_p_large_block_write_histogram, "LARGE BLOCK WRITES");
		histogram_dump(g_p_raw_read_histogram,          "RAW READS         ");
		int d;
		for (d = 0; d < g_num_devices; d++) {			
			histogram_dump(g_devices[d].p_raw_read_histogram,
					g_devices[d].histogram_tag);	
		}

		histogram_dump(g_p_read_histogram,              "READS             ");

		fprintf(stdout, "\n");
		fflush(stdout);
	}
	fprintf(stdout, "\nTEST COMPLETED \n");
	g_running = 0;
	int i;
//TODO aio_destroy?

	/* Freeing resources used by async */
	void* ret_value;
	for (i = 0; i < g_worker_threads; i++) 
	{
		pthread_join(workers[i], &ret_value);	
	}
	destroy_async_info_queue();

	int d;
	for (d = 0; d < g_num_devices; d++) {
		device* p_device = &g_devices[d];

		pthread_join(p_device->large_block_read_thread, &ret_value);
		pthread_join(p_device->large_block_write_thread, &ret_value);

		fd_close_all(p_device);
		cf_queue_destroy(p_device->p_fd_queue);
		free(p_device->p_large_block_read_buffer);
		free(p_device->p_raw_read_histogram);
	}

	free(g_p_large_block_read_histogram);
	free(g_p_large_block_write_histogram);
	free(g_p_raw_read_histogram);
	free(g_p_read_histogram);

	destroy_salters();

	return (0);
}
Ejemplo n.º 11
0
struct category *category_lookup_or_create(struct hash_table *categories, const char *name) {
	struct category *c;

	if(!name)
		name = "default";

	c = hash_table_lookup(categories, name);
	if(c) return c;

	c = calloc(1, sizeof(struct category));

	c->name       = xxstrdup(name);
	c->fast_abort = -1;

	c->total_tasks = 0;

	c->first_allocation    = NULL;
	c->max_allocation      = rmsummary_create(-1);
	c->autolabel_resource  = rmsummary_create(0);

	c->max_resources_seen      = rmsummary_create(-1);

	c->cores_histogram           = histogram_create(1);
	c->wall_time_histogram       = histogram_create(time_bucket_size);
	c->cpu_time_histogram        = histogram_create(time_bucket_size);
	c->memory_histogram          = histogram_create(memory_bucket_size);
	c->swap_memory_histogram     = histogram_create(memory_bucket_size);
	c->virtual_memory_histogram  = histogram_create(memory_bucket_size);
	c->bytes_read_histogram      = histogram_create(bytes_bucket_size);
	c->bytes_written_histogram   = histogram_create(bytes_bucket_size);
	c->bytes_received_histogram  = histogram_create(bytes_bucket_size);
	c->bytes_sent_histogram      = histogram_create(bytes_bucket_size);
	c->bandwidth_histogram       = histogram_create(bandwidth_bucket_size);
	c->total_files_histogram     = histogram_create(1);
	c->disk_histogram            = histogram_create(disk_bucket_size);
	c->total_processes_histogram = histogram_create(1);
	c->max_concurrent_processes_histogram = histogram_create(1);

	c->time_peak_independece = 0;

	c->steady_state = 0;
	c->completions_since_last_reset = 0;

	c->allocation_mode = CATEGORY_ALLOCATION_MODE_FIXED;

	hash_table_insert(categories, name, c);

	return c;
}