Exemplo n.º 1
0
void
ssrv_t::req_made ()
{
  reqtimes.push_back (sfs_get_tsnow());
  while (reqtimes.size () && 
	 tsdiff (reqtimes[0], sfs_get_tsnow(), ok_amt_lasi))
    reqtimes.pop_front ();
  load_avg = reqtimes.size ();
}
Exemplo n.º 2
0
void
timecb_check ()
{
  struct timespec my_ts;

  timecb_t *tp, *ntp;

  if (timecbs.first ()) {
    sfs_set_global_timestamp ();
    my_ts = sfs_get_tsnow ();

    for (tp = timecbs.first (); tp && tp->ts <= my_ts;
	 tp = timecbs_altered ? timecbs.first () : ntp) {
      ntp = timecbs.next (tp);
      timecbs.remove (tp);
      timecbs_altered = false;
#ifdef WRAP_DEBUG
      if (callback_trace & CBTR_TIME)
	warn ("CALLBACK_TRACE: %stimecb %s <- %s\n", timestring (),
	      tp->cb->dest, tp->cb->line);
#endif /* WRAP_DEBUG */
      STOP_ACHECK_TIMER ();
      sfs_leave_sel_loop ();
      (*tp->cb) ();
      START_ACHECK_TIMER ();
      delete tp;
    }
  }

  selwait.tv_usec = 0;
  selwait.tv_sec = 0;
  if (!sfs_core::g_busywait && !sigdocheck) {
    if (!(tp = timecbs.first ()))
      selwait.tv_sec = 86400;
    else {
      if (tp->ts.tv_sec == 0) {
	selwait.tv_sec = 0;
      } else {
	sfs_set_global_timestamp ();
	my_ts = sfs_get_tsnow ();
	if (tp->ts < my_ts)
	  selwait.tv_sec = 0;
	else if (tp->ts.tv_nsec >= my_ts.tv_nsec) {
	  selwait.tv_sec = tp->ts.tv_sec - my_ts.tv_sec;
	  selwait.tv_usec = (tp->ts.tv_nsec - my_ts.tv_nsec) / 1000;
	}
	else {
	  selwait.tv_sec = tp->ts.tv_sec - my_ts.tv_sec - 1;
	  selwait.tv_usec = (1000000000 + tp->ts.tv_nsec - 
			     my_ts.tv_nsec) / 1000;
	}
      }
    }
  }
}
Exemplo n.º 3
0
void
mtd_stats_t::report ()
{
  if (ok_amt_stat_freq == 0 ||
      !tsdiff (start_sample, sfs_get_tsnow(), ok_amt_stat_freq))
    return;
  epoch_t e = new_epoch ();
  warn ("STATS: i=%d;o=%d;r=%d;q=%d;a=%d;t=%d;l=%d\n",
	e.in, e.out, e.rejects, e.queued, e.async_serv, e.to, e.len_msec);
}
Exemplo n.º 4
0
// returns a time in microseconds
int
stop_timer (const timespec &tm)
{
  struct timespec tsnow = sfs_get_tsnow ();

  int ret = (tsnow.tv_nsec - tm.tv_nsec) / THOUSAND;
  int tmp = (tsnow.tv_sec - tm.tv_sec) * MILLION;
  ret += tmp;
  return ret;
}
Exemplo n.º 5
0
void
tpt_do_sample (bool last)
{
  int diff = stop_timer (tpt_last_sample);
  int num = n_successes - last_n_successes;
  last_n_successes = n_successes;

  tpt_samples.push_back (tpt_pair_t (diff, num));
  tpt_last_sample = sfs_get_tsnow ();
  if (!last)
    sched_tpt_measurement ();
}
Exemplo n.º 6
0
Arquivo: asrv.C Projeto: vonwenm/pbft
void
svccb::init (asrv *s, const sockaddr *src)
{
    srv = mkref (s);
    srv->xi->svcadd ();
    if (!s->xi->xh->connected) {
        addrlen = s->xi->xh->socksize;
        addr = (sockaddr *) opnew (addrlen);
        memcpy (addr, src, addrlen);
    }

    // keep track of when this RPC started
    ts_start = sfs_get_tsnow();
}
Exemplo n.º 7
0
timecb_t *
delaycb (time_t sec, u_int32_t nsec, cbv cb)
{
  timespec ts;
  if (sec == 0 && nsec == 0) {
    ts.tv_sec = 0;
    ts.tv_nsec = 0;
  } else {
    sfs_get_tsnow (&ts, true);
    ts.tv_sec += sec;
    ts.tv_nsec += nsec;
    fixup_timespec (ts);
  }
  return timecb (ts, cb);
}
Exemplo n.º 8
0
static inline const char *
timestring ()
{

  if (!callback_time)
    return "";

  struct timespec ts;

  sfs_get_tsnow (&ts, true);

  static str buf;
  buf = strbuf ("%d.%06d ", int (ts.tv_sec), int (ts.tv_nsec/1000));
  return buf;
}
Exemplo n.º 9
0
static void
lose_patience_cb ()
{
  struct timespec tsnow = sfs_get_tsnow ();
  if (noisy)
    warnx ("lpcb: td=%d; nleft=%d\n", 
	   timediff (tsnow, lastexit), nleft);
  if (lose_patience_after &&  
      timediff (tsnow, lastexit) > lose_patience_after &&
      n_still_patient &&
      nreq < n_still_patient) {
    stats.exit_timeouts += nreq;
    global_do_exit (0);
  } else
    schedule_lose_patience_timer ();
}
Exemplo n.º 10
0
static void
main2 (int n)
{
  struct timespec tsnow = sfs_get_tsnow ();

  lastexit = tsnow;
  startt = tsnow;
  nleft = n - nconcur;
  
  tpt_last_sample = tsnow;
  sched_tpt_measurement ();

  for (int i = 0; i < nconcur; i++) {
    hclient_t *h = New hclient_t ();
    h->run ();
  }
}
Exemplo n.º 11
0
void
hclient_t::run ()
{
  struct timespec tsnow = sfs_get_tsnow ();
  if (noisy) warn << "run: " << id << "\n";
  if (nrunning >= nconcur) {
    if (noisy) warn << "queuing: " << id << "\n";
    q.push_back (this);
    return;
  }
  nrunning++;
  if (noisy) warn << "running: " << id << " (nrunning: " << nrunning << ")\n";
  if (noisy) warn << "connecting to: " << host << "\n";
  cli_start = tsnow;
  tcb = delaycb (timeout, 0, wrap (this, &hclient_t::timed_out, destroyed));
  tcpconnect (host, port, wrap (this, &hclient_t::connected, destroyed));
}
Exemplo n.º 12
0
void
hclient_t::hclient_do_exit (int c)
{
  if (c == 0)
    n_successes ++;

  lastexit = sfs_get_tsnow();

  if (noisy) warn << "at cexit2: " << id << "\n";
  --nrunning;
  launch_others ();
  if (noisy) warn << "done: " << id << " (nreq: " << nreq << ")\n";
  if (success)
    latencies.push_back (stop_timer (cli_start));
  if (!--nreq && sdflag)
    global_do_exit (c);
  delete this;
  return;
}
Exemplo n.º 13
0
epoch_t
mtd_stats_t::new_epoch ()
{
  epoch_t e = sample;
  
  struct timespec tsnow;
  tsnow = sfs_get_tsnow ();

  e.len_msec = (tsnow.tv_sec - start_sample.tv_sec) * 1000
    + (tsnow.tv_nsec - start_sample.tv_nsec) / 1000000;

  start_sample = tsnow;
  sample.in = 0;
  sample.out = 0;
  sample.rejects = 0;
  sample.queued = 0;
  sample.async_serv = 0;
  sample.to = 0;

  return e;
}
Exemplo n.º 14
0
int 
main (int argc, char *argv[])
{
  timeout = 120;
  noisy = false;
  zippity = false;
  srandom(time(0));
  setprogname (argv[0]);
  int ch;
  int n = 1000;
  nconcur = 500; 
  bool delay = false;
  timespec startat;
  startat.tv_nsec = 0;
  startat.tv_sec = 0;
  exited = false;
  hclient_id = 1;
  use_latencies = false;
  num_services = 1;
  tpt_sample_period_secs = 1;
  tpt_sample_period_nsecs = 0;
  int lat_stddv = 25;
  int lat_mean = 75;
  lose_patience_after = 0;
  id_cycler_t *svc_cycler = NULL;
  id_cycler_t *req_cycler = NULL; 
  mode = NONE;
  bool no_pub = false;

  int tmp = 0;

  static rxx lose_patience_rxx ("(\\d+),(\\d+)");

  while ((ch = getopt (argc, argv, "c:dlm:n:pr:t:v:zM:P:S:R:T:V:")) != -1) {
    switch (ch) {

    case 'c':
      if (!convertint (optarg, &nconcur))
	usage ();
      if (noisy) warn << "Concurrency factor: " << nconcur << "\n";
      break;

    case 'd':
      noisy = true;
      break;

    case 'l':
      use_latencies = true;
      if (noisy) warn << "Using Latencies\n";
      break;

    case 'm':
      {
	switch (optarg[0]) {
	case 's':
	case 'S':
	  mode = SEDA;
	  if (noisy) warn << "In SEDA mode\n";
	  break;
	case 'o':
	case 'O':
	  mode = OKWS;
	  if (noisy) warn << "In OKWS mode\n";
	  break;
	case 'P':
	case 'p':
	  mode = PHP;
	  if (noisy) warn << "In PHP mode\n";
	  break;
	case 'f':
	case 'F':
	  mode = FLASH;
	  if (noisy) warn << "In FLASH mode\n";
	  break;
	default:
	  usage ();
	  break;
	}
	break;
      }
	
    case 'n':
      if (!convertint (optarg, &n))
	usage ();
      if (noisy) warn << "Number of requests: " << n << "\n";
      break;

    case 'p':
      no_pub = true;
      break;

    case 'r':
      if (!convertint (optarg, &tmp))
	usage ();
      req_cycler = New id_cycler_t (true, tmp, 1);
      if (noisy) 
	warn << "Ranging ids from 1 to " << tmp << " (randomly)\n";
      break;

    case 't': 
      {
	if (!convertint (optarg, &startat.tv_sec))
	  usage ();
	delay = true;
	if (noisy) warn << "Delaying start until time=" 
			<< startat.tv_sec << "\n";
	time_t mytm = time (NULL);
	tmp =  startat.tv_sec - mytm;
	if (tmp < 0) {
	  warn << "time stamp alreached (it's " << mytm << " right now)!\n";
	  usage ();
	}
	if (noisy) {
	  warn << "Starting in T minus " << tmp << " seconds\n";
	}
	break;
      }

    case 'v':
      if (!convertint (optarg, &tmp))
	usage ();
      svc_cycler = New id_cycler_t (true, tmp, 1);
      if (noisy) 
	warn << "Randing services from 1 to " << tmp << " (randomly)\n";
      break;

    case 'z':
      zippity = true;
      break;

    case 'M':
      if (!convertint (optarg, &lat_mean))
        usage ();
      if (noisy) warn << "Mean of latencies: " << lat_mean << "\n";
      break;

    case 'P':
      if (!convertint (optarg, &tmp))
	usage ();
      tpt_sample_period_secs = tmp / THOUSAND;
      tpt_sample_period_nsecs = (tmp % THOUSAND) * MILLION;
      if (noisy)
	warn ("Sample throughput period=%d.%03d secs\n", 
	      tpt_sample_period_secs,
	      tpt_sample_period_nsecs / MILLION);
      break;

    case 'R':
      req_cycler = New id_cycler_t ();
      if (!req_cycler->init (optarg))
	usage ();
      break;

    
    case 'S':
      if (!convertint (optarg, &lat_stddv))
        usage ();
      if (noisy) warn << "Standard dev. of latency: " << lat_stddv << "\n";
      break;

    case 'T':
      if (!lose_patience_rxx.match (optarg) ||
	  !convertint (lose_patience_rxx[1], &n_still_patient) ||
	  !convertint (lose_patience_rxx[2], &lose_patience_after))
	usage ();
      break;

    case 'V':
      svc_cycler = New id_cycler_t ();
      if (!svc_cycler->init (optarg))
	usage ();
      break;

    default:
      usage ();
    }
  }
  argc -= optind;
  argv += optind;

  if (argc == 0)
    usage ();

  str dest = argv[0];
  argc --;
  argv ++;

  // make the appropriate cyclers...
  if (argc > 0) {

    // in this case, the user supplied extra arguments after the hostname
    // and port; therefore, they're going to be making their own URL
    // by alternating static parts and cyclers.
    if (req_cycler) {
      warn << "Don't provide -r if you're going to make your own URI\n";
      usage ();
    }
    if (svc_cycler) {
      warn << "Don't provide -v if you're going to make your own URI\n";
      usage ();
    }

    for (int i = 0; i < argc; i++) {
      if (i % 2 == 0) {
	uri_parts.push_back (argv[i]);
      } else {
	id_cycler_t *tmp = New id_cycler_t ();
	if (!tmp->init (argv[i])) {
	  warn << "Cannot parse ID cycler: " << argv[i] << "\n";
	  usage ();
	}
	id_cyclers.push_back (tmp);
      }
    }

  } else if (mode != NONE) {
    // no manual URL building required; just specify some defaults
    // though if none were specified
    if (!req_cycler) 
      // roughly a million, but this way all reqs will have the same
      // number of digits
      req_cycler = New id_cycler_t (true, 900000, 100000);
    if (!svc_cycler)
      // don't cycle --- just always return 1
      svc_cycler = New id_cycler_t (false, 1, 1);

    id_cyclers.push_back (svc_cycler);
    id_cyclers.push_back (req_cycler);

    switch (mode) {
    case SEDA:
      uri_parts.push_back ("mt");
      uri_parts.push_back ("?id=");
      break;
    case OKWS: 
      {
	uri_parts.push_back ("mt"); 
	strbuf b ("?");
	if (no_pub) 
	  b << "nopub=1&";
	b << "id=";
	uri_parts.push_back (b);
	break;
      }
    case PHP:
      uri_parts.push_back ("mt");
      uri_parts.push_back (".php?id=");
      break;
    case FLASH:
      uri_parts.push_back ("cgi-bin/mt");
      uri_parts.push_back ("?");
      break;
    default:
      break;
    }
  }

  // normdist (mean, std-dev, "precision")
  if (use_latencies)
    dist = New normdist_t (200,25);

  if (!hostport.match (dest)) 
    usage ();
  host = hostport[1];
  str port_s = hostport[3];
  if (port_s) {
    if (!convertint (port_s, &port)) usage ();
  } else {
    port = 80;
  }

  struct timespec tsnow = sfs_get_tsnow ();

  // unless we don this, shit won't be initialized, and i'll
  // starting ripping my hair out as to why all of the timestamps
  // are negative
  clock_gettime (CLOCK_REALTIME, &tsnow);

  nrunning = 0;
  sdflag = true;
  nreq = n;
  nreq_fixed = n;
  tpt_last_nreq = nreq;

  if (delay) {
    timecb (startat, wrap (main2, n));
  } else {
    main2 (n);
  }
  amain ();
}