TIMESTAMP network::sync(TIMESTAMP t0, TIMESTAMP t1) { OBJECT *obj = OBJECTHDR(this); // update latency? if(latency_last_update + latency_period <= t1){ update_latency(); } if ((latency_period <= 0.001) || (next_event != TS_NEVER) && (next_event < latency_next_update) ){ return next_event; } else { return latency_next_update; } }
int network::init(OBJECT *parent) { OBJECT *hdr = OBJECTHDR(this); // input validation checks if(latency_mode[0] != 0){ random_type = gl_randomtype(latency_mode); if(random_type == RT_INVALID){ GL_THROW("unrecognized random type \'%s\'", latency_mode.get_string()); } } else { random_type = RT_INVALID; // prevents update_latency from updating the value } if(latency_period < 0.0){ gl_warning("negative latency_period was reset to zero"); latency_period = 0.0; } if(bandwidth <= 0.0){ gl_error("non-positive bandwidth"); return 0; } switch(queue_resolution){ case QR_QUEUE: if(buffer_size <= 0.0){ gl_error("non-positive buffer_size when using buffered queue_resolution"); } break; case QR_REJECT: // requires no checks break; default: gl_error("unrecognized queue_resolution, defaulting to QR_REJECT"); queue_resolution = QR_REJECT; break; } if(timeout < 0.0){ gl_warning("negative timeout was reset to zero"); timeout = 0.0; } // operational variable defaults bandwidth_used = 0.0; update_latency(); latency_last_update = gl_globalclock; next_event = TS_NEVER; // success return 1; }
update_latency_fn_t instrumentation::add_latency( const std::string service, const std::string description, std::vector<double> percentiles) { CHECK(rates_id_.load() < k_max_latencies) << "max number of percentiles reached"; int id = latencies_id_.fetch_add(1); latencies_[id].service = service; latencies_[id].description = description; latencies_[id].percentiles = percentiles; return [=](const double v) { update_latency(id, v); }; }
void rpc_manager::doRPCcb (aclnt_cb realcb, ptr<location> l, u_int64_t sent, clnt_stat err) { if (err) { nrpcfailed++; l->set_alive (false); } else { nrpc++; // Only update latency on successful RPC. // This probably includes time needed for rexmits. u_int64_t now = getusec (); // prevent overflow, caused by time reversal if (now >= sent) { u_int64_t lat = now - sent; update_latency (NULL, l, lat); } else { warn << "*** Ignoring timewarp: sent " << sent << " > now " << now << "\n"; } } (realcb) (err); }