use of com.linkedin.pinot.common.metrics.BrokerMetrics in project pinot by linkedin.
the class ScatterGatherTest method testMultipleServerError.
@Test
public void testMultipleServerError() throws Exception {
MetricsRegistry registry = new MetricsRegistry();
// Server start
int serverPort1 = 7091;
int serverPort2 = 7092;
int serverPort3 = 7093;
// error server
int serverPort4 = 7094;
NettyTCPServer server1 = new NettyTCPServer(serverPort1, new TestRequestHandlerFactory(0, 1), null);
NettyTCPServer server2 = new NettyTCPServer(serverPort2, new TestRequestHandlerFactory(1, 1), null);
NettyTCPServer server3 = new NettyTCPServer(serverPort3, new TestRequestHandlerFactory(2, 1), null);
NettyTCPServer server4 = new NettyTCPServer(serverPort4, new TestRequestHandlerFactory(3, 1, 1000, true), null);
Thread t1 = new Thread(server1);
Thread t2 = new Thread(server2);
Thread t3 = new Thread(server3);
Thread t4 = new Thread(server4);
t1.start();
t2.start();
t3.start();
t4.start();
//Client setup
ScheduledExecutorService timedExecutor = new ScheduledThreadPoolExecutor(1);
ExecutorService poolExecutor = MoreExecutors.sameThreadExecutor();
ExecutorService service = new ThreadPoolExecutor(1, 1, 1, TimeUnit.DAYS, new LinkedBlockingDeque<Runnable>());
EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
NettyClientMetrics clientMetrics = new NettyClientMetrics(registry, "client_");
PooledNettyClientResourceManager rm = new PooledNettyClientResourceManager(eventLoopGroup, new HashedWheelTimer(), clientMetrics);
KeyedPoolImpl<ServerInstance, NettyClientConnection> pool = new KeyedPoolImpl<ServerInstance, NettyClientConnection>(1, 1, 300000, 1, rm, timedExecutor, poolExecutor, registry);
rm.setPool(pool);
SegmentIdSet pg1 = new SegmentIdSet();
pg1.addSegment(new SegmentId("0"));
SegmentIdSet pg2 = new SegmentIdSet();
pg2.addSegment(new SegmentId("1"));
SegmentIdSet pg3 = new SegmentIdSet();
pg3.addSegment(new SegmentId("2"));
SegmentIdSet pg4 = new SegmentIdSet();
pg4.addSegment(new SegmentId("3"));
ServerInstance serverInstance1 = new ServerInstance("localhost", serverPort1);
ServerInstance serverInstance2 = new ServerInstance("localhost", serverPort2);
ServerInstance serverInstance3 = new ServerInstance("localhost", serverPort3);
ServerInstance serverInstance4 = new ServerInstance("localhost", serverPort4);
Map<ServerInstance, SegmentIdSet> pgMap = new HashMap<ServerInstance, SegmentIdSet>();
pgMap.put(serverInstance1, pg1);
pgMap.put(serverInstance2, pg2);
pgMap.put(serverInstance3, pg3);
pgMap.put(serverInstance4, pg4);
String request1 = "request_0";
String request2 = "request_1";
String request3 = "request_2";
String request4 = "request_3";
Map<SegmentIdSet, String> pgMapStr = new HashMap<SegmentIdSet, String>();
pgMapStr.put(pg1, request1);
pgMapStr.put(pg2, request2);
pgMapStr.put(pg3, request3);
pgMapStr.put(pg4, request4);
ScatterGatherRequest req = new TestScatterGatherRequest(pgMap, pgMapStr, new RoundRobinReplicaSelection(), ReplicaSelectionGranularity.SEGMENT_ID_SET, 0, 1000);
ScatterGatherImpl scImpl = new ScatterGatherImpl(pool, service);
final ScatterGatherStats scatterGatherStats = new ScatterGatherStats();
final BrokerMetrics brokerMetrics = new BrokerMetrics(new MetricsRegistry());
CompositeFuture<ServerInstance, ByteBuf> fut = scImpl.scatterGather(req, scatterGatherStats, brokerMetrics);
Map<ServerInstance, ByteBuf> v = fut.get();
//Only 3 servers return value.
Assert.assertEquals(v.size(), 3);
ByteBuf b = v.get(serverInstance1);
byte[] b2 = new byte[b.readableBytes()];
b.readBytes(b2);
String response = new String(b2);
Assert.assertEquals(response, "response_0_0");
b = v.get(serverInstance2);
b2 = new byte[b.readableBytes()];
b.readBytes(b2);
response = new String(b2);
Assert.assertEquals(response, "response_1_0");
b = v.get(serverInstance3);
b2 = new byte[b.readableBytes()];
b.readBytes(b2);
response = new String(b2);
Assert.assertEquals(response, "response_2_0");
//No response from 4th server
Assert.assertNull(v.get(serverInstance4), "No response from 4th server");
Map<ServerInstance, Throwable> errorMap = fut.getError();
Assert.assertEquals(errorMap.size(), 1, "One error");
Assert.assertNotNull(errorMap.get(serverInstance4), "Server4 returned timeout");
// System.out.println("Error is :" + errorMap.get(serverInstance4));
Thread.sleep(3000);
// System.out.println("Pool Stats :" + pool.getStats());
pool.getStats().refresh();
Assert.assertEquals(pool.getStats().getTotalBadDestroyed(), 1, "Total Bad destroyed");
pool.shutdown();
service.shutdown();
eventLoopGroup.shutdownGracefully();
server1.shutdownGracefully();
server2.shutdownGracefully();
server3.shutdownGracefully();
server4.shutdownGracefully();
}
use of com.linkedin.pinot.common.metrics.BrokerMetrics in project pinot by linkedin.
the class BrokerServerBuilder method buildNetwork.
public void buildNetwork() throws ConfigurationException {
// build transport
Configuration transportConfigs = _config.subset(TRANSPORT_CONFIG_PREFIX);
TransportClientConf conf = new TransportClientConf();
conf.init(transportConfigs);
_registry = new MetricsRegistry();
MetricsHelper.initializeMetrics(_config.subset(METRICS_CONFIG_PREFIX));
MetricsHelper.registerMetricsRegistry(_registry);
_brokerMetrics = new BrokerMetrics(_registry, !emitTableLevelMetrics());
_brokerMetrics.initializeGlobalMeters();
_state.set(State.INIT);
_eventLoopGroup = new NioEventLoopGroup();
/**
* Some of the client metrics uses histogram which is doing synchronous operation.
* These are fixed overhead per request/response.
* TODO: Measure the overhead of this.
*/
final NettyClientMetrics clientMetrics = new NettyClientMetrics(_registry, "client_");
// Setup Netty Connection Pool
_resourceManager = new PooledNettyClientResourceManager(_eventLoopGroup, new HashedWheelTimer(), clientMetrics);
_poolTimeoutExecutor = new ScheduledThreadPoolExecutor(50);
// _requestSenderPool = MoreExecutors.sameThreadExecutor();
_requestSenderPool = Executors.newCachedThreadPool();
final ConnectionPoolConfig connPoolCfg = conf.getConnPool();
_connPool = new KeyedPoolImpl<ServerInstance, NettyClientConnection>(connPoolCfg.getMinConnectionsPerServer(), connPoolCfg.getMaxConnectionsPerServer(), connPoolCfg.getIdleTimeoutMs(), connPoolCfg.getMaxBacklogPerServer(), _resourceManager, _poolTimeoutExecutor, _requestSenderPool, _registry);
// MoreExecutors.sameThreadExecutor(), _registry);
_resourceManager.setPool(_connPool);
// Setup Routing Table
if (conf.getRoutingMode() == RoutingMode.CONFIG) {
final CfgBasedRouting rt = new CfgBasedRouting();
rt.init(conf.getCfgBasedRouting());
_routingTable = rt;
} else {
// Helix based routing is already initialized.
}
// Setup ScatterGather
_scatterGather = new ScatterGatherImpl(_connPool, _requestSenderPool);
// Setup Broker Request Handler
ReduceServiceRegistry reduceServiceRegistry = buildReduceServiceRegistry();
_requestHandler = new BrokerRequestHandler(_routingTable, _timeBoundaryService, _scatterGather, reduceServiceRegistry, _brokerMetrics, _config);
LOGGER.info("Network initialized !!");
}
Aggregations