use of com.linkedin.pinot.common.metrics.MetricsHelper.TimerContext in project pinot by linkedin.
the class NettyTCPClientConnection method connect.
/**
* Open a connection
*/
@Override
public boolean connect() {
try {
checkTransition(State.CONNECTED);
//Connect synchronously. At the end of this line, _channel should have been set
TimerContext t = MetricsHelper.startTimer();
ChannelFuture f = _bootstrap.connect(_server.getHostname(), _server.getPort()).sync();
/**
* Waiting for future alone does not guarantee that _channel is set. _channel is set
* only when the channelActive() async callback runs. So we should also wait for it.
*/
f.get();
_channelSet.await();
t.stop();
_connState = State.CONNECTED;
_clientMetric.addConnectStats(t.getLatencyMs());
return true;
} catch (Exception ie) {
if (ie instanceof ConnectException && ie.getMessage() != null && ie.getMessage().startsWith("Connection refused")) {
// Most common case when a server is down. Don't print the entire stack and fill the logs.
LOGGER.error("Could not connect to server {}:{} connId:{}", _server, ie.getMessage(), getConnId());
} else {
LOGGER.error("Got exception when connecting to server {} connId {}", _server, ie, getConnId());
}
}
return false;
}
use of com.linkedin.pinot.common.metrics.MetricsHelper.TimerContext in project pinot by linkedin.
the class ScatterGatherImpl method sendRequest.
/**
*
* Helper Function to send scatter-request. This method should be called after the servers are selected
*
* @param ctxt Scatter-Gather Request context with selected servers for each request.
* @param scatterGatherStats scatter-gather statistics.
* @param isOfflineTable whether the scatter-gather target is an OFFLINE table.
* @param brokerMetrics broker metrics to track execution statistics.
* @return a composite future representing the gather process.
* @throws InterruptedException
*/
protected CompositeFuture<ServerInstance, ByteBuf> sendRequest(ScatterGatherRequestContext ctxt, ScatterGatherStats scatterGatherStats, Boolean isOfflineTable, BrokerMetrics brokerMetrics) throws InterruptedException {
TimerContext t = MetricsHelper.startTimer();
// Servers are expected to be selected at this stage
Map<ServerInstance, SegmentIdSet> mp = ctxt.getSelectedServers();
CountDownLatch requestDispatchLatch = new CountDownLatch(mp.size());
// async checkout of connections and then dispatch of request
List<SingleRequestHandler> handlers = new ArrayList<SingleRequestHandler>(mp.size());
for (Entry<ServerInstance, SegmentIdSet> e : mp.entrySet()) {
ServerInstance server = e.getKey();
String serverName = server.toString();
if (isOfflineTable != null) {
if (isOfflineTable) {
serverName += ScatterGatherStats.OFFLINE_TABLE_SUFFIX;
} else {
serverName += ScatterGatherStats.REALTIME_TABLE_SUFFIX;
}
}
scatterGatherStats.initServer(serverName);
SingleRequestHandler handler = new SingleRequestHandler(_connPool, server, ctxt.getRequest(), e.getValue(), ctxt.getTimeRemaining(), requestDispatchLatch, brokerMetrics);
// Submit to thread-pool for checking-out and sending request
_executorService.submit(handler);
handlers.add(handler);
}
// Create the composite future for returning
CompositeFuture<ServerInstance, ByteBuf> response = new CompositeFuture<ServerInstance, ByteBuf>("scatterRequest", GatherModeOnError.SHORTCIRCUIT_AND);
// Wait for requests to be sent
long timeRemaining = ctxt.getTimeRemaining();
boolean sentSuccessfully = requestDispatchLatch.await(timeRemaining, TimeUnit.MILLISECONDS);
if (sentSuccessfully) {
List<KeyedFuture<ServerInstance, ByteBuf>> responseFutures = new ArrayList<KeyedFuture<ServerInstance, ByteBuf>>();
for (SingleRequestHandler h : handlers) {
responseFutures.add(h.getResponseFuture());
String serverName = h.getServer().toString();
if (isOfflineTable != null) {
if (isOfflineTable) {
serverName += ScatterGatherStats.OFFLINE_TABLE_SUFFIX;
} else {
serverName += ScatterGatherStats.REALTIME_TABLE_SUFFIX;
}
}
scatterGatherStats.setSendStartTimeMillis(serverName, h.getConnStartTimeMillis());
scatterGatherStats.setConnStartTimeMillis(serverName, h.getStartDelayMillis());
scatterGatherStats.setSendCompletionTimeMillis(serverName, h.getSendCompletionTimeMillis());
}
response.start(responseFutures);
} else {
LOGGER.error("Request (" + ctxt.getRequest().getRequestId() + ") not sent completely within time (" + timeRemaining + " ms) !! Cancelling !!. NumSentFailed:" + requestDispatchLatch.getCount());
response.start(null);
// and so we cancel all of them here
for (SingleRequestHandler h : handlers) {
LOGGER.info("Request to {} was sent successfully:{}, cancelling.", h.getServer(), h.isSent());
h.cancel();
}
}
t.stop();
_latency.update(t.getLatencyMs());
return response;
}
use of com.linkedin.pinot.common.metrics.MetricsHelper.TimerContext in project pinot by linkedin.
the class ScatterGatherPerfClient method run.
@Override
public void run() {
System.out.println("Client starting !!");
try {
List<ServerInstance> s1 = new ArrayList<ServerInstance>();
ServerInstance s = new ServerInstance("localhost", 9099);
s1.add(s);
SimpleScatterGatherRequest req = null;
TimerContext tc = null;
for (int i = 0; i < _numRequests; i++) {
LOGGER.debug("Sending request number {}", i);
do {
req = getRequest();
} while ((null == req));
if (i == _numRequestsToSkipForMeasurement) {
tc = MetricsHelper.startTimer();
_beginFirstRequestTime = System.currentTimeMillis();
}
if (i >= _numRequestsToSkipForMeasurement) {
_numRequestsMeasured++;
}
final ScatterGatherStats scatterGatherStats = new ScatterGatherStats();
if (!_asyncRequestSubmit) {
sendRequestAndGetResponse(req, scatterGatherStats);
_endLastResponseTime = System.currentTimeMillis();
} else {
CompositeFuture<ServerInstance, ByteBuf> future = asyncSendRequestAndGetResponse(req, scatterGatherStats);
_queue.offer(new QueueEntry(false, i >= _numRequestsToSkipForMeasurement, System.currentTimeMillis(), future));
}
//System.out.println("Response is :" + r);
//System.out.println("\n\n");
req = null;
}
if (_asyncRequestSubmit) {
int numTerminalEntries = _readerThreads.size();
for (int i = 0; i < numTerminalEntries; i++) {
_queue.offer(new QueueEntry(true, false, System.currentTimeMillis(), null));
}
for (AsyncReader r : _readerThreads) {
r.join();
}
}
if (null != tc) {
tc.stop();
_timerContext = tc;
System.out.println("Num Requests :" + _numRequestsMeasured);
System.out.println("Total time :" + tc.getLatencyMs());
System.out.println("Throughput (Requests/Second) :" + ((_numRequestsMeasured * 1.0 * 1000) / tc.getLatencyMs()));
System.out.println("Latency :" + new LatencyMetric<Histogram>(_latencyHistogram));
System.out.println("Scatter-Gather Latency :" + new LatencyMetric<Histogram>(_scatterGather.getLatency()));
}
} catch (Exception ex) {
System.err.println("Client stopped abnormally ");
ex.printStackTrace();
}
shutdown();
System.out.println("Client done !!");
}
Aggregations