Search in sources :

Example 36 with MetricsRegistryMap

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();
}
Also used : ReadableMetricsRegistry(org.apache.samza.metrics.ReadableMetricsRegistry) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) YarnAppState(org.apache.samza.job.yarn.YarnAppState) HttpServer(org.apache.samza.coordinator.server.HttpServer) YarnContainer(org.apache.samza.job.yarn.YarnContainer) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 37 with MetricsRegistryMap

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();
}
Also used : FlushOptions(org.rocksdb.FlushOptions) WriteOptions(org.rocksdb.WriteOptions) Options(org.rocksdb.Options) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlushOptions(org.rocksdb.FlushOptions) WriteOptions(org.rocksdb.WriteOptions) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) MapConfig(org.apache.samza.config.MapConfig) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) File(java.io.File) Test(org.junit.Test)

Example 38 with MetricsRegistryMap

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();
        }
    }
}
Also used : ReadableMetricsRegistry(org.apache.samza.metrics.ReadableMetricsRegistry) Server(org.eclipse.jetty.server.Server) MetricsConfig(org.apache.samza.config.MetricsConfig) MetricsReporter(org.apache.samza.metrics.MetricsReporter) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) SamzaMonitorService(org.apache.samza.monitor.SamzaMonitorService)

Example 39 with MetricsRegistryMap

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;
}
Also used : CoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore) JobConfig(org.apache.samza.config.JobConfig) ApplicationConfig(org.apache.samza.config.ApplicationConfig) MapConfig(org.apache.samza.config.MapConfig) TaskConfig(org.apache.samza.config.TaskConfig) ZkConfig(org.apache.samza.config.ZkConfig) JobCoordinatorConfig(org.apache.samza.config.JobCoordinatorConfig) Config(org.apache.samza.config.Config) JobCoordinatorFactory(org.apache.samza.coordinator.JobCoordinatorFactory) JobCoordinator(org.apache.samza.coordinator.JobCoordinator) JobCoordinatorConfig(org.apache.samza.config.JobCoordinatorConfig) MapConfig(org.apache.samza.config.MapConfig) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) ProcessorLifecycleListener(org.apache.samza.runtime.ProcessorLifecycleListener)

Example 40 with MetricsRegistryMap

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);
}
Also used : FlushOptions(org.rocksdb.FlushOptions) WriteOptions(org.rocksdb.WriteOptions) Options(org.rocksdb.Options) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) FlushOptions(org.rocksdb.FlushOptions) WriteOptions(org.rocksdb.WriteOptions) MapConfig(org.apache.samza.config.MapConfig) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) File(java.io.File) Before(org.junit.Before)

Aggregations

MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)69 Test (org.junit.Test)27 MapConfig (org.apache.samza.config.MapConfig)24 Config (org.apache.samza.config.Config)23 HashMap (java.util.HashMap)17 JobConfig (org.apache.samza.config.JobConfig)12 Before (org.junit.Before)12 File (java.io.File)10 StorageConfig (org.apache.samza.config.StorageConfig)10 CoordinatorStreamStore (org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore)9 SamzaException (org.apache.samza.SamzaException)8 TaskName (org.apache.samza.container.TaskName)8 TaskModel (org.apache.samza.job.model.TaskModel)8 ClusterManagerConfig (org.apache.samza.config.ClusterManagerConfig)7 LocalityManager (org.apache.samza.container.LocalityManager)7 TaskContext (org.apache.samza.task.TaskContext)7 Partition (org.apache.samza.Partition)6 SystemStream (org.apache.samza.system.SystemStream)6 Map (java.util.Map)5 MetricsConfig (org.apache.samza.config.MetricsConfig)5