Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STORM-3042 fix acker and metric component resource requests #2645

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -144,11 +144,11 @@
import org.apache.storm.metric.api.DataPoint;
import org.apache.storm.metric.api.IClusterMetricsConsumer;
import org.apache.storm.metric.api.IClusterMetricsConsumer.ClusterInfo;
import org.apache.storm.nimbus.AssignmentDistributionService;
import org.apache.storm.metricstore.AggLevel;
import org.apache.storm.metricstore.Metric;
import org.apache.storm.metricstore.MetricStore;
import org.apache.storm.metricstore.MetricStoreConfig;
import org.apache.storm.nimbus.AssignmentDistributionService;
import org.apache.storm.nimbus.DefaultTopologyValidator;
import org.apache.storm.nimbus.ILeaderElector;
import org.apache.storm.nimbus.ITopologyActionNotifierPlugin;
Expand Down Expand Up @@ -1022,7 +1022,7 @@ private static void setResourcesDefaultIfNotSet(Map<String, NormalizedResourceRe
Map<String, Object> topoConf) {
NormalizedResourceRequest resources = compResourcesMap.get(compId);
if (resources == null) {
compResourcesMap.put(compId, new NormalizedResourceRequest(topoConf));
compResourcesMap.put(compId, new NormalizedResourceRequest(topoConf, compId));
}
}

