You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by GitBox <gi...@apache.org> on 2020/04/06 22:10:35 UTC
[GitHub] [storm] bipinprasad opened a new pull request #3244: [STORM-3600]
Add caching in Cluster.calculateSharedOffHeapNodeMemory
bipinprasad opened a new pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244
This yields a 4 fourfold increase in speed when scheduling large cluster. Tested via TestLargeCluster.
Anonymized topologies and configurations generated by TestTopologyAnonymizerUtils.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] bipinprasad commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406491761
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
+ codeResourceMap.put(nm, resource);
+ } else if (resource.endsWith("conf.ser")) {
+ confResourceMap.put(nm, resource);
+ } else {
+ LOG.info("Ignoring unsupported resource file " + resource);
+ }
+ }
+ String[] examinedConfParams = {
+ Config.TOPOLOGY_NAME,
+ Config.TOPOLOGY_SCHEDULER_STRATEGY,
+ Config.TOPOLOGY_PRIORITY,
+ Config.TOPOLOGY_WORKERS,
+ Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB,
+ Config.TOPOLOGY_SUBMITTER_USER,
+ Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT,
+ Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB,
+ Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB,
+ };
+
+ for (String nm : codeResourceMap.keySet()) {
+ String codeResource = codeResourceMap.get(nm);
+ if (!confResourceMap.containsKey(nm)) {
+ String err = String.format("Ignoring topology file %s because of missing config file for %s", codeResource, nm);
+ errors.add(err);
+ LOG.error(err);
+ continue;
+ }
+ String confResource = confResourceMap.get(nm);
+ LOG.info("Found matching topology and config files: {}, {}", codeResource, confResource);
+ StormTopology stormTopology;
+ try {
+ stormTopology = Utils.deserialize(getResourceAsBytes(codeResource), StormTopology.class);
+ } catch (Exception ex) {
+ String err = String.format("Cannot read topology from resource %s", codeResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+
+ Map<String, Object> conf;
+ try {
+ conf = Utils.fromCompressedJsonConf(getResourceAsBytes(confResource));
+ } catch (RuntimeException | IOException ex) {
+ String err = String.format("Cannot read configuration from resource %s", confResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+ // fix 0.10 conf class names
+ String[] configParamsToFix = {Config.TOPOLOGY_SCHEDULER_STRATEGY, Config.STORM_NETWORK_TOPOGRAPHY_PLUGIN,
+ DaemonConfig.RESOURCE_AWARE_SCHEDULER_PRIORITY_STRATEGY };
+ for (String configParam: configParamsToFix) {
+ if (!conf.containsKey(configParam)) {
+ continue;
+ }
+ String className = (String) conf.get(configParam);
+ if (className.startsWith("backtype")) {
+ className = className.replace("backtype", "org.apache");
+ conf.put(configParam, className);
+ }
+ }
+ // fix conf params used by ConstraintSolverStrategy
+ if (!conf.containsKey(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH)) {
+ conf.put(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH, 10_000);
+ }
+ if (!conf.containsKey(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH)) {
+ conf.put(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH, 10_000);
+ }
+
+ String topoId = nm;
+ String topoName = (String) conf.getOrDefault(Config.TOPOLOGY_NAME, nm);
+
+ // conf
+ StringBuffer sb = new StringBuffer("Config for " + nm + ": ");
+ for (String param : examinedConfParams) {
+ Object val = conf.getOrDefault(param, "<null>");
+ sb.append(param).append("=").append(val).append(", ");
+ }
+ LOG.info(sb.toString());
+
+ // topo
+ Map<ExecutorDetails, String> execToComp = TestUtilsForResourceAwareScheduler.genExecsAndComps(stormTopology);
+ LOG.info("Topology \"{}\" spouts={}, bolts={}, execToComp size is {}", topoName,
+ stormTopology.get_spouts_size(), stormTopology.get_bolts_size(), execToComp.size());
+ int numWorkers = Integer.parseInt("" + conf.getOrDefault(Config.TOPOLOGY_WORKERS, "0"));
+ TopologyDetails topo = new TopologyDetails(topoId, conf, stormTopology, numWorkers,
+ execToComp, Time.currentTimeSecs(), "user");
+ topo.getComponents(); // sanity check - normally this should not fail
+
+ topoDetailsList.add(topo);
+ }
+ if (!errors.isEmpty() && failOnParseError) {
+ throw new Exception("Unable to parse all serialized objects\n\t" + String.join("\n\t", errors));
+ }
+ return topoDetailsList.toArray(new TopologyDetails[0]);
+ }
+
+ /**
+ * Check if the files in the resource directory are matched, can be read properly, and code/config files occur
+ * in matched pairs.
+ *
+ * @throws Exception showing bad and unmatched resource files.
+ */
+ @Test
+ public void testReadSerializedTopologiesAndConfigs() throws Exception {
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Assert.assertTrue("No resource files found in " + TEST_RESOURCE_PATH, !resources.isEmpty());
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(true);
+ }
+
+ /**
+ * Create one supervisor and add to the supervisors list.
+ *
+ * @param rack rack-number
+ * @param superInRack supervisor number in the rack
+ * @param cpu percentage
+ * @param mem in megabytes
+ * @param numPorts number of ports on this supervisor
+ * @param sups returned map os supervisors
+ */
+ private static void createAndAddOneSupervisor(
+ int rack, int superInRack, double cpu, double mem, int numPorts,
+ Map<String, SupervisorDetails> sups) {
+
+ List<Number> ports = new LinkedList<>();
+ for (int p = 0; p < numPorts; p++) {
+ ports.add(p);
+ }
+ String superId = String.format("r%03ds%03d", rack, superInRack);
+ String hostId = String.format("host-%03d-rack-%03d", superInRack, rack);
+ Map<String, Double> resourceMap = new HashMap<>();
+ resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, cpu);
+ resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, mem);
+ resourceMap.put("network.resource.units", 50.0);
+ SupervisorDetails sup = new SupervisorDetails(superId,
+ hostId, null, ports,
+ NormalizedResources.RESOURCE_NAME_NORMALIZER.normalizedResourceMap(resourceMap));
+ sups.put(sup.getId(), sup);
+ }
+
+ /**
+ * Create supervisors.
+ *
+ * @param uniformSupervisors true if all supervisors are of the same size, false otherwise.
+ * @return supervisor details indexed by id
+ */
+ private static Map<String, SupervisorDetails> createSupervisors(boolean uniformSupervisors) {
+ Map<String, SupervisorDetails> retVal;
+ if (uniformSupervisors) {
+ int numRacks = 16;
+ int numSupersPerRack = 82;
+ int numPorts = 50; // scheduling will fill up 2-6, leaving of 90% workerslots unused - does this cause slow scheduling?
+ int rackStart = 0;
+ int superInRackStart = 1;
+ double cpu = 7200; // %percent
+ double mem = 356_000; // MB
+ Map<String, Double> miscResources = new HashMap<>();
+ miscResources.put("network.resource.units", 100.0);
+
+ return TestUtilsForResourceAwareScheduler.genSupervisorsWithRacks(
+ numRacks, numSupersPerRack, numPorts, rackStart, superInRackStart, cpu, mem, miscResources);
+
+ } else {
+ // this non-uniform supervisor distribution closelt (but not exactly) mimics IridiumBlue cluster
Review comment:
changed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406510275
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
+ codeResourceMap.put(nm, resource);
+ } else if (resource.endsWith("conf.ser")) {
+ confResourceMap.put(nm, resource);
+ } else {
+ LOG.info("Ignoring unsupported resource file " + resource);
+ }
+ }
+ String[] examinedConfParams = {
+ Config.TOPOLOGY_NAME,
+ Config.TOPOLOGY_SCHEDULER_STRATEGY,
+ Config.TOPOLOGY_PRIORITY,
+ Config.TOPOLOGY_WORKERS,
+ Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB,
+ Config.TOPOLOGY_SUBMITTER_USER,
+ Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT,
+ Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB,
+ Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB,
+ };
+
+ for (String nm : codeResourceMap.keySet()) {
+ String codeResource = codeResourceMap.get(nm);
+ if (!confResourceMap.containsKey(nm)) {
+ String err = String.format("Ignoring topology file %s because of missing config file for %s", codeResource, nm);
+ errors.add(err);
+ LOG.error(err);
+ continue;
+ }
+ String confResource = confResourceMap.get(nm);
+ LOG.info("Found matching topology and config files: {}, {}", codeResource, confResource);
+ StormTopology stormTopology;
+ try {
+ stormTopology = Utils.deserialize(getResourceAsBytes(codeResource), StormTopology.class);
+ } catch (Exception ex) {
+ String err = String.format("Cannot read topology from resource %s", codeResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+
+ Map<String, Object> conf;
+ try {
+ conf = Utils.fromCompressedJsonConf(getResourceAsBytes(confResource));
+ } catch (RuntimeException | IOException ex) {
+ String err = String.format("Cannot read configuration from resource %s", confResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+ // fix 0.10 conf class names
+ String[] configParamsToFix = {Config.TOPOLOGY_SCHEDULER_STRATEGY, Config.STORM_NETWORK_TOPOGRAPHY_PLUGIN,
+ DaemonConfig.RESOURCE_AWARE_SCHEDULER_PRIORITY_STRATEGY };
+ for (String configParam: configParamsToFix) {
+ if (!conf.containsKey(configParam)) {
+ continue;
+ }
+ String className = (String) conf.get(configParam);
+ if (className.startsWith("backtype")) {
+ className = className.replace("backtype", "org.apache");
+ conf.put(configParam, className);
+ }
+ }
+ // fix conf params used by ConstraintSolverStrategy
+ if (!conf.containsKey(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH)) {
+ conf.put(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH, 10_000);
+ }
+ if (!conf.containsKey(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH)) {
+ conf.put(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH, 10_000);
+ }
+
+ String topoId = nm;
+ String topoName = (String) conf.getOrDefault(Config.TOPOLOGY_NAME, nm);
+
+ // conf
+ StringBuffer sb = new StringBuffer("Config for " + nm + ": ");
+ for (String param : examinedConfParams) {
+ Object val = conf.getOrDefault(param, "<null>");
+ sb.append(param).append("=").append(val).append(", ");
+ }
+ LOG.info(sb.toString());
+
+ // topo
+ Map<ExecutorDetails, String> execToComp = TestUtilsForResourceAwareScheduler.genExecsAndComps(stormTopology);
+ LOG.info("Topology \"{}\" spouts={}, bolts={}, execToComp size is {}", topoName,
+ stormTopology.get_spouts_size(), stormTopology.get_bolts_size(), execToComp.size());
+ int numWorkers = Integer.parseInt("" + conf.getOrDefault(Config.TOPOLOGY_WORKERS, "0"));
+ TopologyDetails topo = new TopologyDetails(topoId, conf, stormTopology, numWorkers,
+ execToComp, Time.currentTimeSecs(), "user");
+ topo.getComponents(); // sanity check - normally this should not fail
+
+ topoDetailsList.add(topo);
+ }
+ if (!errors.isEmpty() && failOnParseError) {
+ throw new Exception("Unable to parse all serialized objects\n\t" + String.join("\n\t", errors));
+ }
+ return topoDetailsList.toArray(new TopologyDetails[0]);
+ }
+
+ /**
+ * Check if the files in the resource directory are matched, can be read properly, and code/config files occur
+ * in matched pairs.
+ *
+ * @throws Exception showing bad and unmatched resource files.
+ */
+ @Test
+ public void testReadSerializedTopologiesAndConfigs() throws Exception {
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Assert.assertTrue("No resource files found in " + TEST_RESOURCE_PATH, !resources.isEmpty());
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(true);
+ }
+
+ /**
+ * Create one supervisor and add to the supervisors list.
+ *
+ * @param rack rack-number
+ * @param superInRack supervisor number in the rack
+ * @param cpu percentage
+ * @param mem in megabytes
+ * @param numPorts number of ports on this supervisor
+ * @param sups returned map os supervisors
+ */
+ private static void createAndAddOneSupervisor(
+ int rack, int superInRack, double cpu, double mem, int numPorts,
+ Map<String, SupervisorDetails> sups) {
+
+ List<Number> ports = new LinkedList<>();
+ for (int p = 0; p < numPorts; p++) {
+ ports.add(p);
+ }
+ String superId = String.format("r%03ds%03d", rack, superInRack);
+ String hostId = String.format("host-%03d-rack-%03d", superInRack, rack);
+ Map<String, Double> resourceMap = new HashMap<>();
+ resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, cpu);
+ resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, mem);
+ resourceMap.put("network.resource.units", 50.0);
+ SupervisorDetails sup = new SupervisorDetails(superId,
+ hostId, null, ports,
+ NormalizedResources.RESOURCE_NAME_NORMALIZER.normalizedResourceMap(resourceMap));
+ sups.put(sup.getId(), sup);
+ }
+
+ /**
+ * Create supervisors.
+ *
+ * @param uniformSupervisors true if all supervisors are of the same size, false otherwise.
+ * @return supervisor details indexed by id
+ */
+ private static Map<String, SupervisorDetails> createSupervisors(boolean uniformSupervisors) {
+ Map<String, SupervisorDetails> retVal;
+ if (uniformSupervisors) {
+ int numRacks = 16;
+ int numSupersPerRack = 82;
+ int numPorts = 50; // scheduling will fill up 2-6, leaving of 90% workerslots unused - does this cause slow scheduling?
Review comment:
It would be better if it can be reworded. Your comment here is much clearer to me
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r408889508
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -70,6 +70,8 @@
public static final String TEST_CLUSTER_NAME = "largeCluster01";
public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+ public static final String COMPRESSED_SERIALIZED_TOPOLOGY_FILENAME_ENDING = "code.ser";
Review comment:
There is a variable with the same name in TestTopologyAnonymizerUtils.java but with different meanings. What's the difference here?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] bipinprasad commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406492383
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
+ codeResourceMap.put(nm, resource);
+ } else if (resource.endsWith("conf.ser")) {
+ confResourceMap.put(nm, resource);
+ } else {
+ LOG.info("Ignoring unsupported resource file " + resource);
+ }
+ }
+ String[] examinedConfParams = {
+ Config.TOPOLOGY_NAME,
+ Config.TOPOLOGY_SCHEDULER_STRATEGY,
+ Config.TOPOLOGY_PRIORITY,
+ Config.TOPOLOGY_WORKERS,
+ Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB,
+ Config.TOPOLOGY_SUBMITTER_USER,
+ Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT,
+ Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB,
+ Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB,
+ };
+
+ for (String nm : codeResourceMap.keySet()) {
+ String codeResource = codeResourceMap.get(nm);
+ if (!confResourceMap.containsKey(nm)) {
+ String err = String.format("Ignoring topology file %s because of missing config file for %s", codeResource, nm);
+ errors.add(err);
+ LOG.error(err);
+ continue;
+ }
+ String confResource = confResourceMap.get(nm);
+ LOG.info("Found matching topology and config files: {}, {}", codeResource, confResource);
+ StormTopology stormTopology;
+ try {
+ stormTopology = Utils.deserialize(getResourceAsBytes(codeResource), StormTopology.class);
+ } catch (Exception ex) {
+ String err = String.format("Cannot read topology from resource %s", codeResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+
+ Map<String, Object> conf;
+ try {
+ conf = Utils.fromCompressedJsonConf(getResourceAsBytes(confResource));
+ } catch (RuntimeException | IOException ex) {
+ String err = String.format("Cannot read configuration from resource %s", confResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+ // fix 0.10 conf class names
+ String[] configParamsToFix = {Config.TOPOLOGY_SCHEDULER_STRATEGY, Config.STORM_NETWORK_TOPOGRAPHY_PLUGIN,
+ DaemonConfig.RESOURCE_AWARE_SCHEDULER_PRIORITY_STRATEGY };
+ for (String configParam: configParamsToFix) {
+ if (!conf.containsKey(configParam)) {
+ continue;
+ }
+ String className = (String) conf.get(configParam);
+ if (className.startsWith("backtype")) {
+ className = className.replace("backtype", "org.apache");
+ conf.put(configParam, className);
+ }
+ }
+ // fix conf params used by ConstraintSolverStrategy
+ if (!conf.containsKey(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH)) {
+ conf.put(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH, 10_000);
+ }
+ if (!conf.containsKey(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH)) {
+ conf.put(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH, 10_000);
+ }
+
+ String topoId = nm;
+ String topoName = (String) conf.getOrDefault(Config.TOPOLOGY_NAME, nm);
+
+ // conf
+ StringBuffer sb = new StringBuffer("Config for " + nm + ": ");
+ for (String param : examinedConfParams) {
+ Object val = conf.getOrDefault(param, "<null>");
+ sb.append(param).append("=").append(val).append(", ");
+ }
+ LOG.info(sb.toString());
+
+ // topo
+ Map<ExecutorDetails, String> execToComp = TestUtilsForResourceAwareScheduler.genExecsAndComps(stormTopology);
+ LOG.info("Topology \"{}\" spouts={}, bolts={}, execToComp size is {}", topoName,
+ stormTopology.get_spouts_size(), stormTopology.get_bolts_size(), execToComp.size());
+ int numWorkers = Integer.parseInt("" + conf.getOrDefault(Config.TOPOLOGY_WORKERS, "0"));
+ TopologyDetails topo = new TopologyDetails(topoId, conf, stormTopology, numWorkers,
+ execToComp, Time.currentTimeSecs(), "user");
+ topo.getComponents(); // sanity check - normally this should not fail
+
+ topoDetailsList.add(topo);
+ }
+ if (!errors.isEmpty() && failOnParseError) {
+ throw new Exception("Unable to parse all serialized objects\n\t" + String.join("\n\t", errors));
+ }
+ return topoDetailsList.toArray(new TopologyDetails[0]);
+ }
+
+ /**
+ * Check if the files in the resource directory are matched, can be read properly, and code/config files occur
+ * in matched pairs.
+ *
+ * @throws Exception showing bad and unmatched resource files.
+ */
+ @Test
+ public void testReadSerializedTopologiesAndConfigs() throws Exception {
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Assert.assertTrue("No resource files found in " + TEST_RESOURCE_PATH, !resources.isEmpty());
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(true);
+ }
+
+ /**
+ * Create one supervisor and add to the supervisors list.
+ *
+ * @param rack rack-number
+ * @param superInRack supervisor number in the rack
+ * @param cpu percentage
+ * @param mem in megabytes
+ * @param numPorts number of ports on this supervisor
+ * @param sups returned map os supervisors
+ */
+ private static void createAndAddOneSupervisor(
+ int rack, int superInRack, double cpu, double mem, int numPorts,
+ Map<String, SupervisorDetails> sups) {
+
+ List<Number> ports = new LinkedList<>();
+ for (int p = 0; p < numPorts; p++) {
+ ports.add(p);
+ }
+ String superId = String.format("r%03ds%03d", rack, superInRack);
+ String hostId = String.format("host-%03d-rack-%03d", superInRack, rack);
+ Map<String, Double> resourceMap = new HashMap<>();
+ resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, cpu);
+ resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, mem);
+ resourceMap.put("network.resource.units", 50.0);
+ SupervisorDetails sup = new SupervisorDetails(superId,
+ hostId, null, ports,
+ NormalizedResources.RESOURCE_NAME_NORMALIZER.normalizedResourceMap(resourceMap));
+ sups.put(sup.getId(), sup);
+ }
+
+ /**
+ * Create supervisors.
+ *
+ * @param uniformSupervisors true if all supervisors are of the same size, false otherwise.
+ * @return supervisor details indexed by id
+ */
+ private static Map<String, SupervisorDetails> createSupervisors(boolean uniformSupervisors) {
+ Map<String, SupervisorDetails> retVal;
+ if (uniformSupervisors) {
+ int numRacks = 16;
+ int numSupersPerRack = 82;
+ int numPorts = 50; // scheduling will fill up 2-6, leaving of 90% workerslots unused - does this cause slow scheduling?
+ int rackStart = 0;
+ int superInRackStart = 1;
+ double cpu = 7200; // %percent
+ double mem = 356_000; // MB
+ Map<String, Double> miscResources = new HashMap<>();
+ miscResources.put("network.resource.units", 100.0);
+
+ return TestUtilsForResourceAwareScheduler.genSupervisorsWithRacks(
+ numRacks, numSupersPerRack, numPorts, rackStart, superInRackStart, cpu, mem, miscResources);
+
+ } else {
+ // this non-uniform supervisor distribution closelt (but not exactly) mimics IridiumBlue cluster
+ int numSupersPerRack = 82;
+ int numPorts = 50;
+
+ Map<String, SupervisorDetails> retList = new HashMap<>();
+
+ for (int rack = 0 ; rack < 12 ; rack++) {
+ double cpu = 3600; // %percent
+ double mem = 178_000; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ for (int rack = 12 ; rack < 14 ; rack++) {
+ double cpu = 2400; // %percent
+ double mem = 118_100; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ for (int rack = 14 ; rack < 16 ; rack++) {
+ double cpu = 1200; // %percent
+ double mem = 42_480; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ return retList;
+ }
+ }
+
+ /**
+ * Create a large cluster, read topologies and configuration from resource directory and schedule.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testLargeCluster() throws Exception {
+ boolean uniformSupervisors = false; // false means non-uniform supervisor distribution
+
+ Map<String, SupervisorDetails> supervisors = createSupervisors(uniformSupervisors);
+
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(false);
+ Assert.assertTrue("No topologies found", topoDetailsArray.length > 0);
+ Topologies topologies = new Topologies(topoDetailsArray);
+
+ Config confWithDefaultStrategy = new Config();
+ confWithDefaultStrategy.putAll(topoDetailsArray[0].getConf());
+ confWithDefaultStrategy.put(Config.TOPOLOGY_SCHEDULER_STRATEGY, DefaultResourceAwareStrategy.class.getName());
+
+ INimbus iNimbus = new INimbusTest();
+ Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supervisors, new HashMap<>(),
+ topologies, confWithDefaultStrategy);
+
+ scheduler = new ResourceAwareScheduler();
+
+ List<Class> classesToDebug = Arrays.asList(DefaultResourceAwareStrategy.class,
+ GenericResourceAwareStrategy.class, ResourceAwareScheduler.class,
+ Cluster.class // count calls to calculateSharedOffHeapNodeMemory()
Review comment:
I had debug statement earlier in Cluster.java - since removed. Comment is not relevant any more.
Removed.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] bipinprasad commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406495728
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
+ codeResourceMap.put(nm, resource);
+ } else if (resource.endsWith("conf.ser")) {
+ confResourceMap.put(nm, resource);
+ } else {
+ LOG.info("Ignoring unsupported resource file " + resource);
+ }
+ }
+ String[] examinedConfParams = {
+ Config.TOPOLOGY_NAME,
+ Config.TOPOLOGY_SCHEDULER_STRATEGY,
+ Config.TOPOLOGY_PRIORITY,
+ Config.TOPOLOGY_WORKERS,
+ Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB,
+ Config.TOPOLOGY_SUBMITTER_USER,
+ Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT,
+ Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB,
+ Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB,
+ };
+
+ for (String nm : codeResourceMap.keySet()) {
+ String codeResource = codeResourceMap.get(nm);
+ if (!confResourceMap.containsKey(nm)) {
+ String err = String.format("Ignoring topology file %s because of missing config file for %s", codeResource, nm);
+ errors.add(err);
+ LOG.error(err);
+ continue;
+ }
+ String confResource = confResourceMap.get(nm);
+ LOG.info("Found matching topology and config files: {}, {}", codeResource, confResource);
+ StormTopology stormTopology;
+ try {
+ stormTopology = Utils.deserialize(getResourceAsBytes(codeResource), StormTopology.class);
+ } catch (Exception ex) {
+ String err = String.format("Cannot read topology from resource %s", codeResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+
+ Map<String, Object> conf;
+ try {
+ conf = Utils.fromCompressedJsonConf(getResourceAsBytes(confResource));
+ } catch (RuntimeException | IOException ex) {
+ String err = String.format("Cannot read configuration from resource %s", confResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+ // fix 0.10 conf class names
+ String[] configParamsToFix = {Config.TOPOLOGY_SCHEDULER_STRATEGY, Config.STORM_NETWORK_TOPOGRAPHY_PLUGIN,
+ DaemonConfig.RESOURCE_AWARE_SCHEDULER_PRIORITY_STRATEGY };
+ for (String configParam: configParamsToFix) {
+ if (!conf.containsKey(configParam)) {
+ continue;
+ }
+ String className = (String) conf.get(configParam);
+ if (className.startsWith("backtype")) {
+ className = className.replace("backtype", "org.apache");
+ conf.put(configParam, className);
+ }
+ }
+ // fix conf params used by ConstraintSolverStrategy
+ if (!conf.containsKey(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH)) {
+ conf.put(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH, 10_000);
+ }
+ if (!conf.containsKey(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH)) {
+ conf.put(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH, 10_000);
+ }
+
+ String topoId = nm;
+ String topoName = (String) conf.getOrDefault(Config.TOPOLOGY_NAME, nm);
+
+ // conf
+ StringBuffer sb = new StringBuffer("Config for " + nm + ": ");
+ for (String param : examinedConfParams) {
+ Object val = conf.getOrDefault(param, "<null>");
+ sb.append(param).append("=").append(val).append(", ");
+ }
+ LOG.info(sb.toString());
+
+ // topo
+ Map<ExecutorDetails, String> execToComp = TestUtilsForResourceAwareScheduler.genExecsAndComps(stormTopology);
+ LOG.info("Topology \"{}\" spouts={}, bolts={}, execToComp size is {}", topoName,
+ stormTopology.get_spouts_size(), stormTopology.get_bolts_size(), execToComp.size());
+ int numWorkers = Integer.parseInt("" + conf.getOrDefault(Config.TOPOLOGY_WORKERS, "0"));
+ TopologyDetails topo = new TopologyDetails(topoId, conf, stormTopology, numWorkers,
+ execToComp, Time.currentTimeSecs(), "user");
+ topo.getComponents(); // sanity check - normally this should not fail
+
+ topoDetailsList.add(topo);
+ }
+ if (!errors.isEmpty() && failOnParseError) {
+ throw new Exception("Unable to parse all serialized objects\n\t" + String.join("\n\t", errors));
+ }
+ return topoDetailsList.toArray(new TopologyDetails[0]);
+ }
+
+ /**
+ * Check if the files in the resource directory are matched, can be read properly, and code/config files occur
+ * in matched pairs.
+ *
+ * @throws Exception showing bad and unmatched resource files.
+ */
+ @Test
+ public void testReadSerializedTopologiesAndConfigs() throws Exception {
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Assert.assertTrue("No resource files found in " + TEST_RESOURCE_PATH, !resources.isEmpty());
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(true);
+ }
+
+ /**
+ * Create one supervisor and add to the supervisors list.
+ *
+ * @param rack rack-number
+ * @param superInRack supervisor number in the rack
+ * @param cpu percentage
+ * @param mem in megabytes
+ * @param numPorts number of ports on this supervisor
+ * @param sups returned map os supervisors
+ */
+ private static void createAndAddOneSupervisor(
+ int rack, int superInRack, double cpu, double mem, int numPorts,
+ Map<String, SupervisorDetails> sups) {
+
+ List<Number> ports = new LinkedList<>();
+ for (int p = 0; p < numPorts; p++) {
+ ports.add(p);
+ }
+ String superId = String.format("r%03ds%03d", rack, superInRack);
+ String hostId = String.format("host-%03d-rack-%03d", superInRack, rack);
+ Map<String, Double> resourceMap = new HashMap<>();
+ resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, cpu);
+ resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, mem);
+ resourceMap.put("network.resource.units", 50.0);
+ SupervisorDetails sup = new SupervisorDetails(superId,
+ hostId, null, ports,
+ NormalizedResources.RESOURCE_NAME_NORMALIZER.normalizedResourceMap(resourceMap));
+ sups.put(sup.getId(), sup);
+ }
+
+ /**
+ * Create supervisors.
+ *
+ * @param uniformSupervisors true if all supervisors are of the same size, false otherwise.
+ * @return supervisor details indexed by id
+ */
+ private static Map<String, SupervisorDetails> createSupervisors(boolean uniformSupervisors) {
+ Map<String, SupervisorDetails> retVal;
+ if (uniformSupervisors) {
+ int numRacks = 16;
+ int numSupersPerRack = 82;
+ int numPorts = 50; // scheduling will fill up 2-6, leaving of 90% workerslots unused - does this cause slow scheduling?
+ int rackStart = 0;
+ int superInRackStart = 1;
+ double cpu = 7200; // %percent
+ double mem = 356_000; // MB
+ Map<String, Double> miscResources = new HashMap<>();
+ miscResources.put("network.resource.units", 100.0);
+
+ return TestUtilsForResourceAwareScheduler.genSupervisorsWithRacks(
+ numRacks, numSupersPerRack, numPorts, rackStart, superInRackStart, cpu, mem, miscResources);
+
+ } else {
+ // this non-uniform supervisor distribution closelt (but not exactly) mimics IridiumBlue cluster
+ int numSupersPerRack = 82;
+ int numPorts = 50;
+
+ Map<String, SupervisorDetails> retList = new HashMap<>();
+
+ for (int rack = 0 ; rack < 12 ; rack++) {
+ double cpu = 3600; // %percent
+ double mem = 178_000; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ for (int rack = 12 ; rack < 14 ; rack++) {
+ double cpu = 2400; // %percent
+ double mem = 118_100; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ for (int rack = 14 ; rack < 16 ; rack++) {
+ double cpu = 1200; // %percent
+ double mem = 42_480; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ return retList;
+ }
+ }
+
+ /**
+ * Create a large cluster, read topologies and configuration from resource directory and schedule.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testLargeCluster() throws Exception {
+ boolean uniformSupervisors = false; // false means non-uniform supervisor distribution
+
+ Map<String, SupervisorDetails> supervisors = createSupervisors(uniformSupervisors);
+
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(false);
+ Assert.assertTrue("No topologies found", topoDetailsArray.length > 0);
+ Topologies topologies = new Topologies(topoDetailsArray);
+
+ Config confWithDefaultStrategy = new Config();
+ confWithDefaultStrategy.putAll(topoDetailsArray[0].getConf());
+ confWithDefaultStrategy.put(Config.TOPOLOGY_SCHEDULER_STRATEGY, DefaultResourceAwareStrategy.class.getName());
+
+ INimbus iNimbus = new INimbusTest();
+ Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supervisors, new HashMap<>(),
+ topologies, confWithDefaultStrategy);
+
+ scheduler = new ResourceAwareScheduler();
+
+ List<Class> classesToDebug = Arrays.asList(DefaultResourceAwareStrategy.class,
+ GenericResourceAwareStrategy.class, ResourceAwareScheduler.class,
+ Cluster.class // count calls to calculateSharedOffHeapNodeMemory()
+ );
+ Level logLevel = Level.INFO ; // switch to Level.DEBUG for verbose otherwise Level.INFO
+ classesToDebug.forEach(x -> Configurator.setLevel(x.getName(), logLevel));
+ long startTime = System.currentTimeMillis();
+ scheduler.prepare(confWithDefaultStrategy, new StormMetricsRegistry());
+ scheduler.schedule(topologies, cluster);
+ long endTime = System.currentTimeMillis();
+ LOG.info("Scheduling Time: {} topologies in {} seconds", topoDetailsArray.length, (endTime - startTime) / 1000.0);
+
+ for (TopologyDetails td : topoDetailsArray) {
+ TestUtilsForResourceAwareScheduler.assertTopologiesFullyScheduled(cluster, td.getName());
+ }
+
+ // Remove topology and reschedule it
+ java.util.Random random = new java.util.Random();
+ for (int i = 0 ; i < topoDetailsArray.length ; i++) {
+ startTime = System.currentTimeMillis();
+ int iTopo = i; // random.nextInt(topoDetailsArray.length);
Review comment:
i for now.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] bipinprasad commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406490221
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
+ codeResourceMap.put(nm, resource);
+ } else if (resource.endsWith("conf.ser")) {
+ confResourceMap.put(nm, resource);
+ } else {
+ LOG.info("Ignoring unsupported resource file " + resource);
+ }
+ }
+ String[] examinedConfParams = {
+ Config.TOPOLOGY_NAME,
+ Config.TOPOLOGY_SCHEDULER_STRATEGY,
+ Config.TOPOLOGY_PRIORITY,
+ Config.TOPOLOGY_WORKERS,
+ Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB,
+ Config.TOPOLOGY_SUBMITTER_USER,
+ Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT,
+ Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB,
+ Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB,
+ };
+
+ for (String nm : codeResourceMap.keySet()) {
+ String codeResource = codeResourceMap.get(nm);
+ if (!confResourceMap.containsKey(nm)) {
+ String err = String.format("Ignoring topology file %s because of missing config file for %s", codeResource, nm);
+ errors.add(err);
+ LOG.error(err);
+ continue;
+ }
+ String confResource = confResourceMap.get(nm);
+ LOG.info("Found matching topology and config files: {}, {}", codeResource, confResource);
+ StormTopology stormTopology;
+ try {
+ stormTopology = Utils.deserialize(getResourceAsBytes(codeResource), StormTopology.class);
+ } catch (Exception ex) {
+ String err = String.format("Cannot read topology from resource %s", codeResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+
+ Map<String, Object> conf;
+ try {
+ conf = Utils.fromCompressedJsonConf(getResourceAsBytes(confResource));
+ } catch (RuntimeException | IOException ex) {
+ String err = String.format("Cannot read configuration from resource %s", confResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+ // fix 0.10 conf class names
+ String[] configParamsToFix = {Config.TOPOLOGY_SCHEDULER_STRATEGY, Config.STORM_NETWORK_TOPOGRAPHY_PLUGIN,
+ DaemonConfig.RESOURCE_AWARE_SCHEDULER_PRIORITY_STRATEGY };
+ for (String configParam: configParamsToFix) {
+ if (!conf.containsKey(configParam)) {
+ continue;
+ }
+ String className = (String) conf.get(configParam);
+ if (className.startsWith("backtype")) {
+ className = className.replace("backtype", "org.apache");
+ conf.put(configParam, className);
+ }
+ }
+ // fix conf params used by ConstraintSolverStrategy
+ if (!conf.containsKey(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH)) {
+ conf.put(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH, 10_000);
+ }
+ if (!conf.containsKey(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH)) {
+ conf.put(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH, 10_000);
+ }
+
+ String topoId = nm;
+ String topoName = (String) conf.getOrDefault(Config.TOPOLOGY_NAME, nm);
+
+ // conf
+ StringBuffer sb = new StringBuffer("Config for " + nm + ": ");
+ for (String param : examinedConfParams) {
+ Object val = conf.getOrDefault(param, "<null>");
+ sb.append(param).append("=").append(val).append(", ");
+ }
+ LOG.info(sb.toString());
+
+ // topo
+ Map<ExecutorDetails, String> execToComp = TestUtilsForResourceAwareScheduler.genExecsAndComps(stormTopology);
+ LOG.info("Topology \"{}\" spouts={}, bolts={}, execToComp size is {}", topoName,
+ stormTopology.get_spouts_size(), stormTopology.get_bolts_size(), execToComp.size());
+ int numWorkers = Integer.parseInt("" + conf.getOrDefault(Config.TOPOLOGY_WORKERS, "0"));
+ TopologyDetails topo = new TopologyDetails(topoId, conf, stormTopology, numWorkers,
+ execToComp, Time.currentTimeSecs(), "user");
+ topo.getComponents(); // sanity check - normally this should not fail
+
+ topoDetailsList.add(topo);
+ }
+ if (!errors.isEmpty() && failOnParseError) {
+ throw new Exception("Unable to parse all serialized objects\n\t" + String.join("\n\t", errors));
+ }
+ return topoDetailsList.toArray(new TopologyDetails[0]);
+ }
+
+ /**
+ * Check if the files in the resource directory are matched, can be read properly, and code/config files occur
+ * in matched pairs.
+ *
+ * @throws Exception showing bad and unmatched resource files.
+ */
+ @Test
+ public void testReadSerializedTopologiesAndConfigs() throws Exception {
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Assert.assertTrue("No resource files found in " + TEST_RESOURCE_PATH, !resources.isEmpty());
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(true);
+ }
+
+ /**
+ * Create one supervisor and add to the supervisors list.
+ *
+ * @param rack rack-number
+ * @param superInRack supervisor number in the rack
+ * @param cpu percentage
+ * @param mem in megabytes
+ * @param numPorts number of ports on this supervisor
+ * @param sups returned map os supervisors
+ */
+ private static void createAndAddOneSupervisor(
+ int rack, int superInRack, double cpu, double mem, int numPorts,
+ Map<String, SupervisorDetails> sups) {
+
+ List<Number> ports = new LinkedList<>();
+ for (int p = 0; p < numPorts; p++) {
+ ports.add(p);
+ }
+ String superId = String.format("r%03ds%03d", rack, superInRack);
+ String hostId = String.format("host-%03d-rack-%03d", superInRack, rack);
+ Map<String, Double> resourceMap = new HashMap<>();
+ resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, cpu);
+ resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, mem);
+ resourceMap.put("network.resource.units", 50.0);
+ SupervisorDetails sup = new SupervisorDetails(superId,
+ hostId, null, ports,
+ NormalizedResources.RESOURCE_NAME_NORMALIZER.normalizedResourceMap(resourceMap));
+ sups.put(sup.getId(), sup);
+ }
+
+ /**
+ * Create supervisors.
+ *
+ * @param uniformSupervisors true if all supervisors are of the same size, false otherwise.
+ * @return supervisor details indexed by id
+ */
+ private static Map<String, SupervisorDetails> createSupervisors(boolean uniformSupervisors) {
+ Map<String, SupervisorDetails> retVal;
+ if (uniformSupervisors) {
+ int numRacks = 16;
+ int numSupersPerRack = 82;
+ int numPorts = 50; // scheduling will fill up 2-6, leaving of 90% workerslots unused - does this cause slow scheduling?
Review comment:
I found that for topology components with large cpu/mem, most of the workeslots get left unused - but the looping logic in scheduling spends a lot of cycles in those. How workerslots are processed may need to be revisited for further speed gains. If it is not clear, it needs to be reworded.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406510012
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
+ codeResourceMap.put(nm, resource);
+ } else if (resource.endsWith("conf.ser")) {
+ confResourceMap.put(nm, resource);
+ } else {
+ LOG.info("Ignoring unsupported resource file " + resource);
+ }
+ }
+ String[] examinedConfParams = {
+ Config.TOPOLOGY_NAME,
+ Config.TOPOLOGY_SCHEDULER_STRATEGY,
+ Config.TOPOLOGY_PRIORITY,
+ Config.TOPOLOGY_WORKERS,
+ Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB,
+ Config.TOPOLOGY_SUBMITTER_USER,
+ Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT,
+ Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB,
+ Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB,
+ };
+
+ for (String nm : codeResourceMap.keySet()) {
Review comment:
Thanks. I was confused about `nm` variable. Maybe `name` is more clear. But that's fine.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406509469
##########
File path: storm-server/src/main/java/org/apache/storm/scheduler/Cluster.java
##########
@@ -709,6 +720,33 @@ public void assign(SchedulerAssignment assignment, boolean ignoreSingleException
}
}
+ /**
+ * Initialize the flag to true if specified topology uses SharedOffHeapNodeMemory, false otherwise.
+ *
+ * @param td TopologyDetails to examine
+ */
+ private void initializeTopoSharedOffHeapNodeMemoryFlag(TopologyDetails td) {
+ String topoId = td.getId();
+ topoSharedOffHeapMemoryNodeFlag.put(topoId, false);
+ StormTopology topology = td.getTopology();
+ if (topology == null) {
+ return; // accomodate multitenant_scheduler_test.clj
+ }
+ if (topology.is_set_component_to_shared_memory()) {
Review comment:
They are designed this way. For example
I can have two SharedMemory with name as `sharedMemory1` and `sharedMemory2`.
And I can add `sharedMemory1` to `comp1` and `sharedMemory2` to `comp2`.
Now shared_memory is
object1 (name=`sharedMemory1`), object2 (name=`sharedMemory2`);
component_to_shared_memory is
`comp1` -> object1 (name=`sharedMemory1`), `comp2` -> object2 (name=`sharedMemory2`);
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] bipinprasad commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406483094
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestTopologyAnonymizerUtils.java
##########
@@ -0,0 +1,355 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.Bolt;
+import org.apache.storm.generated.GlobalStreamId;
+import org.apache.storm.generated.SpoutSpec;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.serialization.GzipThriftSerializationDelegate;
+import org.apache.storm.utils.Utils;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Anonymize Serialized Topologies and Configs with the goal of taking internally developed topologies and configuration
+ * and make them publicly available for testing.
+ *
+ * Assume that topologies and configurations exist in the specified resource directory with names ending in stormcode.ser
+ * and stormconf.ser respectively as they exist in blobstore. Also, stormconf.ser file shares the same name prefix with
+ * the topology serialized file.
+ *
+ * <li> Rename topologies and its corresponding configuration (as identified by its resource name). Ensure that renamed
+ * configuration file for a topology retains the proper linkage so that:
+ * <p><old-topo-name>-stormcode.ser -> <new-topo-name>-stormcode.ser</p> and its old conf
+ * <p><old-topo-name>-stormconf.ser -> <new-topo-name>-stormconf.ser</p>
+ * </li>
+ *
+ * <li>Rename components in each of the topologies.</li>
+ *
+ * The new converted resource files can be copied to a resource directory under "clusterconf" and made available for use
+ * in TestLargeCluster class.
+ */
+public class TestTopologyAnonymizerUtils {
+ private static final Logger LOG = LoggerFactory.getLogger(TestTopologyAnonymizerUtils.class);
+
+ private static final String DEFAULT_ORIGINAL_RESOURCES_PATH = "clusterconf/iridiumblue";
+ private static final String DEFAULT_ANONYMIZED_RESOURCES_OUTDIR = "src/test/resources/clusterconf/largeCluster01";
+
+ private String originalResourcePath;
+ private String outputDirPath;
+
+ public TestTopologyAnonymizerUtils() {
+ this.originalResourcePath = DEFAULT_ORIGINAL_RESOURCES_PATH;
+ this.outputDirPath = DEFAULT_ANONYMIZED_RESOURCES_OUTDIR;
+ }
+
+ //public TestTopologyAnonymizerUtils(String originalResourcePath, String outputDirPath) {
Review comment:
removed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406445528
##########
File path: storm-server/src/main/java/org/apache/storm/scheduler/Cluster.java
##########
@@ -709,6 +720,33 @@ public void assign(SchedulerAssignment assignment, boolean ignoreSingleException
}
}
+ /**
+ * Initialize the flag to true if specified topology uses SharedOffHeapNodeMemory, false otherwise.
+ *
+ * @param td TopologyDetails to examine
+ */
+ private void initializeTopoSharedOffHeapNodeMemoryFlag(TopologyDetails td) {
+ String topoId = td.getId();
+ topoSharedOffHeapMemoryNodeFlag.put(topoId, false);
+ StormTopology topology = td.getTopology();
+ if (topology == null) {
+ return; // accomodate multitenant_scheduler_test.clj
+ }
+ if (topology.is_set_component_to_shared_memory()) {
Review comment:
We should be able to simplify this with
```
StormTopology topology = td.getTopology();
if (topology.is_set_shared_memory()) {
for (SharedMemory sharedMemory : topology.get_shared_memory().values()) {
double val = sharedMemory.get_off_heap_node();
if (val > 0.0) {
topoSharedOffHeapMemoryNodeFlag.put(topoId, true);
return;
}
}
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] govind-menon commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
govind-menon commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r407732285
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
Review comment:
Agreed - try with resources will close as part of the "destructor"
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] govind-menon commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
govind-menon commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r407732526
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,456 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
Review comment:
Nit: See above about extracting file extension as cosnt ants
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on issue #3244: [STORM-3600] Add caching
in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on issue #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#issuecomment-611680934
```
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check (validate) on project storm-server: You have 1 Checkstyle violation. -> [Help 1]
```
There is a checkstyle violation. Can you please fix it? Thanks
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406454009
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
+ codeResourceMap.put(nm, resource);
+ } else if (resource.endsWith("conf.ser")) {
+ confResourceMap.put(nm, resource);
+ } else {
+ LOG.info("Ignoring unsupported resource file " + resource);
+ }
+ }
+ String[] examinedConfParams = {
+ Config.TOPOLOGY_NAME,
+ Config.TOPOLOGY_SCHEDULER_STRATEGY,
+ Config.TOPOLOGY_PRIORITY,
+ Config.TOPOLOGY_WORKERS,
+ Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB,
+ Config.TOPOLOGY_SUBMITTER_USER,
+ Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT,
+ Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB,
+ Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB,
+ };
+
+ for (String nm : codeResourceMap.keySet()) {
Review comment:
It looks like `nm` is actually `topoId`? What does `nm` stand for?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] kishorvpatil merged pull request #3244: [STORM-3600] Add
caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
kishorvpatil merged pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] bipinprasad commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r408559074
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,456 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
Review comment:
changed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406446966
##########
File path: storm-server/src/main/java/org/apache/storm/scheduler/Cluster.java
##########
@@ -749,12 +792,16 @@ private double calculateSharedOffHeapNodeMemory(
*/
public void freeSlot(WorkerSlot slot) {
// remove the slot from the existing assignments
+ String nodeId = slot.getNodeId();
Review comment:
Since this is added, Line 808 can be updated to use `nodeId` instead of `slot.getNodeId()`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] bipinprasad commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406481252
##########
File path: storm-server/src/main/java/org/apache/storm/scheduler/Cluster.java
##########
@@ -709,6 +720,33 @@ public void assign(SchedulerAssignment assignment, boolean ignoreSingleException
}
}
+ /**
+ * Initialize the flag to true if specified topology uses SharedOffHeapNodeMemory, false otherwise.
+ *
+ * @param td TopologyDetails to examine
+ */
+ private void initializeTopoSharedOffHeapNodeMemoryFlag(TopologyDetails td) {
+ String topoId = td.getId();
+ topoSharedOffHeapMemoryNodeFlag.put(topoId, false);
+ StormTopology topology = td.getTopology();
+ if (topology == null) {
+ return; // accomodate multitenant_scheduler_test.clj
+ }
+ if (topology.is_set_component_to_shared_memory()) {
Review comment:
(1) topology == null check is required weirdly enough due to some other tests failure (later I also found note in TopologyDetails.getSharedMemoryRequests()
(2) In StormTopology shared_memory and component_to_shared_memory are two different thrift fields. And setters don't seem to cross set. If I change this code then this will change the prior logic in Cluster.java. How are these two different fields equivalent?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406450528
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
Review comment:
I was wondering if `return` within the try-with-resources block will close the resources or not. And I found this https://stackoverflow.com/questions/22947755/try-with-resources-and-return-statements-in-java/22947904
So it should be fine.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406457877
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestTopologyAnonymizerUtils.java
##########
@@ -0,0 +1,355 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.Bolt;
+import org.apache.storm.generated.GlobalStreamId;
+import org.apache.storm.generated.SpoutSpec;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.serialization.GzipThriftSerializationDelegate;
+import org.apache.storm.utils.Utils;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Anonymize Serialized Topologies and Configs with the goal of taking internally developed topologies and configuration
+ * and make them publicly available for testing.
+ *
+ * Assume that topologies and configurations exist in the specified resource directory with names ending in stormcode.ser
+ * and stormconf.ser respectively as they exist in blobstore. Also, stormconf.ser file shares the same name prefix with
+ * the topology serialized file.
+ *
+ * <li> Rename topologies and its corresponding configuration (as identified by its resource name). Ensure that renamed
+ * configuration file for a topology retains the proper linkage so that:
+ * <p><old-topo-name>-stormcode.ser -> <new-topo-name>-stormcode.ser</p> and its old conf
+ * <p><old-topo-name>-stormconf.ser -> <new-topo-name>-stormconf.ser</p>
+ * </li>
+ *
+ * <li>Rename components in each of the topologies.</li>
+ *
+ * The new converted resource files can be copied to a resource directory under "clusterconf" and made available for use
+ * in TestLargeCluster class.
+ */
+public class TestTopologyAnonymizerUtils {
+ private static final Logger LOG = LoggerFactory.getLogger(TestTopologyAnonymizerUtils.class);
+
+ private static final String DEFAULT_ORIGINAL_RESOURCES_PATH = "clusterconf/iridiumblue";
+ private static final String DEFAULT_ANONYMIZED_RESOURCES_OUTDIR = "src/test/resources/clusterconf/largeCluster01";
+
+ private String originalResourcePath;
+ private String outputDirPath;
+
+ public TestTopologyAnonymizerUtils() {
+ this.originalResourcePath = DEFAULT_ORIGINAL_RESOURCES_PATH;
+ this.outputDirPath = DEFAULT_ANONYMIZED_RESOURCES_OUTDIR;
+ }
+
+ //public TestTopologyAnonymizerUtils(String originalResourcePath, String outputDirPath) {
Review comment:
Maybe clean up the comments if they are not needed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] bipinprasad commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r408912963
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -70,6 +70,8 @@
public static final String TEST_CLUSTER_NAME = "largeCluster01";
public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+ public static final String COMPRESSED_SERIALIZED_TOPOLOGY_FILENAME_ENDING = "code.ser";
Review comment:
Anonymizer can be stricter with naming convention. Files in the resources need just the bare minimum to be distinguished from each other. But more importantly, they are independent of each other.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406510511
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
+ codeResourceMap.put(nm, resource);
+ } else if (resource.endsWith("conf.ser")) {
+ confResourceMap.put(nm, resource);
+ } else {
+ LOG.info("Ignoring unsupported resource file " + resource);
+ }
+ }
+ String[] examinedConfParams = {
+ Config.TOPOLOGY_NAME,
+ Config.TOPOLOGY_SCHEDULER_STRATEGY,
+ Config.TOPOLOGY_PRIORITY,
+ Config.TOPOLOGY_WORKERS,
+ Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB,
+ Config.TOPOLOGY_SUBMITTER_USER,
+ Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT,
+ Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB,
+ Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB,
+ };
+
+ for (String nm : codeResourceMap.keySet()) {
+ String codeResource = codeResourceMap.get(nm);
+ if (!confResourceMap.containsKey(nm)) {
+ String err = String.format("Ignoring topology file %s because of missing config file for %s", codeResource, nm);
+ errors.add(err);
+ LOG.error(err);
+ continue;
+ }
+ String confResource = confResourceMap.get(nm);
+ LOG.info("Found matching topology and config files: {}, {}", codeResource, confResource);
+ StormTopology stormTopology;
+ try {
+ stormTopology = Utils.deserialize(getResourceAsBytes(codeResource), StormTopology.class);
+ } catch (Exception ex) {
+ String err = String.format("Cannot read topology from resource %s", codeResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+
+ Map<String, Object> conf;
+ try {
+ conf = Utils.fromCompressedJsonConf(getResourceAsBytes(confResource));
+ } catch (RuntimeException | IOException ex) {
+ String err = String.format("Cannot read configuration from resource %s", confResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+ // fix 0.10 conf class names
+ String[] configParamsToFix = {Config.TOPOLOGY_SCHEDULER_STRATEGY, Config.STORM_NETWORK_TOPOGRAPHY_PLUGIN,
+ DaemonConfig.RESOURCE_AWARE_SCHEDULER_PRIORITY_STRATEGY };
+ for (String configParam: configParamsToFix) {
+ if (!conf.containsKey(configParam)) {
+ continue;
+ }
+ String className = (String) conf.get(configParam);
+ if (className.startsWith("backtype")) {
+ className = className.replace("backtype", "org.apache");
+ conf.put(configParam, className);
+ }
+ }
+ // fix conf params used by ConstraintSolverStrategy
+ if (!conf.containsKey(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH)) {
+ conf.put(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH, 10_000);
+ }
+ if (!conf.containsKey(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH)) {
+ conf.put(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH, 10_000);
+ }
+
+ String topoId = nm;
+ String topoName = (String) conf.getOrDefault(Config.TOPOLOGY_NAME, nm);
+
+ // conf
+ StringBuffer sb = new StringBuffer("Config for " + nm + ": ");
+ for (String param : examinedConfParams) {
+ Object val = conf.getOrDefault(param, "<null>");
+ sb.append(param).append("=").append(val).append(", ");
+ }
+ LOG.info(sb.toString());
+
+ // topo
+ Map<ExecutorDetails, String> execToComp = TestUtilsForResourceAwareScheduler.genExecsAndComps(stormTopology);
+ LOG.info("Topology \"{}\" spouts={}, bolts={}, execToComp size is {}", topoName,
+ stormTopology.get_spouts_size(), stormTopology.get_bolts_size(), execToComp.size());
+ int numWorkers = Integer.parseInt("" + conf.getOrDefault(Config.TOPOLOGY_WORKERS, "0"));
+ TopologyDetails topo = new TopologyDetails(topoId, conf, stormTopology, numWorkers,
+ execToComp, Time.currentTimeSecs(), "user");
+ topo.getComponents(); // sanity check - normally this should not fail
+
+ topoDetailsList.add(topo);
+ }
+ if (!errors.isEmpty() && failOnParseError) {
+ throw new Exception("Unable to parse all serialized objects\n\t" + String.join("\n\t", errors));
+ }
+ return topoDetailsList.toArray(new TopologyDetails[0]);
+ }
+
+ /**
+ * Check if the files in the resource directory are matched, can be read properly, and code/config files occur
+ * in matched pairs.
+ *
+ * @throws Exception showing bad and unmatched resource files.
+ */
+ @Test
+ public void testReadSerializedTopologiesAndConfigs() throws Exception {
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Assert.assertTrue("No resource files found in " + TEST_RESOURCE_PATH, !resources.isEmpty());
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(true);
+ }
+
+ /**
+ * Create one supervisor and add to the supervisors list.
+ *
+ * @param rack rack-number
+ * @param superInRack supervisor number in the rack
+ * @param cpu percentage
+ * @param mem in megabytes
+ * @param numPorts number of ports on this supervisor
+ * @param sups returned map os supervisors
+ */
+ private static void createAndAddOneSupervisor(
+ int rack, int superInRack, double cpu, double mem, int numPorts,
+ Map<String, SupervisorDetails> sups) {
+
+ List<Number> ports = new LinkedList<>();
+ for (int p = 0; p < numPorts; p++) {
+ ports.add(p);
+ }
+ String superId = String.format("r%03ds%03d", rack, superInRack);
+ String hostId = String.format("host-%03d-rack-%03d", superInRack, rack);
+ Map<String, Double> resourceMap = new HashMap<>();
+ resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, cpu);
+ resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, mem);
+ resourceMap.put("network.resource.units", 50.0);
+ SupervisorDetails sup = new SupervisorDetails(superId,
+ hostId, null, ports,
+ NormalizedResources.RESOURCE_NAME_NORMALIZER.normalizedResourceMap(resourceMap));
+ sups.put(sup.getId(), sup);
+ }
+
+ /**
+ * Create supervisors.
+ *
+ * @param uniformSupervisors true if all supervisors are of the same size, false otherwise.
+ * @return supervisor details indexed by id
+ */
+ private static Map<String, SupervisorDetails> createSupervisors(boolean uniformSupervisors) {
+ Map<String, SupervisorDetails> retVal;
+ if (uniformSupervisors) {
+ int numRacks = 16;
+ int numSupersPerRack = 82;
+ int numPorts = 50; // scheduling will fill up 2-6, leaving of 90% workerslots unused - does this cause slow scheduling?
+ int rackStart = 0;
+ int superInRackStart = 1;
+ double cpu = 7200; // %percent
+ double mem = 356_000; // MB
+ Map<String, Double> miscResources = new HashMap<>();
+ miscResources.put("network.resource.units", 100.0);
+
+ return TestUtilsForResourceAwareScheduler.genSupervisorsWithRacks(
+ numRacks, numSupersPerRack, numPorts, rackStart, superInRackStart, cpu, mem, miscResources);
+
+ } else {
+ // this non-uniform supervisor distribution closelt (but not exactly) mimics IridiumBlue cluster
+ int numSupersPerRack = 82;
+ int numPorts = 50;
+
+ Map<String, SupervisorDetails> retList = new HashMap<>();
+
+ for (int rack = 0 ; rack < 12 ; rack++) {
+ double cpu = 3600; // %percent
+ double mem = 178_000; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ for (int rack = 12 ; rack < 14 ; rack++) {
+ double cpu = 2400; // %percent
+ double mem = 118_100; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ for (int rack = 14 ; rack < 16 ; rack++) {
+ double cpu = 1200; // %percent
+ double mem = 42_480; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ return retList;
+ }
+ }
+
+ /**
+ * Create a large cluster, read topologies and configuration from resource directory and schedule.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testLargeCluster() throws Exception {
+ boolean uniformSupervisors = false; // false means non-uniform supervisor distribution
+
+ Map<String, SupervisorDetails> supervisors = createSupervisors(uniformSupervisors);
+
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(false);
+ Assert.assertTrue("No topologies found", topoDetailsArray.length > 0);
+ Topologies topologies = new Topologies(topoDetailsArray);
+
+ Config confWithDefaultStrategy = new Config();
+ confWithDefaultStrategy.putAll(topoDetailsArray[0].getConf());
+ confWithDefaultStrategy.put(Config.TOPOLOGY_SCHEDULER_STRATEGY, DefaultResourceAwareStrategy.class.getName());
+
+ INimbus iNimbus = new INimbusTest();
+ Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supervisors, new HashMap<>(),
+ topologies, confWithDefaultStrategy);
+
+ scheduler = new ResourceAwareScheduler();
+
+ List<Class> classesToDebug = Arrays.asList(DefaultResourceAwareStrategy.class,
+ GenericResourceAwareStrategy.class, ResourceAwareScheduler.class,
+ Cluster.class // count calls to calculateSharedOffHeapNodeMemory()
+ );
+ Level logLevel = Level.INFO ; // switch to Level.DEBUG for verbose otherwise Level.INFO
+ classesToDebug.forEach(x -> Configurator.setLevel(x.getName(), logLevel));
+ long startTime = System.currentTimeMillis();
+ scheduler.prepare(confWithDefaultStrategy, new StormMetricsRegistry());
+ scheduler.schedule(topologies, cluster);
+ long endTime = System.currentTimeMillis();
+ LOG.info("Scheduling Time: {} topologies in {} seconds", topoDetailsArray.length, (endTime - startTime) / 1000.0);
+
+ for (TopologyDetails td : topoDetailsArray) {
+ TestUtilsForResourceAwareScheduler.assertTopologiesFullyScheduled(cluster, td.getName());
+ }
+
+ // Remove topology and reschedule it
+ java.util.Random random = new java.util.Random();
+ for (int i = 0 ; i < topoDetailsArray.length ; i++) {
+ startTime = System.currentTimeMillis();
+ int iTopo = i; // random.nextInt(topoDetailsArray.length);
Review comment:
Maybe clean it up to avoid confusion. Pick one
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] govind-menon commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
govind-menon commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r407732526
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,456 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
Review comment:
Nit: See above about extracting file extension as constants
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] bipinprasad commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406556930
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
Review comment:
Yes. Pretty cool JDK 8 feature. Here is more authoritative info - which actually uses return as an example too: https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] bipinprasad commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406531454
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
+ codeResourceMap.put(nm, resource);
+ } else if (resource.endsWith("conf.ser")) {
+ confResourceMap.put(nm, resource);
+ } else {
+ LOG.info("Ignoring unsupported resource file " + resource);
+ }
+ }
+ String[] examinedConfParams = {
+ Config.TOPOLOGY_NAME,
+ Config.TOPOLOGY_SCHEDULER_STRATEGY,
+ Config.TOPOLOGY_PRIORITY,
+ Config.TOPOLOGY_WORKERS,
+ Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB,
+ Config.TOPOLOGY_SUBMITTER_USER,
+ Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT,
+ Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB,
+ Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB,
+ };
+
+ for (String nm : codeResourceMap.keySet()) {
+ String codeResource = codeResourceMap.get(nm);
+ if (!confResourceMap.containsKey(nm)) {
+ String err = String.format("Ignoring topology file %s because of missing config file for %s", codeResource, nm);
+ errors.add(err);
+ LOG.error(err);
+ continue;
+ }
+ String confResource = confResourceMap.get(nm);
+ LOG.info("Found matching topology and config files: {}, {}", codeResource, confResource);
+ StormTopology stormTopology;
+ try {
+ stormTopology = Utils.deserialize(getResourceAsBytes(codeResource), StormTopology.class);
+ } catch (Exception ex) {
+ String err = String.format("Cannot read topology from resource %s", codeResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+
+ Map<String, Object> conf;
+ try {
+ conf = Utils.fromCompressedJsonConf(getResourceAsBytes(confResource));
+ } catch (RuntimeException | IOException ex) {
+ String err = String.format("Cannot read configuration from resource %s", confResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+ // fix 0.10 conf class names
+ String[] configParamsToFix = {Config.TOPOLOGY_SCHEDULER_STRATEGY, Config.STORM_NETWORK_TOPOGRAPHY_PLUGIN,
+ DaemonConfig.RESOURCE_AWARE_SCHEDULER_PRIORITY_STRATEGY };
+ for (String configParam: configParamsToFix) {
+ if (!conf.containsKey(configParam)) {
+ continue;
+ }
+ String className = (String) conf.get(configParam);
+ if (className.startsWith("backtype")) {
+ className = className.replace("backtype", "org.apache");
+ conf.put(configParam, className);
+ }
+ }
+ // fix conf params used by ConstraintSolverStrategy
+ if (!conf.containsKey(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH)) {
+ conf.put(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH, 10_000);
+ }
+ if (!conf.containsKey(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH)) {
+ conf.put(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH, 10_000);
+ }
+
+ String topoId = nm;
+ String topoName = (String) conf.getOrDefault(Config.TOPOLOGY_NAME, nm);
+
+ // conf
+ StringBuffer sb = new StringBuffer("Config for " + nm + ": ");
+ for (String param : examinedConfParams) {
+ Object val = conf.getOrDefault(param, "<null>");
+ sb.append(param).append("=").append(val).append(", ");
+ }
+ LOG.info(sb.toString());
+
+ // topo
+ Map<ExecutorDetails, String> execToComp = TestUtilsForResourceAwareScheduler.genExecsAndComps(stormTopology);
+ LOG.info("Topology \"{}\" spouts={}, bolts={}, execToComp size is {}", topoName,
+ stormTopology.get_spouts_size(), stormTopology.get_bolts_size(), execToComp.size());
+ int numWorkers = Integer.parseInt("" + conf.getOrDefault(Config.TOPOLOGY_WORKERS, "0"));
+ TopologyDetails topo = new TopologyDetails(topoId, conf, stormTopology, numWorkers,
+ execToComp, Time.currentTimeSecs(), "user");
+ topo.getComponents(); // sanity check - normally this should not fail
+
+ topoDetailsList.add(topo);
+ }
+ if (!errors.isEmpty() && failOnParseError) {
+ throw new Exception("Unable to parse all serialized objects\n\t" + String.join("\n\t", errors));
+ }
+ return topoDetailsList.toArray(new TopologyDetails[0]);
+ }
+
+ /**
+ * Check if the files in the resource directory are matched, can be read properly, and code/config files occur
+ * in matched pairs.
+ *
+ * @throws Exception showing bad and unmatched resource files.
+ */
+ @Test
+ public void testReadSerializedTopologiesAndConfigs() throws Exception {
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Assert.assertTrue("No resource files found in " + TEST_RESOURCE_PATH, !resources.isEmpty());
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(true);
+ }
+
+ /**
+ * Create one supervisor and add to the supervisors list.
+ *
+ * @param rack rack-number
+ * @param superInRack supervisor number in the rack
+ * @param cpu percentage
+ * @param mem in megabytes
+ * @param numPorts number of ports on this supervisor
+ * @param sups returned map os supervisors
+ */
+ private static void createAndAddOneSupervisor(
+ int rack, int superInRack, double cpu, double mem, int numPorts,
+ Map<String, SupervisorDetails> sups) {
+
+ List<Number> ports = new LinkedList<>();
+ for (int p = 0; p < numPorts; p++) {
+ ports.add(p);
+ }
+ String superId = String.format("r%03ds%03d", rack, superInRack);
+ String hostId = String.format("host-%03d-rack-%03d", superInRack, rack);
+ Map<String, Double> resourceMap = new HashMap<>();
+ resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, cpu);
+ resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, mem);
+ resourceMap.put("network.resource.units", 50.0);
+ SupervisorDetails sup = new SupervisorDetails(superId,
+ hostId, null, ports,
+ NormalizedResources.RESOURCE_NAME_NORMALIZER.normalizedResourceMap(resourceMap));
+ sups.put(sup.getId(), sup);
+ }
+
+ /**
+ * Create supervisors.
+ *
+ * @param uniformSupervisors true if all supervisors are of the same size, false otherwise.
+ * @return supervisor details indexed by id
+ */
+ private static Map<String, SupervisorDetails> createSupervisors(boolean uniformSupervisors) {
+ Map<String, SupervisorDetails> retVal;
+ if (uniformSupervisors) {
+ int numRacks = 16;
+ int numSupersPerRack = 82;
+ int numPorts = 50; // scheduling will fill up 2-6, leaving of 90% workerslots unused - does this cause slow scheduling?
+ int rackStart = 0;
+ int superInRackStart = 1;
+ double cpu = 7200; // %percent
+ double mem = 356_000; // MB
+ Map<String, Double> miscResources = new HashMap<>();
+ miscResources.put("network.resource.units", 100.0);
+
+ return TestUtilsForResourceAwareScheduler.genSupervisorsWithRacks(
+ numRacks, numSupersPerRack, numPorts, rackStart, superInRackStart, cpu, mem, miscResources);
+
+ } else {
+ // this non-uniform supervisor distribution closelt (but not exactly) mimics IridiumBlue cluster
+ int numSupersPerRack = 82;
+ int numPorts = 50;
+
+ Map<String, SupervisorDetails> retList = new HashMap<>();
+
+ for (int rack = 0 ; rack < 12 ; rack++) {
+ double cpu = 3600; // %percent
+ double mem = 178_000; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ for (int rack = 12 ; rack < 14 ; rack++) {
+ double cpu = 2400; // %percent
+ double mem = 118_100; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ for (int rack = 14 ; rack < 16 ; rack++) {
+ double cpu = 1200; // %percent
+ double mem = 42_480; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ return retList;
+ }
+ }
+
+ /**
+ * Create a large cluster, read topologies and configuration from resource directory and schedule.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testLargeCluster() throws Exception {
+ boolean uniformSupervisors = false; // false means non-uniform supervisor distribution
+
+ Map<String, SupervisorDetails> supervisors = createSupervisors(uniformSupervisors);
+
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(false);
+ Assert.assertTrue("No topologies found", topoDetailsArray.length > 0);
+ Topologies topologies = new Topologies(topoDetailsArray);
+
+ Config confWithDefaultStrategy = new Config();
+ confWithDefaultStrategy.putAll(topoDetailsArray[0].getConf());
+ confWithDefaultStrategy.put(Config.TOPOLOGY_SCHEDULER_STRATEGY, DefaultResourceAwareStrategy.class.getName());
+
+ INimbus iNimbus = new INimbusTest();
+ Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supervisors, new HashMap<>(),
+ topologies, confWithDefaultStrategy);
+
+ scheduler = new ResourceAwareScheduler();
+
+ List<Class> classesToDebug = Arrays.asList(DefaultResourceAwareStrategy.class,
+ GenericResourceAwareStrategy.class, ResourceAwareScheduler.class,
+ Cluster.class // count calls to calculateSharedOffHeapNodeMemory()
+ );
+ Level logLevel = Level.INFO ; // switch to Level.DEBUG for verbose otherwise Level.INFO
+ classesToDebug.forEach(x -> Configurator.setLevel(x.getName(), logLevel));
+ long startTime = System.currentTimeMillis();
+ scheduler.prepare(confWithDefaultStrategy, new StormMetricsRegistry());
+ scheduler.schedule(topologies, cluster);
+ long endTime = System.currentTimeMillis();
+ LOG.info("Scheduling Time: {} topologies in {} seconds", topoDetailsArray.length, (endTime - startTime) / 1000.0);
+
+ for (TopologyDetails td : topoDetailsArray) {
+ TestUtilsForResourceAwareScheduler.assertTopologiesFullyScheduled(cluster, td.getName());
+ }
+
+ // Remove topology and reschedule it
+ java.util.Random random = new java.util.Random();
+ for (int i = 0 ; i < topoDetailsArray.length ; i++) {
+ startTime = System.currentTimeMillis();
+ int iTopo = i; // random.nextInt(topoDetailsArray.length);
Review comment:
changed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406456599
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
+ codeResourceMap.put(nm, resource);
+ } else if (resource.endsWith("conf.ser")) {
+ confResourceMap.put(nm, resource);
+ } else {
+ LOG.info("Ignoring unsupported resource file " + resource);
+ }
+ }
+ String[] examinedConfParams = {
+ Config.TOPOLOGY_NAME,
+ Config.TOPOLOGY_SCHEDULER_STRATEGY,
+ Config.TOPOLOGY_PRIORITY,
+ Config.TOPOLOGY_WORKERS,
+ Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB,
+ Config.TOPOLOGY_SUBMITTER_USER,
+ Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT,
+ Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB,
+ Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB,
+ };
+
+ for (String nm : codeResourceMap.keySet()) {
+ String codeResource = codeResourceMap.get(nm);
+ if (!confResourceMap.containsKey(nm)) {
+ String err = String.format("Ignoring topology file %s because of missing config file for %s", codeResource, nm);
+ errors.add(err);
+ LOG.error(err);
+ continue;
+ }
+ String confResource = confResourceMap.get(nm);
+ LOG.info("Found matching topology and config files: {}, {}", codeResource, confResource);
+ StormTopology stormTopology;
+ try {
+ stormTopology = Utils.deserialize(getResourceAsBytes(codeResource), StormTopology.class);
+ } catch (Exception ex) {
+ String err = String.format("Cannot read topology from resource %s", codeResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+
+ Map<String, Object> conf;
+ try {
+ conf = Utils.fromCompressedJsonConf(getResourceAsBytes(confResource));
+ } catch (RuntimeException | IOException ex) {
+ String err = String.format("Cannot read configuration from resource %s", confResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+ // fix 0.10 conf class names
+ String[] configParamsToFix = {Config.TOPOLOGY_SCHEDULER_STRATEGY, Config.STORM_NETWORK_TOPOGRAPHY_PLUGIN,
+ DaemonConfig.RESOURCE_AWARE_SCHEDULER_PRIORITY_STRATEGY };
+ for (String configParam: configParamsToFix) {
+ if (!conf.containsKey(configParam)) {
+ continue;
+ }
+ String className = (String) conf.get(configParam);
+ if (className.startsWith("backtype")) {
+ className = className.replace("backtype", "org.apache");
+ conf.put(configParam, className);
+ }
+ }
+ // fix conf params used by ConstraintSolverStrategy
+ if (!conf.containsKey(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH)) {
+ conf.put(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH, 10_000);
+ }
+ if (!conf.containsKey(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH)) {
+ conf.put(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH, 10_000);
+ }
+
+ String topoId = nm;
+ String topoName = (String) conf.getOrDefault(Config.TOPOLOGY_NAME, nm);
+
+ // conf
+ StringBuffer sb = new StringBuffer("Config for " + nm + ": ");
+ for (String param : examinedConfParams) {
+ Object val = conf.getOrDefault(param, "<null>");
+ sb.append(param).append("=").append(val).append(", ");
+ }
+ LOG.info(sb.toString());
+
+ // topo
+ Map<ExecutorDetails, String> execToComp = TestUtilsForResourceAwareScheduler.genExecsAndComps(stormTopology);
+ LOG.info("Topology \"{}\" spouts={}, bolts={}, execToComp size is {}", topoName,
+ stormTopology.get_spouts_size(), stormTopology.get_bolts_size(), execToComp.size());
+ int numWorkers = Integer.parseInt("" + conf.getOrDefault(Config.TOPOLOGY_WORKERS, "0"));
+ TopologyDetails topo = new TopologyDetails(topoId, conf, stormTopology, numWorkers,
+ execToComp, Time.currentTimeSecs(), "user");
+ topo.getComponents(); // sanity check - normally this should not fail
+
+ topoDetailsList.add(topo);
+ }
+ if (!errors.isEmpty() && failOnParseError) {
+ throw new Exception("Unable to parse all serialized objects\n\t" + String.join("\n\t", errors));
+ }
+ return topoDetailsList.toArray(new TopologyDetails[0]);
+ }
+
+ /**
+ * Check if the files in the resource directory are matched, can be read properly, and code/config files occur
+ * in matched pairs.
+ *
+ * @throws Exception showing bad and unmatched resource files.
+ */
+ @Test
+ public void testReadSerializedTopologiesAndConfigs() throws Exception {
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Assert.assertTrue("No resource files found in " + TEST_RESOURCE_PATH, !resources.isEmpty());
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(true);
+ }
+
+ /**
+ * Create one supervisor and add to the supervisors list.
+ *
+ * @param rack rack-number
+ * @param superInRack supervisor number in the rack
+ * @param cpu percentage
+ * @param mem in megabytes
+ * @param numPorts number of ports on this supervisor
+ * @param sups returned map os supervisors
+ */
+ private static void createAndAddOneSupervisor(
+ int rack, int superInRack, double cpu, double mem, int numPorts,
+ Map<String, SupervisorDetails> sups) {
+
+ List<Number> ports = new LinkedList<>();
+ for (int p = 0; p < numPorts; p++) {
+ ports.add(p);
+ }
+ String superId = String.format("r%03ds%03d", rack, superInRack);
+ String hostId = String.format("host-%03d-rack-%03d", superInRack, rack);
+ Map<String, Double> resourceMap = new HashMap<>();
+ resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, cpu);
+ resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, mem);
+ resourceMap.put("network.resource.units", 50.0);
+ SupervisorDetails sup = new SupervisorDetails(superId,
+ hostId, null, ports,
+ NormalizedResources.RESOURCE_NAME_NORMALIZER.normalizedResourceMap(resourceMap));
+ sups.put(sup.getId(), sup);
+ }
+
+ /**
+ * Create supervisors.
+ *
+ * @param uniformSupervisors true if all supervisors are of the same size, false otherwise.
+ * @return supervisor details indexed by id
+ */
+ private static Map<String, SupervisorDetails> createSupervisors(boolean uniformSupervisors) {
+ Map<String, SupervisorDetails> retVal;
+ if (uniformSupervisors) {
+ int numRacks = 16;
+ int numSupersPerRack = 82;
+ int numPorts = 50; // scheduling will fill up 2-6, leaving of 90% workerslots unused - does this cause slow scheduling?
+ int rackStart = 0;
+ int superInRackStart = 1;
+ double cpu = 7200; // %percent
+ double mem = 356_000; // MB
+ Map<String, Double> miscResources = new HashMap<>();
+ miscResources.put("network.resource.units", 100.0);
+
+ return TestUtilsForResourceAwareScheduler.genSupervisorsWithRacks(
+ numRacks, numSupersPerRack, numPorts, rackStart, superInRackStart, cpu, mem, miscResources);
+
+ } else {
+ // this non-uniform supervisor distribution closelt (but not exactly) mimics IridiumBlue cluster
+ int numSupersPerRack = 82;
+ int numPorts = 50;
+
+ Map<String, SupervisorDetails> retList = new HashMap<>();
+
+ for (int rack = 0 ; rack < 12 ; rack++) {
+ double cpu = 3600; // %percent
+ double mem = 178_000; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ for (int rack = 12 ; rack < 14 ; rack++) {
+ double cpu = 2400; // %percent
+ double mem = 118_100; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ for (int rack = 14 ; rack < 16 ; rack++) {
+ double cpu = 1200; // %percent
+ double mem = 42_480; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ return retList;
+ }
+ }
+
+ /**
+ * Create a large cluster, read topologies and configuration from resource directory and schedule.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testLargeCluster() throws Exception {
+ boolean uniformSupervisors = false; // false means non-uniform supervisor distribution
+
+ Map<String, SupervisorDetails> supervisors = createSupervisors(uniformSupervisors);
+
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(false);
+ Assert.assertTrue("No topologies found", topoDetailsArray.length > 0);
+ Topologies topologies = new Topologies(topoDetailsArray);
+
+ Config confWithDefaultStrategy = new Config();
+ confWithDefaultStrategy.putAll(topoDetailsArray[0].getConf());
+ confWithDefaultStrategy.put(Config.TOPOLOGY_SCHEDULER_STRATEGY, DefaultResourceAwareStrategy.class.getName());
+
+ INimbus iNimbus = new INimbusTest();
+ Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supervisors, new HashMap<>(),
+ topologies, confWithDefaultStrategy);
+
+ scheduler = new ResourceAwareScheduler();
+
+ List<Class> classesToDebug = Arrays.asList(DefaultResourceAwareStrategy.class,
+ GenericResourceAwareStrategy.class, ResourceAwareScheduler.class,
+ Cluster.class // count calls to calculateSharedOffHeapNodeMemory()
+ );
+ Level logLevel = Level.INFO ; // switch to Level.DEBUG for verbose otherwise Level.INFO
+ classesToDebug.forEach(x -> Configurator.setLevel(x.getName(), logLevel));
+ long startTime = System.currentTimeMillis();
+ scheduler.prepare(confWithDefaultStrategy, new StormMetricsRegistry());
+ scheduler.schedule(topologies, cluster);
+ long endTime = System.currentTimeMillis();
+ LOG.info("Scheduling Time: {} topologies in {} seconds", topoDetailsArray.length, (endTime - startTime) / 1000.0);
+
+ for (TopologyDetails td : topoDetailsArray) {
+ TestUtilsForResourceAwareScheduler.assertTopologiesFullyScheduled(cluster, td.getName());
+ }
+
+ // Remove topology and reschedule it
+ java.util.Random random = new java.util.Random();
+ for (int i = 0 ; i < topoDetailsArray.length ; i++) {
+ startTime = System.currentTimeMillis();
+ int iTopo = i; // random.nextInt(topoDetailsArray.length);
Review comment:
Which one we want to keep? ` iTopo = i` or `random.nextInt(topoDetailsArray.length);`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] govind-menon commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
govind-menon commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r407731489
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,456 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
Review comment:
Nit: move these file extensions as constants to the head of the file
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] bipinprasad commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r408558957
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,456 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
Review comment:
changed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] bipinprasad commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406487668
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
+ codeResourceMap.put(nm, resource);
+ } else if (resource.endsWith("conf.ser")) {
+ confResourceMap.put(nm, resource);
+ } else {
+ LOG.info("Ignoring unsupported resource file " + resource);
+ }
+ }
+ String[] examinedConfParams = {
+ Config.TOPOLOGY_NAME,
+ Config.TOPOLOGY_SCHEDULER_STRATEGY,
+ Config.TOPOLOGY_PRIORITY,
+ Config.TOPOLOGY_WORKERS,
+ Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB,
+ Config.TOPOLOGY_SUBMITTER_USER,
+ Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT,
+ Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB,
+ Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB,
+ };
+
+ for (String nm : codeResourceMap.keySet()) {
Review comment:
nm (name) is the crud that stands in from of the code.ser and conf.ser in the file name and is the same for two topology and config files for the same topology. The code is expecting/assuming topology name to be embedded in the file names.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406456957
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
+ codeResourceMap.put(nm, resource);
+ } else if (resource.endsWith("conf.ser")) {
+ confResourceMap.put(nm, resource);
+ } else {
+ LOG.info("Ignoring unsupported resource file " + resource);
+ }
+ }
+ String[] examinedConfParams = {
+ Config.TOPOLOGY_NAME,
+ Config.TOPOLOGY_SCHEDULER_STRATEGY,
+ Config.TOPOLOGY_PRIORITY,
+ Config.TOPOLOGY_WORKERS,
+ Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB,
+ Config.TOPOLOGY_SUBMITTER_USER,
+ Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT,
+ Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB,
+ Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB,
+ };
+
+ for (String nm : codeResourceMap.keySet()) {
+ String codeResource = codeResourceMap.get(nm);
+ if (!confResourceMap.containsKey(nm)) {
+ String err = String.format("Ignoring topology file %s because of missing config file for %s", codeResource, nm);
+ errors.add(err);
+ LOG.error(err);
+ continue;
+ }
+ String confResource = confResourceMap.get(nm);
+ LOG.info("Found matching topology and config files: {}, {}", codeResource, confResource);
+ StormTopology stormTopology;
+ try {
+ stormTopology = Utils.deserialize(getResourceAsBytes(codeResource), StormTopology.class);
+ } catch (Exception ex) {
+ String err = String.format("Cannot read topology from resource %s", codeResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+
+ Map<String, Object> conf;
+ try {
+ conf = Utils.fromCompressedJsonConf(getResourceAsBytes(confResource));
+ } catch (RuntimeException | IOException ex) {
+ String err = String.format("Cannot read configuration from resource %s", confResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+ // fix 0.10 conf class names
+ String[] configParamsToFix = {Config.TOPOLOGY_SCHEDULER_STRATEGY, Config.STORM_NETWORK_TOPOGRAPHY_PLUGIN,
+ DaemonConfig.RESOURCE_AWARE_SCHEDULER_PRIORITY_STRATEGY };
+ for (String configParam: configParamsToFix) {
+ if (!conf.containsKey(configParam)) {
+ continue;
+ }
+ String className = (String) conf.get(configParam);
+ if (className.startsWith("backtype")) {
+ className = className.replace("backtype", "org.apache");
+ conf.put(configParam, className);
+ }
+ }
+ // fix conf params used by ConstraintSolverStrategy
+ if (!conf.containsKey(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH)) {
+ conf.put(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH, 10_000);
+ }
+ if (!conf.containsKey(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH)) {
+ conf.put(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH, 10_000);
+ }
+
+ String topoId = nm;
+ String topoName = (String) conf.getOrDefault(Config.TOPOLOGY_NAME, nm);
+
+ // conf
+ StringBuffer sb = new StringBuffer("Config for " + nm + ": ");
+ for (String param : examinedConfParams) {
+ Object val = conf.getOrDefault(param, "<null>");
+ sb.append(param).append("=").append(val).append(", ");
+ }
+ LOG.info(sb.toString());
+
+ // topo
+ Map<ExecutorDetails, String> execToComp = TestUtilsForResourceAwareScheduler.genExecsAndComps(stormTopology);
+ LOG.info("Topology \"{}\" spouts={}, bolts={}, execToComp size is {}", topoName,
+ stormTopology.get_spouts_size(), stormTopology.get_bolts_size(), execToComp.size());
+ int numWorkers = Integer.parseInt("" + conf.getOrDefault(Config.TOPOLOGY_WORKERS, "0"));
+ TopologyDetails topo = new TopologyDetails(topoId, conf, stormTopology, numWorkers,
+ execToComp, Time.currentTimeSecs(), "user");
+ topo.getComponents(); // sanity check - normally this should not fail
+
+ topoDetailsList.add(topo);
+ }
+ if (!errors.isEmpty() && failOnParseError) {
+ throw new Exception("Unable to parse all serialized objects\n\t" + String.join("\n\t", errors));
+ }
+ return topoDetailsList.toArray(new TopologyDetails[0]);
+ }
+
+ /**
+ * Check if the files in the resource directory are matched, can be read properly, and code/config files occur
+ * in matched pairs.
+ *
+ * @throws Exception showing bad and unmatched resource files.
+ */
+ @Test
+ public void testReadSerializedTopologiesAndConfigs() throws Exception {
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Assert.assertTrue("No resource files found in " + TEST_RESOURCE_PATH, !resources.isEmpty());
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(true);
+ }
+
+ /**
+ * Create one supervisor and add to the supervisors list.
+ *
+ * @param rack rack-number
+ * @param superInRack supervisor number in the rack
+ * @param cpu percentage
+ * @param mem in megabytes
+ * @param numPorts number of ports on this supervisor
+ * @param sups returned map os supervisors
+ */
+ private static void createAndAddOneSupervisor(
+ int rack, int superInRack, double cpu, double mem, int numPorts,
+ Map<String, SupervisorDetails> sups) {
+
+ List<Number> ports = new LinkedList<>();
+ for (int p = 0; p < numPorts; p++) {
+ ports.add(p);
+ }
+ String superId = String.format("r%03ds%03d", rack, superInRack);
+ String hostId = String.format("host-%03d-rack-%03d", superInRack, rack);
+ Map<String, Double> resourceMap = new HashMap<>();
+ resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, cpu);
+ resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, mem);
+ resourceMap.put("network.resource.units", 50.0);
+ SupervisorDetails sup = new SupervisorDetails(superId,
+ hostId, null, ports,
+ NormalizedResources.RESOURCE_NAME_NORMALIZER.normalizedResourceMap(resourceMap));
+ sups.put(sup.getId(), sup);
+ }
+
+ /**
+ * Create supervisors.
+ *
+ * @param uniformSupervisors true if all supervisors are of the same size, false otherwise.
+ * @return supervisor details indexed by id
+ */
+ private static Map<String, SupervisorDetails> createSupervisors(boolean uniformSupervisors) {
+ Map<String, SupervisorDetails> retVal;
+ if (uniformSupervisors) {
+ int numRacks = 16;
+ int numSupersPerRack = 82;
+ int numPorts = 50; // scheduling will fill up 2-6, leaving of 90% workerslots unused - does this cause slow scheduling?
+ int rackStart = 0;
+ int superInRackStart = 1;
+ double cpu = 7200; // %percent
+ double mem = 356_000; // MB
+ Map<String, Double> miscResources = new HashMap<>();
+ miscResources.put("network.resource.units", 100.0);
+
+ return TestUtilsForResourceAwareScheduler.genSupervisorsWithRacks(
+ numRacks, numSupersPerRack, numPorts, rackStart, superInRackStart, cpu, mem, miscResources);
+
+ } else {
+ // this non-uniform supervisor distribution closelt (but not exactly) mimics IridiumBlue cluster
+ int numSupersPerRack = 82;
+ int numPorts = 50;
+
+ Map<String, SupervisorDetails> retList = new HashMap<>();
+
+ for (int rack = 0 ; rack < 12 ; rack++) {
+ double cpu = 3600; // %percent
+ double mem = 178_000; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ for (int rack = 12 ; rack < 14 ; rack++) {
+ double cpu = 2400; // %percent
+ double mem = 118_100; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ for (int rack = 14 ; rack < 16 ; rack++) {
+ double cpu = 1200; // %percent
+ double mem = 42_480; // MB
+ for (int superInRack = 0; superInRack < numSupersPerRack ; superInRack++) {
+ createAndAddOneSupervisor(rack, superInRack, cpu - 100 * (superInRack % 2), mem, numPorts, retList);
+ }
+ }
+ return retList;
+ }
+ }
+
+ /**
+ * Create a large cluster, read topologies and configuration from resource directory and schedule.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testLargeCluster() throws Exception {
+ boolean uniformSupervisors = false; // false means non-uniform supervisor distribution
+
+ Map<String, SupervisorDetails> supervisors = createSupervisors(uniformSupervisors);
+
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(false);
+ Assert.assertTrue("No topologies found", topoDetailsArray.length > 0);
+ Topologies topologies = new Topologies(topoDetailsArray);
+
+ Config confWithDefaultStrategy = new Config();
+ confWithDefaultStrategy.putAll(topoDetailsArray[0].getConf());
+ confWithDefaultStrategy.put(Config.TOPOLOGY_SCHEDULER_STRATEGY, DefaultResourceAwareStrategy.class.getName());
+
+ INimbus iNimbus = new INimbusTest();
+ Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supervisors, new HashMap<>(),
+ topologies, confWithDefaultStrategy);
+
+ scheduler = new ResourceAwareScheduler();
+
+ List<Class> classesToDebug = Arrays.asList(DefaultResourceAwareStrategy.class,
+ GenericResourceAwareStrategy.class, ResourceAwareScheduler.class,
+ Cluster.class // count calls to calculateSharedOffHeapNodeMemory()
Review comment:
What does the comment mean here?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406455030
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
+ codeResourceMap.put(nm, resource);
+ } else if (resource.endsWith("conf.ser")) {
+ confResourceMap.put(nm, resource);
+ } else {
+ LOG.info("Ignoring unsupported resource file " + resource);
+ }
+ }
+ String[] examinedConfParams = {
+ Config.TOPOLOGY_NAME,
+ Config.TOPOLOGY_SCHEDULER_STRATEGY,
+ Config.TOPOLOGY_PRIORITY,
+ Config.TOPOLOGY_WORKERS,
+ Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB,
+ Config.TOPOLOGY_SUBMITTER_USER,
+ Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT,
+ Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB,
+ Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB,
+ };
+
+ for (String nm : codeResourceMap.keySet()) {
+ String codeResource = codeResourceMap.get(nm);
+ if (!confResourceMap.containsKey(nm)) {
+ String err = String.format("Ignoring topology file %s because of missing config file for %s", codeResource, nm);
+ errors.add(err);
+ LOG.error(err);
+ continue;
+ }
+ String confResource = confResourceMap.get(nm);
+ LOG.info("Found matching topology and config files: {}, {}", codeResource, confResource);
+ StormTopology stormTopology;
+ try {
+ stormTopology = Utils.deserialize(getResourceAsBytes(codeResource), StormTopology.class);
+ } catch (Exception ex) {
+ String err = String.format("Cannot read topology from resource %s", codeResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+
+ Map<String, Object> conf;
+ try {
+ conf = Utils.fromCompressedJsonConf(getResourceAsBytes(confResource));
+ } catch (RuntimeException | IOException ex) {
+ String err = String.format("Cannot read configuration from resource %s", confResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+ // fix 0.10 conf class names
+ String[] configParamsToFix = {Config.TOPOLOGY_SCHEDULER_STRATEGY, Config.STORM_NETWORK_TOPOGRAPHY_PLUGIN,
+ DaemonConfig.RESOURCE_AWARE_SCHEDULER_PRIORITY_STRATEGY };
+ for (String configParam: configParamsToFix) {
+ if (!conf.containsKey(configParam)) {
+ continue;
+ }
+ String className = (String) conf.get(configParam);
+ if (className.startsWith("backtype")) {
+ className = className.replace("backtype", "org.apache");
+ conf.put(configParam, className);
+ }
+ }
+ // fix conf params used by ConstraintSolverStrategy
+ if (!conf.containsKey(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH)) {
+ conf.put(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH, 10_000);
+ }
+ if (!conf.containsKey(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH)) {
+ conf.put(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH, 10_000);
+ }
+
+ String topoId = nm;
+ String topoName = (String) conf.getOrDefault(Config.TOPOLOGY_NAME, nm);
+
+ // conf
+ StringBuffer sb = new StringBuffer("Config for " + nm + ": ");
+ for (String param : examinedConfParams) {
+ Object val = conf.getOrDefault(param, "<null>");
+ sb.append(param).append("=").append(val).append(", ");
+ }
+ LOG.info(sb.toString());
+
+ // topo
+ Map<ExecutorDetails, String> execToComp = TestUtilsForResourceAwareScheduler.genExecsAndComps(stormTopology);
+ LOG.info("Topology \"{}\" spouts={}, bolts={}, execToComp size is {}", topoName,
+ stormTopology.get_spouts_size(), stormTopology.get_bolts_size(), execToComp.size());
+ int numWorkers = Integer.parseInt("" + conf.getOrDefault(Config.TOPOLOGY_WORKERS, "0"));
+ TopologyDetails topo = new TopologyDetails(topoId, conf, stormTopology, numWorkers,
+ execToComp, Time.currentTimeSecs(), "user");
+ topo.getComponents(); // sanity check - normally this should not fail
+
+ topoDetailsList.add(topo);
+ }
+ if (!errors.isEmpty() && failOnParseError) {
+ throw new Exception("Unable to parse all serialized objects\n\t" + String.join("\n\t", errors));
+ }
+ return topoDetailsList.toArray(new TopologyDetails[0]);
+ }
+
+ /**
+ * Check if the files in the resource directory are matched, can be read properly, and code/config files occur
+ * in matched pairs.
+ *
+ * @throws Exception showing bad and unmatched resource files.
+ */
+ @Test
+ public void testReadSerializedTopologiesAndConfigs() throws Exception {
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Assert.assertTrue("No resource files found in " + TEST_RESOURCE_PATH, !resources.isEmpty());
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(true);
+ }
+
+ /**
+ * Create one supervisor and add to the supervisors list.
+ *
+ * @param rack rack-number
+ * @param superInRack supervisor number in the rack
+ * @param cpu percentage
+ * @param mem in megabytes
+ * @param numPorts number of ports on this supervisor
+ * @param sups returned map os supervisors
+ */
+ private static void createAndAddOneSupervisor(
+ int rack, int superInRack, double cpu, double mem, int numPorts,
+ Map<String, SupervisorDetails> sups) {
+
+ List<Number> ports = new LinkedList<>();
+ for (int p = 0; p < numPorts; p++) {
+ ports.add(p);
+ }
+ String superId = String.format("r%03ds%03d", rack, superInRack);
+ String hostId = String.format("host-%03d-rack-%03d", superInRack, rack);
+ Map<String, Double> resourceMap = new HashMap<>();
+ resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, cpu);
+ resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, mem);
+ resourceMap.put("network.resource.units", 50.0);
+ SupervisorDetails sup = new SupervisorDetails(superId,
+ hostId, null, ports,
+ NormalizedResources.RESOURCE_NAME_NORMALIZER.normalizedResourceMap(resourceMap));
+ sups.put(sup.getId(), sup);
+ }
+
+ /**
+ * Create supervisors.
+ *
+ * @param uniformSupervisors true if all supervisors are of the same size, false otherwise.
+ * @return supervisor details indexed by id
+ */
+ private static Map<String, SupervisorDetails> createSupervisors(boolean uniformSupervisors) {
+ Map<String, SupervisorDetails> retVal;
+ if (uniformSupervisors) {
+ int numRacks = 16;
+ int numSupersPerRack = 82;
+ int numPorts = 50; // scheduling will fill up 2-6, leaving of 90% workerslots unused - does this cause slow scheduling?
Review comment:
What does the comment mean? Or can it be removed?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] bipinprasad commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406482742
##########
File path: storm-server/src/main/java/org/apache/storm/scheduler/Cluster.java
##########
@@ -749,12 +792,16 @@ private double calculateSharedOffHeapNodeMemory(
*/
public void freeSlot(WorkerSlot slot) {
// remove the slot from the existing assignments
+ String nodeId = slot.getNodeId();
Review comment:
changed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406455496
##########
File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
##########
@@ -0,0 +1,458 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+ private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+ public static final String TEST_CLUSTER_NAME = "largeCluster01";
+ public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+ private static IScheduler scheduler = null;
+
+ @AfterEach
+ public void cleanup() {
+ if (scheduler != null) {
+ scheduler.cleanup();
+ scheduler = null;
+ }
+ }
+
+ /**
+ * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+ * resource files in the path. The resources are sorted so that paired topology and conf
+ * files are sequential. Unpaired files may be ignored by the caller.
+ *
+ * @param path directory in which resources exist.
+ * @return
+ * @throws IOException
+ */
+ public static List<String> getResourceFiles(String path) throws IOException {
+ List<String> fileNames = new ArrayList<>();
+
+ try (
+ InputStream in = getResourceAsStream(path);
+ BufferedReader br = new BufferedReader(new InputStreamReader(in))
+ ) {
+ String resource;
+
+ while ((resource = br.readLine()) != null) {
+ if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+ fileNames.add(path + "/" + resource);
+ }
+ }
+ Collections.sort(fileNames);
+ }
+ return fileNames;
+ }
+
+ /**
+ * InputStream to read the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ */
+ public static InputStream getResourceAsStream(String resource) {
+ final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+ }
+
+ /**
+ * Read the contents of the fully qualified resource path.
+ *
+ * @param resource
+ * @return
+ * @throws Exception
+ */
+ public static byte[] getResourceAsBytes(String resource) throws Exception {
+ InputStream in = getResourceAsStream(resource);
+ if (in == null) {
+ return null;
+ }
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ while (in.available() > 0) {
+ out.write(in.read());
+ }
+ return out.toByteArray();
+ }
+ }
+
+ public static ClassLoader getContextClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Create an array of TopologyDetails by reading serialized files for topology and configuration in the
+ * resource path.
+ *
+ * @param failOnParseError throw exception if there are unmatched files, otherwise ignore unmatched and read errors.
+ * @return An array of TopologyDetails representing resource files.
+ * @throws Exception
+ */
+ public static TopologyDetails[] createTopoDetailsArray(boolean failOnParseError) throws Exception {
+ List<TopologyDetails> topoDetailsList = new ArrayList<>();
+ List<String> errors = new ArrayList<>();
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Map<String, String> codeResourceMap = new TreeMap<>();
+ Map<String, String> confResourceMap = new HashMap<>();
+ for (int i = 0 ; i < resources.size() ; i++) {
+ String resource = resources.get(i);
+ int idxOfSlash = resource.lastIndexOf("/");
+ int idxOfDash = resource.lastIndexOf("-");
+ String nm = idxOfDash > idxOfSlash ? resource.substring(idxOfSlash + 1, idxOfDash) : resource.substring(idxOfSlash + 1, resource.length() - 7);
+ if (resource.endsWith("code.ser")) {
+ codeResourceMap.put(nm, resource);
+ } else if (resource.endsWith("conf.ser")) {
+ confResourceMap.put(nm, resource);
+ } else {
+ LOG.info("Ignoring unsupported resource file " + resource);
+ }
+ }
+ String[] examinedConfParams = {
+ Config.TOPOLOGY_NAME,
+ Config.TOPOLOGY_SCHEDULER_STRATEGY,
+ Config.TOPOLOGY_PRIORITY,
+ Config.TOPOLOGY_WORKERS,
+ Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB,
+ Config.TOPOLOGY_SUBMITTER_USER,
+ Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT,
+ Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB,
+ Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB,
+ };
+
+ for (String nm : codeResourceMap.keySet()) {
+ String codeResource = codeResourceMap.get(nm);
+ if (!confResourceMap.containsKey(nm)) {
+ String err = String.format("Ignoring topology file %s because of missing config file for %s", codeResource, nm);
+ errors.add(err);
+ LOG.error(err);
+ continue;
+ }
+ String confResource = confResourceMap.get(nm);
+ LOG.info("Found matching topology and config files: {}, {}", codeResource, confResource);
+ StormTopology stormTopology;
+ try {
+ stormTopology = Utils.deserialize(getResourceAsBytes(codeResource), StormTopology.class);
+ } catch (Exception ex) {
+ String err = String.format("Cannot read topology from resource %s", codeResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+
+ Map<String, Object> conf;
+ try {
+ conf = Utils.fromCompressedJsonConf(getResourceAsBytes(confResource));
+ } catch (RuntimeException | IOException ex) {
+ String err = String.format("Cannot read configuration from resource %s", confResource);
+ errors.add(err);
+ LOG.error(err, ex);
+ continue;
+ }
+ // fix 0.10 conf class names
+ String[] configParamsToFix = {Config.TOPOLOGY_SCHEDULER_STRATEGY, Config.STORM_NETWORK_TOPOGRAPHY_PLUGIN,
+ DaemonConfig.RESOURCE_AWARE_SCHEDULER_PRIORITY_STRATEGY };
+ for (String configParam: configParamsToFix) {
+ if (!conf.containsKey(configParam)) {
+ continue;
+ }
+ String className = (String) conf.get(configParam);
+ if (className.startsWith("backtype")) {
+ className = className.replace("backtype", "org.apache");
+ conf.put(configParam, className);
+ }
+ }
+ // fix conf params used by ConstraintSolverStrategy
+ if (!conf.containsKey(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH)) {
+ conf.put(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH, 10_000);
+ }
+ if (!conf.containsKey(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH)) {
+ conf.put(Config.TOPOLOGY_RAS_CONSTRAINT_MAX_STATE_SEARCH, 10_000);
+ }
+
+ String topoId = nm;
+ String topoName = (String) conf.getOrDefault(Config.TOPOLOGY_NAME, nm);
+
+ // conf
+ StringBuffer sb = new StringBuffer("Config for " + nm + ": ");
+ for (String param : examinedConfParams) {
+ Object val = conf.getOrDefault(param, "<null>");
+ sb.append(param).append("=").append(val).append(", ");
+ }
+ LOG.info(sb.toString());
+
+ // topo
+ Map<ExecutorDetails, String> execToComp = TestUtilsForResourceAwareScheduler.genExecsAndComps(stormTopology);
+ LOG.info("Topology \"{}\" spouts={}, bolts={}, execToComp size is {}", topoName,
+ stormTopology.get_spouts_size(), stormTopology.get_bolts_size(), execToComp.size());
+ int numWorkers = Integer.parseInt("" + conf.getOrDefault(Config.TOPOLOGY_WORKERS, "0"));
+ TopologyDetails topo = new TopologyDetails(topoId, conf, stormTopology, numWorkers,
+ execToComp, Time.currentTimeSecs(), "user");
+ topo.getComponents(); // sanity check - normally this should not fail
+
+ topoDetailsList.add(topo);
+ }
+ if (!errors.isEmpty() && failOnParseError) {
+ throw new Exception("Unable to parse all serialized objects\n\t" + String.join("\n\t", errors));
+ }
+ return topoDetailsList.toArray(new TopologyDetails[0]);
+ }
+
+ /**
+ * Check if the files in the resource directory are matched, can be read properly, and code/config files occur
+ * in matched pairs.
+ *
+ * @throws Exception showing bad and unmatched resource files.
+ */
+ @Test
+ public void testReadSerializedTopologiesAndConfigs() throws Exception {
+ List<String> resources = getResourceFiles(TEST_RESOURCE_PATH);
+ Assert.assertTrue("No resource files found in " + TEST_RESOURCE_PATH, !resources.isEmpty());
+ TopologyDetails[] topoDetailsArray = createTopoDetailsArray(true);
+ }
+
+ /**
+ * Create one supervisor and add to the supervisors list.
+ *
+ * @param rack rack-number
+ * @param superInRack supervisor number in the rack
+ * @param cpu percentage
+ * @param mem in megabytes
+ * @param numPorts number of ports on this supervisor
+ * @param sups returned map os supervisors
+ */
+ private static void createAndAddOneSupervisor(
+ int rack, int superInRack, double cpu, double mem, int numPorts,
+ Map<String, SupervisorDetails> sups) {
+
+ List<Number> ports = new LinkedList<>();
+ for (int p = 0; p < numPorts; p++) {
+ ports.add(p);
+ }
+ String superId = String.format("r%03ds%03d", rack, superInRack);
+ String hostId = String.format("host-%03d-rack-%03d", superInRack, rack);
+ Map<String, Double> resourceMap = new HashMap<>();
+ resourceMap.put(Config.SUPERVISOR_CPU_CAPACITY, cpu);
+ resourceMap.put(Config.SUPERVISOR_MEMORY_CAPACITY_MB, mem);
+ resourceMap.put("network.resource.units", 50.0);
+ SupervisorDetails sup = new SupervisorDetails(superId,
+ hostId, null, ports,
+ NormalizedResources.RESOURCE_NAME_NORMALIZER.normalizedResourceMap(resourceMap));
+ sups.put(sup.getId(), sup);
+ }
+
+ /**
+ * Create supervisors.
+ *
+ * @param uniformSupervisors true if all supervisors are of the same size, false otherwise.
+ * @return supervisor details indexed by id
+ */
+ private static Map<String, SupervisorDetails> createSupervisors(boolean uniformSupervisors) {
+ Map<String, SupervisorDetails> retVal;
+ if (uniformSupervisors) {
+ int numRacks = 16;
+ int numSupersPerRack = 82;
+ int numPorts = 50; // scheduling will fill up 2-6, leaving of 90% workerslots unused - does this cause slow scheduling?
+ int rackStart = 0;
+ int superInRackStart = 1;
+ double cpu = 7200; // %percent
+ double mem = 356_000; // MB
+ Map<String, Double> miscResources = new HashMap<>();
+ miscResources.put("network.resource.units", 100.0);
+
+ return TestUtilsForResourceAwareScheduler.genSupervisorsWithRacks(
+ numRacks, numSupersPerRack, numPorts, rackStart, superInRackStart, cpu, mem, miscResources);
+
+ } else {
+ // this non-uniform supervisor distribution closelt (but not exactly) mimics IridiumBlue cluster
Review comment:
`IridiumBlue` doesn't mean anything in the community code. Maybe reword it.
Typo: `closelt`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] bipinprasad commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
bipinprasad commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406518586
##########
File path: storm-server/src/main/java/org/apache/storm/scheduler/Cluster.java
##########
@@ -709,6 +720,33 @@ public void assign(SchedulerAssignment assignment, boolean ignoreSingleException
}
}
+ /**
+ * Initialize the flag to true if specified topology uses SharedOffHeapNodeMemory, false otherwise.
+ *
+ * @param td TopologyDetails to examine
+ */
+ private void initializeTopoSharedOffHeapNodeMemoryFlag(TopologyDetails td) {
+ String topoId = td.getId();
+ topoSharedOffHeapMemoryNodeFlag.put(topoId, false);
+ StormTopology topology = td.getTopology();
+ if (topology == null) {
+ return; // accomodate multitenant_scheduler_test.clj
+ }
+ if (topology.is_set_component_to_shared_memory()) {
Review comment:
Thanks for explanation. Looks like TopologyBuilder.createTopology() makes the only to call to set_component_to_shared_memory() and set_shared_memory() and thus ensuring this consistency.
Changed code.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [storm] Ethanlm commented on a change in pull request #3244:
[STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
Posted by GitBox <gi...@apache.org>.
Ethanlm commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r406508374
##########
File path: storm-server/src/main/java/org/apache/storm/scheduler/Cluster.java
##########
@@ -709,6 +720,33 @@ public void assign(SchedulerAssignment assignment, boolean ignoreSingleException
}
}
+ /**
+ * Initialize the flag to true if specified topology uses SharedOffHeapNodeMemory, false otherwise.
+ *
+ * @param td TopologyDetails to examine
+ */
+ private void initializeTopoSharedOffHeapNodeMemoryFlag(TopologyDetails td) {
+ String topoId = td.getId();
+ topoSharedOffHeapMemoryNodeFlag.put(topoId, false);
+ StormTopology topology = td.getTopology();
+ if (topology == null) {
+ return; // accomodate multitenant_scheduler_test.clj
+ }
+ if (topology.is_set_component_to_shared_memory()) {
Review comment:
I agree with (1). Sorry I didn't copy that part of the code.
(2)
These two fields are equivalent.
There is a 1-to-1 mapping between `SharedMemory name` to `SharedMemory object`.
shared_memory and component_to_shared_memory are different structures to keep `SharedMemory object` but they essentially keep the whole mapping of `SharedMemory name` to `SharedMemory object`
https://github.com/apache/storm/blob/master/storm-client/src/jvm/org/apache/storm/topology/TopologyBuilder.java#L631-L638
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services