Пример #1
0
/* 
 * prepare data and execute the stock level transaction
 */
static int do_slev (int t_num)
{
    int c_num;
    int i,ret;
    clock_t clk1,clk2;
    double rt;
    struct timespec tbuf1;
    struct timespec tbuf2;
    int  w_id, d_id, level;

    if(num_node==0){
	w_id = RandomNumber(1, num_ware);
    }else{
	c_num = ((num_node * t_num)/num_conn); /* drop moduls */
	w_id = RandomNumber(1 + (num_ware * c_num)/num_node,
			    (num_ware * (c_num + 1))/num_node);
    }
    d_id = RandomNumber(1, DIST_PER_WARE); 
    level = RandomNumber(10, 20); 

      clk1 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf1 );
    for (i = 0; i < MAX_RETRY; i++) {
      ret = slev(t_num, w_id, d_id, level);
      clk2 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf2 );

      if(ret){

	rt = (double)(tbuf2.tv_sec * 1000.0 + tbuf2.tv_nsec/1000000.0-tbuf1.tv_sec * 1000.0 - tbuf1.tv_nsec/1000000.0);
	if(rt > max_rt[4])
	  max_rt[4]=rt;
	hist_inc(4, rt );
	if(counting_on){
	  if( rt < RTIME_SLEV ){
	    success[4]++;
	    success2[4][t_num]++;
	  }else{
	    late[4]++;
	    late2[4][t_num]++;
	  }
	}

	return (1); /* end */
      }else{

	if(counting_on){
	  retry[4]++;
	  retry2[4][t_num]++;
	}

      }
    }

    if(counting_on){
      retry[4]--;
      retry2[4][t_num]--;
      failure[4]++;
      failure2[4][t_num]++;
    }

    return (0);

}
Пример #2
0
/*
 * execute delivery transaction
 */
static int do_delivery (int t_num)
{
    int c_num;
    int i,ret;
    clock_t clk1,clk2;
    double rt;
    struct timespec tbuf1;
    struct timespec tbuf2;
    int  w_id, o_carrier_id;

    if(num_node==0){
	w_id = RandomNumber(1, num_ware);
    }else{
	c_num = ((num_node * t_num)/num_conn); /* drop moduls */
	w_id = RandomNumber(1 + (num_ware * c_num)/num_node,
			    (num_ware * (c_num + 1))/num_node);
    }
    o_carrier_id = RandomNumber(1, 10);

      clk1 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf1 );
    for (i = 0; i < MAX_RETRY; i++) {
      ret = delivery(t_num, w_id, o_carrier_id);
      clk2 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf2 );

      if(ret){

	rt = (double)(tbuf2.tv_sec * 1000.0 + tbuf2.tv_nsec/1000000.0-tbuf1.tv_sec * 1000.0 - tbuf1.tv_nsec/1000000.0);
	if(rt > max_rt[3])
	  max_rt[3]=rt;
	hist_inc(3, rt );
	if(counting_on){
	  if( rt < RTIME_DELIVERY ){
	    success[3]++;
	    success2[3][t_num]++;
	  }else{
	    late[3]++;
	    late2[3][t_num]++;
	  }
	}

	return (1); /* end */
      }else{

	if(counting_on){
	  retry[3]++;
	  retry2[3][t_num]++;
	}

      }
    }

    if(counting_on){
      retry[3]--;
      retry2[3][t_num]--;
      failure[3]++;
      failure2[3][t_num]++;
    }

    return (0);

}
Пример #3
0
/*
 * prepare data and execute the new order transaction for one order
 * officially, this is supposed to be simulated terminal I/O
 */
