use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestYarnContainerHeartbeatServlet method setup.
@Before
public void setup() throws Exception {
container = mock(YarnContainer.class);
ReadableMetricsRegistry registry = new MetricsRegistryMap();
yarnAppState = new YarnAppState(-1, ConverterUtils.toContainerId("container_1350670447861_0003_01_000001"), "testHost", 1, 1);
webApp = new HttpServer("/", 0, "", new ServletHolder(new DefaultServlet()));
webApp.addServlet("/", new YarnContainerHeartbeatServlet(yarnAppState, registry));
webApp.start();
mapper = new ObjectMapper();
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestRocksDbKeyValueStoreJava method testPerf.
@Test
public void testPerf() throws Exception {
Config config = new MapConfig();
Options options = new Options();
options.setCreateIfMissing(true);
File dbDir = new File(System.getProperty("java.io.tmpdir") + "/dbStore" + System.currentTimeMillis());
RocksDbKeyValueStore store = new RocksDbKeyValueStore(dbDir, options, config, false, "dbStore", new WriteOptions(), new FlushOptions(), new KeyValueStoreMetrics("dbStore", new MetricsRegistryMap()));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
String prefix = "this is the key prefix";
Random r = new Random();
for (int i = 0; i < 100000; i++) {
store.put(genKey(outputStream, prefix, r.nextInt()), genValue());
}
byte[] firstKey = genKey(outputStream, prefix, 0);
byte[] lastKey = genKey(outputStream, prefix, Integer.MAX_VALUE);
long start;
start = System.currentTimeMillis();
KeyValueIterator<byte[], byte[]> iterator1 = store.range(firstKey, lastKey);
long rangeTime = System.currentTimeMillis() - start;
start = System.currentTimeMillis();
Iterators.size(iterator1);
long rangeIterTime = System.currentTimeMillis() - start;
System.out.println("range iter create time: " + rangeTime + ", iterate time: " + rangeIterTime);
iterator1.close();
// Please comment out range query part in order to do an accurate perf test for snapshot
start = System.currentTimeMillis();
KeyValueSnapshot<byte[], byte[]> snapshot = store.snapshot(firstKey, lastKey);
KeyValueIterator<byte[], byte[]> iterator2 = snapshot.iterator();
long snapshotTime = System.currentTimeMillis() - start;
start = System.currentTimeMillis();
Iterators.size(iterator2);
long snapshotIterTime = System.currentTimeMillis() - start;
System.out.println("snapshot iter create time: " + snapshotTime + ", iterate time: " + snapshotIterTime);
iterator2.close();
snapshot.close();
store.close();
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class SamzaRestService method main.
/**
* Command line interface to run the server.
*
* @param args arguments supported by {@link org.apache.samza.util.CommandLine}.
* In particular, --config job.config.loader.properties.path and
* --config job.config.loader.factory are used to read the Samza REST config file.
* @throws Exception if the server could not be successfully started.
*/
public static void main(String[] args) throws Exception {
SamzaMonitorService monitorService = null;
try {
SamzaRestConfig config = parseConfig(args);
ReadableMetricsRegistry metricsRegistry = new MetricsRegistryMap();
log.info("Creating new SamzaRestService with config: {}", config);
MetricsConfig metricsConfig = new MetricsConfig(config);
Map<String, MetricsReporter> metricsReporters = MetricsReporterLoader.getMetricsReporters(metricsConfig, Util.getLocalHost().getHostName());
SamzaRestService restService = new SamzaRestService(new Server(config.getPort()), metricsRegistry, metricsReporters, new ServletContextHandler(ServletContextHandler.SESSIONS));
// Add applications
SamzaRestApplication samzaRestApplication = new SamzaRestApplication(config);
ServletContainer container = new ServletContainer(samzaRestApplication);
restService.addServlet(container, "/*");
monitorService = new SamzaMonitorService(config, metricsRegistry);
monitorService.start();
restService.runBlocking();
} catch (Throwable t) {
log.error("Exception in main.", t);
} finally {
if (monitorService != null) {
monitorService.stop();
}
}
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestZkStreamProcessorBase method createStreamProcessor.
protected StreamProcessor createStreamProcessor(final String pId, Map<String, String> map, final CountDownLatch waitStart, final CountDownLatch waitStop) {
map.put(ApplicationConfig.PROCESSOR_ID, pId);
Config config = new MapConfig(map);
String jobCoordinatorFactoryClassName = new JobCoordinatorConfig(config).getJobCoordinatorFactoryClassName();
JobCoordinator jobCoordinator = ReflectionUtil.getObj(jobCoordinatorFactoryClassName, JobCoordinatorFactory.class).getJobCoordinator(pId, config, new MetricsRegistryMap(), Mockito.mock(CoordinatorStreamStore.class));
ProcessorLifecycleListener listener = new ProcessorLifecycleListener() {
@Override
public void beforeStart() {
}
@Override
public void afterStart() {
if (waitStart != null) {
waitStart.countDown();
}
LOG.info("onStart is called for pid=" + pId);
}
@Override
public void afterStop() {
// stopped w/o failure
if (waitStop != null) {
waitStop.countDown();
}
LOG.info("afterStop is called for pid=" + pId + " with successful shutdown");
}
@Override
public void afterFailure(Throwable t) {
// stopped w/ failure
LOG.info("afterStop is called for pid=" + pId + " with failure");
}
};
StreamProcessor processor = new StreamProcessor(pId, config, new HashMap<>(), (StreamTaskFactory) TestStreamTask::new, listener, jobCoordinator);
return processor;
}
use of org.apache.samza.metrics.MetricsRegistryMap in project samza by apache.
the class TestKeyValueSizeHistogramMetric method setup.
@Before
public void setup() {
Config config = new MapConfig();
Options options = new Options();
options.setCreateIfMissing(true);
File dbDir = new File(System.getProperty("java.io.tmpdir") + "/dbStore" + System.currentTimeMillis());
RocksDbKeyValueStore kvStore = new RocksDbKeyValueStore(dbDir, options, config, false, "dbStore", new WriteOptions(), new FlushOptions(), new KeyValueStoreMetrics("dbStore", new MetricsRegistryMap()));
KeyValueStore<String, String> serializedStore = new SerializedKeyValueStore<>(kvStore, stringSerde, stringSerde, serializedKeyValueStoreMetrics);
store = new NullSafeKeyValueStore<>(serializedStore);
}
Aggregations