Expand Down Expand Up @@ -4190,13 +4190,13 @@ public ComponentPageInfo getComponentPageInfo(String topoId, String componentId,
if (compPageInfo.get_component_type() == ComponentType.SPOUT) {
NormalizedResourceRequest spoutResources = ResourceUtils.getSpoutResources(topology, topoConf, componentId);
if (spoutResources == null) {
spoutResources = new NormalizedResourceRequest(topoConf);
spoutResources = new NormalizedResourceRequest(topoConf, componentId);
}
compPageInfo.set_resources_map(spoutResources.toNormalizedMap());
} else { //bolt
NormalizedResourceRequest boltResources = ResourceUtils.getBoltResources(topology, topoConf, componentId);
if (boltResources == null) {
boltResources = new NormalizedResourceRequest(topoConf);
boltResources = new NormalizedResourceRequest(topoConf, componentId);
}
compPageInfo.set_resources_map(boltResources.toNormalizedMap());
}
Expand Down
Expand Up @@ -136,7 +136,8 @@ private void initResourceList() {
if (topology.get_bolts() != null) {
for (Map.Entry<String, Bolt> bolt : topology.get_bolts().entrySet()) {
//the json_conf is populated by TopologyBuilder (e.g. boltDeclarer.setMemoryLoad)
NormalizedResourceRequest topologyResources = new NormalizedResourceRequest(bolt.getValue().get_common(), topologyConf);
NormalizedResourceRequest topologyResources =
new NormalizedResourceRequest(bolt.getValue().get_common(), topologyConf, bolt.getKey());
for (Map.Entry<ExecutorDetails, String> anExecutorToComponent :
executorToComponent.entrySet()) {
if (bolt.getKey().equals(anExecutorToComponent.getValue())) {
Expand All @@ -148,7 +149,8 @@ private void initResourceList() {
// Extract spout resource info
if (topology.get_spouts() != null) {
for (Map.Entry<String, SpoutSpec> spout : topology.get_spouts().entrySet()) {
NormalizedResourceRequest topologyResources = new NormalizedResourceRequest(spout.getValue().get_common(), topologyConf);
NormalizedResourceRequest topologyResources =
new NormalizedResourceRequest(spout.getValue().get_common(), topologyConf, spout.getKey());
for (Map.Entry<ExecutorDetails, String> anExecutorToComponent :
executorToComponent.entrySet()) {
if (spout.getKey().equals(anExecutorToComponent.getValue())) {
Expand All @@ -168,8 +170,7 @@ private void initResourceList() {
getExecutorToComponent().get(exec),
exec,
topologyConf.get(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB),
resourceList.get(exec)
);
resourceList.get(exec));
addDefaultResforExec(exec);
}
}
Expand Down Expand Up @@ -461,41 +462,8 @@ public void addResourcesForExec(ExecutorDetails exec, NormalizedResourceRequest
* Add default resource requirements for a executor.
*/
private void addDefaultResforExec(ExecutorDetails exec) {
addResourcesForExec(exec, new NormalizedResourceRequest(topologyConf));
}

/**
* Some components might have different resource configs.
*/
private void adjustResourcesForExec(ExecutorDetails exec, Map<String, Double> resourceListForExec) {
String component = getExecutorToComponent().get(exec);
if (component.equals(Acker.ACKER_COMPONENT_ID)) {
if (topologyConf.containsKey(Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB)) {
resourceListForExec.put(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB,
ObjectReader.getDouble(topologyConf.get(Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB)));
}
if (topologyConf.containsKey(Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB)) {
resourceListForExec.put(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB,
ObjectReader.getDouble(topologyConf.get(Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB)));
}
if (topologyConf.containsKey(Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT)) {
resourceListForExec.put(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT,
ObjectReader.getDouble(topologyConf.get(Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT)));
}
} else if (component.startsWith(Constants.METRICS_COMPONENT_ID_PREFIX)) {
if (topologyConf.containsKey(Config.TOPOLOGY_METRICS_CONSUMER_RESOURCES_ONHEAP_MEMORY_MB)) {
resourceListForExec.put(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB,
ObjectReader.getDouble(topologyConf.get(Config.TOPOLOGY_METRICS_CONSUMER_RESOURCES_ONHEAP_MEMORY_MB)));
}
if (topologyConf.containsKey(Config.TOPOLOGY_METRICS_CONSUMER_RESOURCES_OFFHEAP_MEMORY_MB)) {
resourceListForExec.put(Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB,
ObjectReader.getDouble(topologyConf.get(Config.TOPOLOGY_METRICS_CONSUMER_RESOURCES_OFFHEAP_MEMORY_MB)));
}
if (topologyConf.containsKey(Config.TOPOLOGY_METRICS_CONSUMER_CPU_PCORE_PERCENT)) {
resourceListForExec.put(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT,
ObjectReader.getDouble(topologyConf.get(Config.TOPOLOGY_METRICS_CONSUMER_CPU_PCORE_PERCENT)));
}
}
addResourcesForExec(exec, new NormalizedResourceRequest(topologyConf, component));
}

/**
Expand Down
Expand Up @@ -40,7 +40,7 @@ public static NormalizedResourceRequest getBoltResources(StormTopology topology,
String componentId) {
if (topology.get_bolts() != null) {
Bolt bolt = topology.get_bolts().get(componentId);
return new NormalizedResourceRequest(bolt.get_common(), topologyConf);
return new NormalizedResourceRequest(bolt.get_common(), topologyConf, componentId);
}
return null;
}
Expand All @@ -50,7 +50,8 @@ public static Map<String, NormalizedResourceRequest> getBoltsResources(StormTopo
Map<String, NormalizedResourceRequest> boltResources = new HashMap<>();
if (topology.get_bolts() != null) {
for (Map.Entry<String, Bolt> bolt : topology.get_bolts().entrySet()) {
NormalizedResourceRequest topologyResources = new NormalizedResourceRequest(bolt.getValue().get_common(), topologyConf);
NormalizedResourceRequest topologyResources =
new NormalizedResourceRequest(bolt.getValue().get_common(), topologyConf, bolt.getKey());
if (LOG.isTraceEnabled()) {
LOG.trace("Turned {} into {}", bolt.getValue().get_common().get_json_conf(), topologyResources);
}
Expand All @@ -64,7 +65,7 @@ public static NormalizedResourceRequest getSpoutResources(StormTopology topology
String componentId) {
if (topology.get_spouts() != null) {
SpoutSpec spout = topology.get_spouts().get(componentId);
return new NormalizedResourceRequest(spout.get_common(), topologyConf);
return new NormalizedResourceRequest(spout.get_common(), topologyConf, componentId);
}
return null;
}
Expand All @@ -74,7 +75,8 @@ public static Map<String, NormalizedResourceRequest> getSpoutsResources(StormTop
Map<String, NormalizedResourceRequest> spoutResources = new HashMap<>();
if (topology.get_spouts() != null) {
for (Map.Entry<String, SpoutSpec> spout : topology.get_spouts().entrySet()) {
NormalizedResourceRequest topologyResources = new NormalizedResourceRequest(spout.getValue().get_common(), topologyConf);
NormalizedResourceRequest topologyResources =
new NormalizedResourceRequest(spout.getValue().get_common(), topologyConf, spout.getKey());
if (LOG.isTraceEnabled()) {
LOG.trace("Turned {} into {}", spout.getValue().get_common().get_json_conf(), topologyResources);
}
Expand Down
Expand Up @@ -22,6 +22,7 @@
import java.util.Map;
import org.apache.storm.Config;
import org.apache.storm.Constants;
import org.apache.storm.daemon.Acker;
import org.apache.storm.generated.ComponentCommon;
import org.apache.storm.generated.WorkerResources;
import org.apache.storm.utils.ObjectReader;
Expand All @@ -47,12 +48,45 @@ private static void putIfMissing(Map<String, Double> dest, String destKey, Map<S
}
}

private static Map<String, Double> getDefaultResources(Map<String, Object> topoConf) {
Map<String, Double> ret = NormalizedResources.RESOURCE_NAME_NORMALIZER.normalizedResourceMap((Map<String, Number>) topoConf.getOrDefault(
Config.TOPOLOGY_COMPONENT_RESOURCES_MAP, new HashMap<>()));
private static Map<String, Double> getDefaultResources(Map<String, Object> topoConf, String componentId) {
Map<String, Double> ret = NormalizedResources.RESOURCE_NAME_NORMALIZER.normalizedResourceMap((Map<String, Number>)
topoConf.getOrDefault(Config.TOPOLOGY_COMPONENT_RESOURCES_MAP, new HashMap<>()));

// Some components might have different resource configs.
if (componentId != null) {
if (componentId.equals(Acker.ACKER_COMPONENT_ID)) {
if (topoConf.containsKey(Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB)) {
ret.put(Constants.COMMON_ONHEAP_MEMORY_RESOURCE_NAME,
ObjectReader.getDouble(topoConf.get(Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB)));
}
if (topoConf.containsKey(Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB)) {
ret.put(Constants.COMMON_OFFHEAP_MEMORY_RESOURCE_NAME,
ObjectReader.getDouble(topoConf.get(Config.TOPOLOGY_ACKER_RESOURCES_OFFHEAP_MEMORY_MB)));
}
if (topoConf.containsKey(Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT)) {
ret.put(Constants.COMMON_CPU_RESOURCE_NAME,
ObjectReader.getDouble(topoConf.get(Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT)));
}
} else if (componentId.startsWith(Constants.METRICS_COMPONENT_ID_PREFIX)) {
if (topoConf.containsKey(Config.TOPOLOGY_METRICS_CONSUMER_RESOURCES_ONHEAP_MEMORY_MB)) {
ret.put(Constants.COMMON_ONHEAP_MEMORY_RESOURCE_NAME,
ObjectReader.getDouble(topoConf.get(Config.TOPOLOGY_METRICS_CONSUMER_RESOURCES_ONHEAP_MEMORY_MB)));
}
if (topoConf.containsKey(Config.TOPOLOGY_METRICS_CONSUMER_RESOURCES_OFFHEAP_MEMORY_MB)) {
ret.put(Constants.COMMON_OFFHEAP_MEMORY_RESOURCE_NAME,
ObjectReader.getDouble(topoConf.get(Config.TOPOLOGY_METRICS_CONSUMER_RESOURCES_OFFHEAP_MEMORY_MB)));
}
if (topoConf.containsKey(Config.TOPOLOGY_METRICS_CONSUMER_CPU_PCORE_PERCENT)) {
ret.put(Constants.COMMON_CPU_RESOURCE_NAME,
ObjectReader.getDouble(topoConf.get(Config.TOPOLOGY_METRICS_CONSUMER_CPU_PCORE_PERCENT)));
}
}
}

putIfMissing(ret, Constants.COMMON_CPU_RESOURCE_NAME, topoConf, Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT);
putIfMissing(ret, Constants.COMMON_OFFHEAP_MEMORY_RESOURCE_NAME, topoConf, Config.TOPOLOGY_COMPONENT_RESOURCES_OFFHEAP_MEMORY_MB);
putIfMissing(ret, Constants.COMMON_ONHEAP_MEMORY_RESOURCE_NAME, topoConf, Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB);

return ret;
}

Expand Down Expand Up @@ -115,12 +149,12 @@ private NormalizedResourceRequest(Map<String, ? extends Number> resources,
normalizedResources = new NormalizedResources(normalizedResourceMap);
}

public NormalizedResourceRequest(ComponentCommon component, Map<String, Object> topoConf) {
this(parseResources(component.get_json_conf()), getDefaultResources(topoConf));
public NormalizedResourceRequest(ComponentCommon component, Map<String, Object> topoConf, String componentId) {
this(parseResources(component.get_json_conf()), getDefaultResources(topoConf, componentId));
}

public NormalizedResourceRequest(Map<String, Object> topoConf) {
this((Map<String, ? extends Number>) null, getDefaultResources(topoConf));
public NormalizedResourceRequest(Map<String, Object> topoConf, String componentId) {
this((Map<String, ? extends Number>) null, getDefaultResources(topoConf, componentId));
}

public NormalizedResourceRequest() {
Expand Down
@@ -0,0 +1,54 @@
/*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.normalization;

import java.util.HashMap;
import java.util.Map;
import org.apache.storm.Config;
import org.apache.storm.Constants;
import org.apache.storm.daemon.Acker;
import org.junit.Assert;
import org.junit.Test;

public class NormalizedResourceRequestTest {

@Test
public void testAckerCPUSetting() {
Map<String, Object> topoConf = new HashMap<>();
topoConf.put(Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT, 40);
topoConf.put(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT, 50);
NormalizedResourceRequest request = new NormalizedResourceRequest(topoConf, Acker.ACKER_COMPONENT_ID);
Map<String, Double> normalizedMap = request.toNormalizedMap();
Double cpu = normalizedMap.get(Constants.COMMON_CPU_RESOURCE_NAME);
Assert.assertNotNull(cpu);
Assert.assertEquals(40, cpu, 0.001);
}

@Test
public void testNonAckerCPUSetting() {
Map<String, Object> topoConf = new HashMap<>();
topoConf.put(Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT, 40);
topoConf.put(Config.TOPOLOGY_COMPONENT_CPU_PCORE_PERCENT, 50);
NormalizedResourceRequest request = new NormalizedResourceRequest(topoConf, "notAnAckerComponent");
Map<String, Double> normalizedMap = request.toNormalizedMap();
Double cpu = normalizedMap.get(Constants.COMMON_CPU_RESOURCE_NAME);
Assert.assertNotNull(cpu);
Assert.assertEquals(50, cpu, 0.001);
}
}