static int do_neword (int t_num)
{
    int c_num;
    int i,ret;
    clock_t clk1,clk2;
    double rt;
    struct timespec tbuf1;
    struct timespec tbuf2;
    int  w_id, d_id, c_id, ol_cnt;
    int  all_local = 1;
    int  notfound = MAXITEMS+1;  /* valid item ids are numbered consecutively
				    [1..MAXITEMS] */
    int rbk;
    int  itemid[MAX_NUM_ITEMS];
    int  supware[MAX_NUM_ITEMS];
    int  qty[MAX_NUM_ITEMS];

    if(num_node==0){
	w_id = RandomNumber(1, num_ware);
    }else{
	c_num = ((num_node * t_num)/num_conn); /* drop moduls */
	w_id = RandomNumber(1 + (num_ware * c_num)/num_node,
			    (num_ware * (c_num + 1))/num_node);
    }
    d_id = RandomNumber(1, DIST_PER_WARE);
    c_id = NURand(1023, 1, CUST_PER_DIST);

    ol_cnt = RandomNumber(5, 15);
    rbk = RandomNumber(1, 100);

    for (i = 0; i < ol_cnt; i++) {
	itemid[i] = NURand(8191, 1, MAXITEMS);
	if ((i == ol_cnt - 1) && (rbk == 1)) {
	    itemid[i] = notfound;
	}
	if (RandomNumber(1, 100) != 1) {
	    supware[i] = w_id;
	}
	else {
	    supware[i] = other_ware(w_id);
	    all_local = 0;
	}
	qty[i] = RandomNumber(1, 10);
    }

    clk1 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf1 );
    for (i = 0; i < MAX_RETRY; i++) {
      ret = neword(t_num, w_id, d_id, c_id, ol_cnt, all_local, itemid, supware, qty);
      clk2 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf2 );

      if(ret){

	rt = (double)(tbuf2.tv_sec * 1000.0 + tbuf2.tv_nsec/1000000.0-tbuf1.tv_sec * 1000.0 - tbuf1.tv_nsec/1000000.0);
        //printf("NOT : %.3f\n", rt);
        if (freport_file != NULL) {
          fprintf(freport_file,"%d %.3f\n", time_count, rt);
        }

	if(rt > max_rt[0])
	  max_rt[0]=rt;
	hist_inc(0, rt);
	if(counting_on){
	  if( rt < RTIME_NEWORD ){
	    success[0]++;
	    success2[0][t_num]++;
	  }else{
	    late[0]++;
	    late2[0][t_num]++;
	  }
	}

	return (1); /* end */
      }else{

	if(counting_on){
	  retry[0]++;
	  retry2[0][t_num]++;
	}

      }
    }

    if(counting_on){
      retry[0]--;
      retry2[0][t_num]--;
      failure[0]++;
      failure2[0][t_num]++;
    }

    return (0);
}
Пример #4
0
/*
 * prepare data and execute order status transaction
 */
