use of com.linkedin.pinot.common.response.ServerInstance in project pinot by linkedin.
the class NettySingleConnectionIntegrationTest method testValidatePool.
/*
* WARNING: This test has potential failures due to timing.
*/
@Test
public void testValidatePool() throws Exception {
NettyClientMetrics metric = new NettyClientMetrics(null, "abc");
Timer timer = new HashedWheelTimer();
MyServer server = new MyServer();
Thread.sleep(1000);
// used as a key to pool. Can be anything.
final String serverName = "SomeServer";
ServerInstance serverInstance = server.getServerInstance();
MetricsRegistry metricsRegistry = new MetricsRegistry();
EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
PooledNettyClientResourceManager resourceManager = new PooledNettyClientResourceManager(eventLoopGroup, new HashedWheelTimer(), metric);
ExecutorService executorService = Executors.newCachedThreadPool();
ScheduledExecutorService timeoutExecutor = new ScheduledThreadPoolExecutor(5);
AsyncPoolResourceManagerAdapter<ServerInstance, NettyClientConnection> rmAdapter = new AsyncPoolResourceManagerAdapter<ServerInstance, NettyClientConnection>(serverInstance, resourceManager, executorService, metricsRegistry);
AsyncPool pool = new AsyncPoolImpl<NettyClientConnection>(serverName, rmAdapter, /*maxSize=*/
5, /*idleTimeoutMs=*/
100000, timeoutExecutor, executorService, /*maxWaiters=*/
10, AsyncPoolImpl.Strategy.LRU, /*minSize=*/
2, metricsRegistry);
pool.start();
Callback<NoneType> callback;
callback = new Callback<NoneType>() {
@Override
public void onSuccess(NoneType arg0) {
}
@Override
public void onError(Throwable arg0) {
Assert.fail("Shutdown error");
}
};
boolean serverShutdown = false;
try {
PoolStats stats;
/* Validate with no connection in pool */
// Give the pool enough time to create connections (in this case, 2 connections minSize)
Thread.sleep(3000);
// System.out.println("Validating with no used objects in the pool");
pool.validate(false);
// System.out.println(stats);
stats = pool.getStats();
Assert.assertEquals(2, stats.getPoolSize());
Assert.assertEquals(0, stats.getTotalBadDestroyed());
/* checkout one connection, it should not destroy anything */
AsyncResponseFuture<ServerInstance, NettyClientConnection> future = new AsyncResponseFuture<ServerInstance, NettyClientConnection>(serverInstance, "Future for " + serverName);
Cancellable cancellable = pool.get(future);
future.setCancellable(cancellable);
NettyClientConnection conn = future.getOne();
// System.out.println(stats);
stats = pool.getStats();
// System.out.println("Validating with one used object in the pool");
pool.validate(false);
Assert.assertEquals(2, stats.getPoolSize());
Assert.assertEquals(0, stats.getTotalBadDestroyed());
Assert.assertEquals(1, stats.getCheckedOut());
// Now stop the server, so that the checked out connection is invalidated.
server.shutdown();
serverShutdown = true;
;
// Wait for the client channel to be closed.
Thread.sleep(2000);
pool.validate(false);
// Wait for the callback into AsyncPoolImpl after the destroy thread completes destroying the connection
Thread.sleep(5000);
// System.out.println("Validating with one used object in the pool, after server shutdown");
// System.out.println(stats);
stats = pool.getStats();
Assert.assertEquals(2, stats.getPoolSize());
Assert.assertEquals(1, stats.getTotalBadDestroyed());
Assert.assertEquals(1, stats.getCheckedOut());
} finally {
server.shutdown();
pool.shutdown(callback);
executorService.shutdown();
timeoutExecutor.shutdown();
}
}
use of com.linkedin.pinot.common.response.ServerInstance in project pinot by linkedin.
the class ScatterGatherPerfTester method run.
public void run() throws Exception {
List<ScatterGatherPerfServer> servers = null;
// Run Servers when mode is RUN_SERVER or RUN_BOTH
if (_mode != ExecutionMode.RUN_CLIENT) {
servers = runServer();
}
if (_mode != ExecutionMode.RUN_SERVER) {
int port = _startPortNum;
// Setup Routing config for clients
RoutingTableConfig config = new RoutingTableConfig();
Map<String, PerTableRoutingConfig> cfg = config.getPerTableRoutingCfg();
PerTableRoutingConfig c = new PerTableRoutingConfig(null);
Map<Integer, List<ServerInstance>> instanceMap = c.getNodeToInstancesMap();
port = _startPortNum;
int numUniqueServers = _remoteServerHosts.size();
for (int i = 0; i < _numServers; i++) {
List<ServerInstance> instances = new ArrayList<ServerInstance>();
String server = null;
if (_mode == ExecutionMode.RUN_BOTH)
server = "localhost";
else
server = _remoteServerHosts.get(i % numUniqueServers);
ServerInstance instance = new ServerInstance(server, port++);
instances.add(instance);
instanceMap.put(i, instances);
}
String server = null;
if (_mode == ExecutionMode.RUN_BOTH)
server = "localhost";
else
server = _remoteServerHosts.get(0);
c.getDefaultServers().add(new ServerInstance(server, port - 1));
cfg.put(_resourceName, c);
System.out.println("Routing Config is :" + cfg);
// Build Clients
List<Thread> clientThreads = new ArrayList<Thread>();
List<ScatterGatherPerfClient> clients = new ArrayList<ScatterGatherPerfClient>();
AggregatedHistogram<Histogram> latencyHistogram = new AggregatedHistogram<Histogram>();
for (int i = 0; i < _numClients; i++) {
ScatterGatherPerfClient c2 = new ScatterGatherPerfClient(config, _requestSize, _resourceName, _asyncRequestDispatch, _numRequests, _maxActiveConnectionsPerClientServerPair, _numResponseReaderThreads);
Thread t = new Thread(c2);
clients.add(c2);
latencyHistogram.add(c2.getLatencyHistogram());
clientThreads.add(t);
}
System.out.println("Starting the clients !!");
long startTimeMs = 0;
// Start Clients
for (Thread t2 : clientThreads) t2.start();
System.out.println("Waiting for clients to finish");
// Wait for clients to finish
for (Thread t2 : clientThreads) t2.join();
Thread.sleep(3000);
System.out.println("Client threads done !!");
int totalRequestsMeasured = 0;
long beginRequestTime = Long.MAX_VALUE;
long endResponseTime = Long.MIN_VALUE;
for (ScatterGatherPerfClient c3 : clients) {
int numRequestsMeasured = c3.getNumRequestsMeasured();
totalRequestsMeasured += numRequestsMeasured;
beginRequestTime = Math.min(beginRequestTime, c3.getBeginFirstRequestTime());
endResponseTime = Math.max(endResponseTime, c3.getEndLastResponseTime());
//System.out.println("2 Num Requests :" + numRequestsMeasured);
//System.out.println("2 time :" + timeTakenMs );
//System.out.println("2 Throughput (Requests/Second) :" + ((numRequestsMeasured* 1.0 * 1000)/timeTakenMs));
}
long totalTimeTakenMs = endResponseTime - beginRequestTime;
System.out.println("Overall Total Num Requests :" + totalRequestsMeasured);
System.out.println("Overall Total time :" + totalTimeTakenMs);
System.out.println("Overall Throughput (Requests/Second) :" + ((totalRequestsMeasured * 1.0 * 1000) / totalTimeTakenMs));
latencyHistogram.refresh();
System.out.println("Latency :" + new LatencyMetric<AggregatedHistogram<Histogram>>(latencyHistogram));
}
if (_mode == ExecutionMode.RUN_BOTH) {
// Shutdown Servers
for (ScatterGatherPerfServer s : servers) {
s.shutdown();
}
}
}
use of com.linkedin.pinot.common.response.ServerInstance in project pinot by linkedin.
the class ScatterGatherTest method testSelectServers.
@Test
public void testSelectServers() throws Exception {
ExecutorService poolExecutor = MoreExecutors.sameThreadExecutor();
ScatterGatherImpl scImpl = new ScatterGatherImpl(null, poolExecutor);
{
// 1 server with 2 partitions
SegmentIdSet pg = new SegmentIdSet();
pg.addSegment(new SegmentId("0"));
pg.addSegment(new SegmentId("1"));
ServerInstance serverInstance1 = new ServerInstance("localhost", 1011);
List<ServerInstance> instances = new ArrayList<ServerInstance>();
instances.add(serverInstance1);
Map<ServerInstance, SegmentIdSet> pgMap = new HashMap<ServerInstance, SegmentIdSet>();
Map<List<ServerInstance>, SegmentIdSet> invMap = new HashMap<List<ServerInstance>, SegmentIdSet>();
pgMap.put(serverInstance1, pg);
invMap.put(instances, pg);
String request = "request_0";
Map<SegmentIdSet, String> pgMapStr = new HashMap<SegmentIdSet, String>();
pgMapStr.put(pg, request);
ScatterGatherRequest req = new TestScatterGatherRequest(pgMap, pgMapStr);
ScatterGatherRequestContext ctxt = new ScatterGatherRequestContext(req);
ctxt.setInvertedMap(invMap);
scImpl.selectServices(ctxt);
Map<ServerInstance, SegmentIdSet> resultMap = ctxt.getSelectedServers();
Assert.assertEquals(resultMap.size(), 1, "Count");
Assert.assertEquals(resultMap.get(serverInstance1), pg, "Element check");
// System.out.println(ctxt);
}
{
// 2 server with 2 partitions each
SegmentIdSet pg = new SegmentIdSet();
pg.addSegment(new SegmentId("0"));
pg.addSegment(new SegmentId("1"));
SegmentIdSet pg2 = new SegmentIdSet();
pg2.addSegment(new SegmentId("2"));
pg2.addSegment(new SegmentId("3"));
ServerInstance serverInstance1 = new ServerInstance("localhost", 1011);
ServerInstance serverInstance2 = new ServerInstance("localhost", 1012);
List<ServerInstance> instances = new ArrayList<ServerInstance>();
instances.add(serverInstance1);
List<ServerInstance> instances2 = new ArrayList<ServerInstance>();
instances2.add(serverInstance2);
Map<ServerInstance, SegmentIdSet> pgMap = new HashMap<ServerInstance, SegmentIdSet>();
Map<List<ServerInstance>, SegmentIdSet> invMap = new HashMap<List<ServerInstance>, SegmentIdSet>();
pgMap.put(serverInstance1, pg);
pgMap.put(serverInstance2, pg2);
invMap.put(instances, pg);
invMap.put(instances2, pg2);
String request = "request_0";
Map<SegmentIdSet, String> pgMapStr = new HashMap<SegmentIdSet, String>();
pgMapStr.put(pg, request);
ScatterGatherRequest req = new TestScatterGatherRequest(pgMap, pgMapStr);
ScatterGatherRequestContext ctxt = new ScatterGatherRequestContext(req);
ctxt.setInvertedMap(invMap);
scImpl.selectServices(ctxt);
Map<ServerInstance, SegmentIdSet> resultMap = ctxt.getSelectedServers();
Assert.assertEquals(resultMap.size(), 2, "Count");
Assert.assertEquals(resultMap.get(serverInstance1), pg, "Element check");
Assert.assertEquals(resultMap.get(serverInstance2), pg2, "Element check");
// System.out.println(ctxt);
}
{
// 2 servers sharing 2 partitions (Round-Robin selection) Partition-Group Granularity
SegmentIdSet pg = new SegmentIdSet();
pg.addSegment(new SegmentId("0"));
pg.addSegment(new SegmentId("1"));
ServerInstance serverInstance1 = new ServerInstance("localhost", 1011);
ServerInstance serverInstance2 = new ServerInstance("localhost", 1012);
List<ServerInstance> instances = new ArrayList<ServerInstance>();
instances.add(serverInstance1);
instances.add(serverInstance2);
Map<ServerInstance, SegmentIdSet> pgMap = new HashMap<ServerInstance, SegmentIdSet>();
Map<List<ServerInstance>, SegmentIdSet> invMap = new HashMap<List<ServerInstance>, SegmentIdSet>();
pgMap.put(serverInstance1, pg);
pgMap.put(serverInstance2, pg);
invMap.put(instances, pg);
String request = "request_0";
Map<SegmentIdSet, String> pgMapStr = new HashMap<SegmentIdSet, String>();
pgMapStr.put(pg, request);
ScatterGatherRequest req = new TestScatterGatherRequest(pgMap, pgMapStr, new RoundRobinReplicaSelection(), ReplicaSelectionGranularity.SEGMENT_ID_SET, 0, 10000);
ScatterGatherRequestContext ctxt = new ScatterGatherRequestContext(req);
ctxt.setInvertedMap(invMap);
scImpl.selectServices(ctxt);
Map<ServerInstance, SegmentIdSet> resultMap = ctxt.getSelectedServers();
Assert.assertEquals(resultMap.size(), 1, "Count");
// first server is getting selected
Assert.assertEquals(resultMap.get(serverInstance1), pg, "Element check");
// System.out.println(ctxt);
// Run selection again. Now the second server should be selected
scImpl.selectServices(ctxt);
resultMap = ctxt.getSelectedServers();
Assert.assertEquals(resultMap.size(), 1, "Count");
// second server is getting selected
Assert.assertEquals(resultMap.get(serverInstance2), pg, "Element check");
// System.out.println(ctxt);
}
{
// 2 servers sharing 2 partitions (Round-Robin selection) Partition Granularity
SegmentIdSet pg = new SegmentIdSet();
pg.addSegment(new SegmentId("0"));
pg.addSegment(new SegmentId("1"));
ServerInstance serverInstance1 = new ServerInstance("localhost", 1011);
ServerInstance serverInstance2 = new ServerInstance("localhost", 1012);
List<ServerInstance> instances = new ArrayList<ServerInstance>();
instances.add(serverInstance1);
instances.add(serverInstance2);
Map<ServerInstance, SegmentIdSet> pgMap = new HashMap<ServerInstance, SegmentIdSet>();
Map<List<ServerInstance>, SegmentIdSet> invMap = new HashMap<List<ServerInstance>, SegmentIdSet>();
pgMap.put(serverInstance1, pg);
pgMap.put(serverInstance1, pg);
invMap.put(instances, pg);
String request = "request_0";
Map<SegmentIdSet, String> pgMapStr = new HashMap<SegmentIdSet, String>();
pgMapStr.put(pg, request);
ScatterGatherRequest req = new TestScatterGatherRequest(pgMap, pgMapStr, new RoundRobinReplicaSelection(), ReplicaSelectionGranularity.SEGMENT_ID, 0, 10000);
ScatterGatherRequestContext ctxt = new ScatterGatherRequestContext(req);
ctxt.setInvertedMap(invMap);
scImpl.selectServices(ctxt);
Map<ServerInstance, SegmentIdSet> resultMap = ctxt.getSelectedServers();
Assert.assertEquals(resultMap.size(), 2, "Count");
// first server is getting selected
Assert.assertFalse(resultMap.get(serverInstance1).equals(resultMap.get(serverInstance2)), "Element check");
// System.out.println(ctxt);
// Run selection again. Now the second server should be selected
scImpl.selectServices(ctxt);
resultMap = ctxt.getSelectedServers();
Assert.assertEquals(resultMap.size(), 2, "Count");
// first server is getting selected
Assert.assertFalse(resultMap.get(serverInstance1).equals(resultMap.get(serverInstance2)), "Element check");
// System.out.println(ctxt);
}
}
use of com.linkedin.pinot.common.response.ServerInstance in project pinot by linkedin.
the class ScatterGatherPerfClient method setup.
private void setup() {
MetricsRegistry registry = new MetricsRegistry();
_timedExecutor = new ScheduledThreadPoolExecutor(1);
_service = new ThreadPoolExecutor(10, 10, 10, TimeUnit.DAYS, new LinkedBlockingDeque<Runnable>());
_eventLoopGroup = new NioEventLoopGroup(10);
_timer = new HashedWheelTimer();
NettyClientMetrics clientMetrics = new NettyClientMetrics(registry, "client_");
PooledNettyClientResourceManager rm = new PooledNettyClientResourceManager(_eventLoopGroup, _timer, clientMetrics);
_pool = new KeyedPoolImpl<ServerInstance, NettyClientConnection>(1, _maxActiveConnections, 300000, 10, rm, _timedExecutor, MoreExecutors.sameThreadExecutor(), registry);
rm.setPool(_pool);
_scatterGather = new ScatterGatherImpl(_pool, _service);
for (AsyncReader r : _readerThreads) {
r.start();
}
}
use of com.linkedin.pinot.common.response.ServerInstance 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