YARN-9782. Avoid DNS resolution while running SLS. Contributed by Abhishek Modi.

This commit is contained in:
Abhishek Modi 2019-10-04 14:45:10 +05:30
parent b23bdaf085
commit 2478cbafe6
4 changed files with 70 additions and 1 deletions

View File

@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.security.Security;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -150,6 +151,10 @@ public enum TraceType {
SLS, RUMEN, SYNTH
}
public static final String NETWORK_CACHE_TTL = "networkaddress.cache.ttl";
public static final String NETWORK_NEGATIVE_CACHE_TTL =
"networkaddress.cache.negative.ttl";
private TraceType inputType;
private SynthTraceJobProducer stjp;
@ -241,6 +246,9 @@ public void setSimulationParams(TraceType inType, String[] inTraces,
public void start() throws IOException, ClassNotFoundException, YarnException,
InterruptedException {
enableDNSCaching(getConf());
// start resource manager
startRM();
// start node managers
@ -260,6 +268,23 @@ public void start() throws IOException, ClassNotFoundException, YarnException,
runner.start();
}
/**
* Enables DNS Caching based on config. If DNS caching is enabled, then set
* the DNS cache to infinite time. Since in SLS random nodes are added, DNS
* resolution can take significant time which can cause erroneous results.
* For more details, check <a href=
* "https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html">
* Java Networking Properties</a>
* @param conf Configuration object.
*/
static void enableDNSCaching(Configuration conf) {
if (conf.getBoolean(SLSConfiguration.DNS_CACHING_ENABLED,
SLSConfiguration.DNS_CACHING_ENABLED_DEFAULT)) {
Security.setProperty(NETWORK_CACHE_TTL, "-1");
Security.setProperty(NETWORK_NEGATIVE_CACHE_TTL, "-1");
}
}
private void startRM() throws ClassNotFoundException, YarnException {
Configuration rmConf = new YarnConfiguration(getConf());
String schedulerClass = rmConf.get(YarnConfiguration.RM_SCHEDULER);

View File

@ -28,6 +28,9 @@
public class SLSConfiguration {
// sls
public static final String PREFIX = "yarn.sls.";
public static final String DNS_CACHING_ENABLED = PREFIX
+ "dns.caching.enabled";
public static final boolean DNS_CACHING_ENABLED_DEFAULT = false;
// runner
public static final String RUNNER_PREFIX = PREFIX + "runner.";
public static final String RUNNER_POOL_SIZE = RUNNER_PREFIX + "pool.size";

View File

@ -64,7 +64,9 @@ public abstract class BaseSLSRunnerTest {
@After
public void tearDown() throws InterruptedException {
sls.stop();
if (sls != null) {
sls.stop();
}
}
public void runSLS(Configuration conf, long timeout) throws Exception {

View File

@ -22,14 +22,18 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler;
import org.apache.hadoop.yarn.sls.conf.SLSConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.*;
import java.security.Security;
import java.util.*;
import static org.junit.Assert.assertEquals;
/**
* This test performs simple runs of the SLS with different trace types and
* schedulers.
@ -86,4 +90,39 @@ public void testSimulatorRunning() throws Exception {
runSLS(conf, timeTillShutdownInsec);
}
/**
* Test to check whether caching is enabled based on config.
*/
@Test
public void testEnableCaching() {
String networkCacheDefault = Security.getProperty(
SLSRunner.NETWORK_CACHE_TTL);
String networkNegativeCacheDefault =
Security.getProperty(SLSRunner.NETWORK_NEGATIVE_CACHE_TTL);
try {
Configuration conf = new Configuration(false);
// check when dns caching is disabled
conf.setBoolean(SLSConfiguration.DNS_CACHING_ENABLED, false);
SLSRunner.enableDNSCaching(conf);
assertEquals(networkCacheDefault,
Security.getProperty(SLSRunner.NETWORK_CACHE_TTL));
assertEquals(networkNegativeCacheDefault,
Security.getProperty(SLSRunner.NETWORK_NEGATIVE_CACHE_TTL));
// check when dns caching is enabled
conf.setBoolean(SLSConfiguration.DNS_CACHING_ENABLED, true);
SLSRunner.enableDNSCaching(conf);
assertEquals("-1",
Security.getProperty(SLSRunner.NETWORK_CACHE_TTL));
assertEquals("-1",
Security.getProperty(SLSRunner.NETWORK_NEGATIVE_CACHE_TTL));
} finally {
// set security settings back to default
Security.setProperty(SLSRunner.NETWORK_CACHE_TTL,
String.valueOf(networkCacheDefault));
Security.setProperty(SLSRunner.NETWORK_NEGATIVE_CACHE_TTL,
String.valueOf(networkNegativeCacheDefault));
}
}
}