static int do_ordstat (int t_num)
{
    int c_num;
    int byname,i,ret;
    clock_t clk1,clk2;
    double rt;
    struct timespec tbuf1;
    struct timespec tbuf2;
    int  w_id, d_id, c_id;
    char c_last[16];

    if(num_node==0){
	w_id = RandomNumber(1, num_ware);
    }else{
	c_num = ((num_node * t_num)/num_conn); /* drop moduls */
	w_id = RandomNumber(1 + (num_ware * c_num)/num_node,
			    (num_ware * (c_num + 1))/num_node);
    }
    d_id = RandomNumber(1, DIST_PER_WARE);
    c_id = NURand(1023, 1, CUST_PER_DIST); 
    Lastname(NURand(255,0,999), c_last); 
    if (RandomNumber(1, 100) <= 60) {
        byname = 1; /* select by last name */
    }else{
        byname = 0; /* select by customer id */
    }

      clk1 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf1 );
    for (i = 0; i < MAX_RETRY; i++) {
      ret = ordstat(t_num, w_id, d_id, byname, c_id, c_last);
      clk2 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf2 );

      if(ret){

	rt = (double)(tbuf2.tv_sec * 1000.0 + tbuf2.tv_nsec/1000000.0-tbuf1.tv_sec * 1000.0 - tbuf1.tv_nsec/1000000.0);
	if(rt > max_rt[2])
	  max_rt[2]=rt;
	hist_inc(2, rt);
	if(counting_on){
	  if( rt < RTIME_ORDSTAT ){
	    success[2]++;
	    success2[2][t_num]++;
	  }else{
	    late[2]++;
	    late2[2][t_num]++;
	  }
	}

	return (1); /* end */
      }else{

	if(counting_on){
	  retry[2]++;
	  retry2[2][t_num]++;
	}

      }
    }

    if(counting_on){
      retry[2]--;
      retry2[2][t_num]--;
      failure[2]++;
      failure2[2][t_num]++;
    }

    return (0);

}
Пример #5
0
static void *
rr_thread(void *arg)
{
  struct rr *r = arg;

#ifdef UNUSED_TEST_CODE
  if (r->server) {
    cpu_set_t cpu;
    CPU_ZERO(&cpu);
    CPU_SET(2, &cpu);
    if (0 != pthread_setaffinity_np(pthread_self(), sizeof(cpu), &cpu)) {
      ERROR_DIE("pthread_setaffinity failed");
    }
  }
#endif
#if CHECK_RTO_RETRANS
  checker_add_so(r->so);
#endif
  if (r->server) {
    while (1) {
      int msg_len;
      char *buf;
      int s = read(r->so, r->buf, sizeof(r->buf));
      if (s < 0) {
        log_msg("%d: read returns an error. %s(%d). stopping\n", r->id,
          strerror(errno), errno);
        goto exit;
      }
      if (s == 0) {
        log_msg("%d: read returns eof. stopping\n", r->id);
        goto exit;
      }
      if (s < sizeof(msg_len)) {
        log_msg("%d: read only %d bytes. stopping\n", r->id, s);
        goto exit;
      }
      buf = r->buf;
      msg_len = *((int*)buf);
      if (msg_len > sizeof(r->buf) || msg_len <= 0) {
        log_msg("%d: invalid msg_len %d. stopping\n", r->id, msg_len);
        goto exit;
      }
      if (s > msg_len) {
        log_msg("%d: client sent too much. msg_len=%d s=%d. stopping\n",
          r->id, msg_len, s);
        goto exit;
      }
      if (s < msg_len) {
        int rem = msg_len - s;
        while (rem > 0) {
          s = read(r->so, r->buf+msg_len-rem, rem);
          if (s > 0)
            rem -= s;
          else if (s < 0) {
            log_msg("%d: read returns an error. %s(%d). stopping\n", r->id,
              strerror(errno), errno);
            goto exit;
          }
          else if (s == 0) {
            log_msg("%d: read returns eof. stopping\n", r->id);
            goto exit;
          }
        }
      }      
      s = write(r->so, r->buf, msg_len);
      if (s != msg_len) {
        log_msg("%d: write failed. s=%d msg_len=%d error=%s(%d). stopping\n",
          r->id, s, msg_len, strerror(errno), errno);
        goto exit;
      }
    }
  }
  else {
    memset(r->buf, 0, sizeof(r->buf));
    while (1) {
      int s, rem;
      uint64_t msec;
      char *buf;

      // Sleep a little and then send a request and receive a response
      
      if (r->sleep > 0)
        usleep(r->sleep);

      msec = getmsec();
      buf = r->buf;
      *((int*)buf) = r->msg_len; // msg length in the first 4 bytes
      s = write(r->so, r->buf, r->msg_len);
      if (s != r->msg_len) {
        log_msg("%d: write failed. s=%d msg_len=%d error=%s(%d). stopping\n",
          r->id, s, r->msg_len, strerror(errno), errno);
        goto exit;
      }

      rem = r->msg_len;
      while (rem > 0) {
        s = read(r->so, r->buf+r->msg_len-rem, rem);
        if (s > 0)
          rem -= s;
        else if (s < 0) {
          log_msg("%d: read returns an error. %s(%d). stopping\n", r->id,
            strerror(errno), errno);
          goto exit;
        }
        else if (s == 0) {
          log_msg("%d: read returns eof. stopping\n", r->id);
          goto exit;
        }
      }
      r->stat_count++;
      msec = getmsec() - msec;
      hist_inc(&r->hist, (uint32_t)msec);
    }
  }
  
exit:
  
#if CHECK_RTO_RETRANS
  checker_remove_so(r->so);
#endif
  // For server, free the conn structure.  The main loop does not.
  if (r->server) {
    free(r);
  }
  return NULL;
}