timetest () : ok (1), no (++ttno) { ctr++; t[0] = t[1] = NULL; timecb_t *tt; tt = timecb (time (NULL) + rnd.getword () % 8, wrap (this, &timetest::timeout, 0)); if (!tt) return; t[0] = tt; tt = timecb (time (NULL) + rnd.getword () % 8, wrap (this, &timetest::timeout, 1)); if (!tt) return; t[1] = tt; }
void fileq::fhclean (bool istmo) { if (istmo) tmo = NULL; if (cleanlock) return; cleanlock = true; fhtimer *fht = NULL; if (minopen < 0 && (fht = timeq.first ()) && fht->expire < sfs_get_timenow()) do { fhtimer *nfht = timeq.next (fht); nfs_fh3 *fhp = New nfs_fh3 (fht->fh); closesim *serv = fht->serv; serv->fhfree (fht); vNew nfscall_cb<NFSPROC_CLOSE> (NULL, fhp, wrap (fhcleancb, fhp), serv); fht = nfht; } while (minopen < 0 && fht->expire < sfs_get_timenow()); cleanlock = false; if (!tmo && minopen < 0 && fht) tmo = timecb (min<time_t> (sfs_get_timenow() + 10, fht->expire), wrap (this, &fileq::fhclean, true)); }
void afs_shutdown_cb (int stat = 0) { if (!stat) exit (0); warn ("unmountall: %s\n", strerror (stat)); timecb (time (NULL) + 5, wrap (afs_shutdown, false)); }
void aios::timeoutbump () { if (timeoutval && !eof) { timeoutnext = time (NULL) + timeoutval; if (!timeoutcb && (rcb || outb.tosuio ()->resid ())) timeoutcb = timecb (timeoutnext, wrap (this, &aios::timeoutcatch)); } }
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); }
void aios::timeoutcatch () { time_t now = time (NULL); if (now < timeoutnext) { timeoutcb = timecb (timeoutnext, wrap (this, &aios::timeoutcatch)); return; } timeoutcb = NULL; if (timeoutval && (rcb || outb.tosuio ()->resid ())) { if (debugname) warnx << debugname << " === Timeout\n"; fail (ETIMEDOUT); } }
void rexsession::silence_check () { silence_check_cb = NULL; if (!proxy->calls_outstanding ()) return; time_t tmo_time = max<time_t> (silence_tmo_min, last_heard + SILENCE_TMO); if (timenow >= tmo_time) { silence_tmo_disable (); probe_call = ping (wrap (this, &rexsession::probed), PROBE_TMO); } else silence_check_cb = timecb (tmo_time, wrap (this, &rexsession::silence_check)); }
static void random_timer () { random_stir (); timecb (time (NULL) + 1800 + rnd.getword () % 1800, wrap (random_timer)); }
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 (); }