Skip to content

Commit

Permalink
Merge pull request Netflix#970 from tcellucci/memory_tuning_pr
Browse files Browse the repository at this point in the history
 memory tuning
  • Loading branch information
tcellucci authored Jul 25, 2017
2 parents 7eb8c40 + 9399571 commit 3677ac7
Show file tree
Hide file tree
Showing 20 changed files with 1,738 additions and 648 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ subprojects {

group = "com.netflix.${githubProjectName}"

sourceCompatibility = 1.7
targetCompatibility = 1.7
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
jcenter()
Expand Down
4 changes: 3 additions & 1 deletion eureka-client/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apply plugin: 'nebula.test-jar'
apply plugin: 'provided-base'
apply plugin: 'nebula.provided-base'

configurations.all {
// jersey2
Expand All @@ -18,6 +18,8 @@ dependencies {
compile "org.apache.httpcomponents:httpclient:${apacheHttpClientVersion}"
compile "com.google.inject:guice:${guiceVersion}"

compile "com.github.vlsi.compactmap:compactmap:1.2.1"

compile "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ public String getIpAddress() {
}

private static Pair<String, String> getHostInfo() {
Pair<String, String> pair = new Pair<String, String>("", "");
Pair<String, String> pair;
try {
pair.setFirst(InetAddress.getLocalHost().getHostAddress());
pair.setSecond(InetAddress.getLocalHost().getHostName());

InetAddress localHost = InetAddress.getLocalHost();
pair = new Pair<String, String>(localHost.getHostAddress(), localHost.getHostName());
} catch (UnknownHostException e) {
logger.error("Cannot get host info", e);
pair = new Pair<String, String>("", "");
}
return pair;
}
Expand Down
13 changes: 10 additions & 3 deletions eureka-client/src/main/java/com/netflix/appinfo/AmazonInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@
* @author Karthik Ranganathan, Greg Kim
*
*/
@JsonDeserialize(builder = StringInterningAmazonInfoBuilder.class)
@JsonDeserialize(using = StringInterningAmazonInfoBuilder.class)
public class AmazonInfo implements DataCenterInfo, UniqueIdentifier {

private Map<String, String> metadata = new HashMap<String, String>();

private static final String AWS_API_VERSION = "latest";
private static final String AWS_METADATA_URL = "http://169.254.169.254/" + AWS_API_VERSION + "/meta-data/";

Expand Down Expand Up @@ -239,7 +237,10 @@ public AmazonInfo autoBuild(String namespace) {
}
}

private Map<String, String> metadata;

public AmazonInfo() {
this.metadata = new HashMap<String, String>();
}

/**
Expand All @@ -254,6 +255,12 @@ public AmazonInfo(
@JsonProperty("metadata") HashMap<String, String> metadata) {
this.metadata = metadata;
}

public AmazonInfo(
@JsonProperty("name") String name,
@JsonProperty("metadata") Map<String, String> metadata) {
this.metadata = metadata;
}

@Override
public Name getName() {
Expand Down
76 changes: 50 additions & 26 deletions eureka-client/src/main/java/com/netflix/appinfo/InstanceInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down Expand Up @@ -56,6 +57,8 @@
@JsonRootName("instance")
public class InstanceInfo {

private static final String VERSION_UNKNOWN = "unknown";

/**
* {@link InstanceInfo} JSON and XML format for port information does not follow the usual conventions, which
* makes its mapping complicated. This class represents the wire format for port information.
Expand Down Expand Up @@ -141,18 +144,21 @@ public int getPort() {
@Auto
private volatile Boolean isCoordinatingDiscoveryServer = Boolean.FALSE;
@XStreamAlias("metadata")
private volatile Map<String, String> metadata = new ConcurrentHashMap<String, String>();
private volatile Map<String, String> metadata;
@Auto
private volatile Long lastUpdatedTimestamp = System.currentTimeMillis();
private volatile Long lastUpdatedTimestamp;
@Auto
private volatile Long lastDirtyTimestamp = System.currentTimeMillis();
private volatile Long lastDirtyTimestamp;
@Auto
private volatile ActionType actionType;
@Auto
private volatile String asgName;
private String version = "unknown";
private String version = VERSION_UNKNOWN;

private InstanceInfo() {
this.metadata = new ConcurrentHashMap<String, String>();
this.lastUpdatedTimestamp = System.currentTimeMillis();
this.lastDirtyTimestamp = lastUpdatedTimestamp;
}

@JsonCreator
Expand Down Expand Up @@ -308,9 +314,12 @@ public enum InstanceStatus {
UNKNOWN;

public static InstanceStatus toEnum(String s) {
for (InstanceStatus e : InstanceStatus.values()) {
if (e.name().equalsIgnoreCase(s)) {
return e;
if (s != null) {
try {
return InstanceStatus.valueOf(s.toUpperCase());
} catch (IllegalArgumentException e) {
// ignore and fall through to unknown
if (logger.isDebugEnabled()) logger.debug("illegal argument supplied to InstanceStatus.valueOf: {}, defaulting to {}", s, UNKNOWN);
}
}
return UNKNOWN;
Expand All @@ -319,10 +328,8 @@ public static InstanceStatus toEnum(String s) {

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
return result;
String id = getId();
return (id == null) ? 31 : (id.hashCode() + 31);
}

@Override
Expand All @@ -337,11 +344,12 @@ public boolean equals(Object obj) {
return false;
}
InstanceInfo other = (InstanceInfo) obj;
if (getId() == null) {
String id = getId();
if (id == null) {
if (other.getId() != null) {
return false;
}
} else if (!getId().equals(other.getId())) {
} else if (!id.equals(other.getId())) {
return false;
}
return true;
Expand All @@ -355,6 +363,7 @@ public static final class Builder {
private static final String COLON = ":";
private static final String HTTPS_PROTOCOL = "https://";
private static final String HTTP_PROTOCOL = "http://";
private final Function<String,String> intern;

private static final class LazyHolder {
private static final VipAddressResolver DEFAULT_VIP_ADDRESS_RESOLVER = new Archaius1VipAddressResolver();
Expand All @@ -368,21 +377,26 @@ private static final class LazyHolder {

private String namespace;

private Builder(InstanceInfo result, VipAddressResolver vipAddressResolver) {
private Builder(InstanceInfo result, VipAddressResolver vipAddressResolver, Function<String,String> intern) {
this.vipAddressResolver = vipAddressResolver;
this.result = result;
this.intern = intern != null ? intern : StringCache::intern;
}

public Builder(InstanceInfo instanceInfo) {
this(instanceInfo, LazyHolder.DEFAULT_VIP_ADDRESS_RESOLVER);
this(instanceInfo, LazyHolder.DEFAULT_VIP_ADDRESS_RESOLVER, null);
}

public static Builder newBuilder() {
return new Builder(new InstanceInfo(), LazyHolder.DEFAULT_VIP_ADDRESS_RESOLVER);
return new Builder(new InstanceInfo(), LazyHolder.DEFAULT_VIP_ADDRESS_RESOLVER, null);
}

public static Builder newBuilder(Function<String,String> intern) {
return new Builder(new InstanceInfo(), LazyHolder.DEFAULT_VIP_ADDRESS_RESOLVER, intern);
}

public static Builder newBuilder(VipAddressResolver vipAddressResolver) {
return new Builder(new InstanceInfo(), vipAddressResolver);
return new Builder(new InstanceInfo(), vipAddressResolver, null);
}

public Builder setInstanceId(String instanceId) {
Expand All @@ -398,18 +412,28 @@ public Builder setInstanceId(String instanceId) {
* @return the instance info builder.
*/
public Builder setAppName(String appName) {
result.appName = StringCache.intern(appName.toUpperCase(Locale.ROOT));
result.appName = intern.apply(appName.toUpperCase(Locale.ROOT));
return this;
}

public Builder setAppNameForDeser(String appName) {
result.appName = appName;
return this;
}


public Builder setAppGroupName(String appGroupName) {
if (appGroupName != null) {
result.appGroupName = appGroupName.toUpperCase(Locale.ROOT);
result.appGroupName = intern.apply(appGroupName.toUpperCase(Locale.ROOT));
} else {
result.appGroupName = null;
}
return this;
}
public Builder setAppGroupNameForDeser(String appGroupName) {
result.appGroupName = appGroupName;
return this;
}

/**
* Sets the fully qualified hostname of this running instance.This is
Expand Down Expand Up @@ -675,8 +699,8 @@ public Builder setHealthCheckUrlsForDeser(String healthCheckUrl, String secureHe
* @return the instance builder.
*/
public Builder setVIPAddress(final String vipAddress) {
result.vipAddressUnresolved = StringCache.intern(vipAddress);
result.vipAddress = StringCache.intern(
result.vipAddressUnresolved = intern.apply(vipAddress);
result.vipAddress = intern.apply(
vipAddressResolver.resolveDeploymentContextBasedVipAddresses(vipAddress));
return this;
}
Expand All @@ -685,7 +709,7 @@ public Builder setVIPAddress(final String vipAddress) {
* Setter used during deserialization process, that does not do macro expansion on the provided value.
*/
public Builder setVIPAddressDeser(String vipAddress) {
result.vipAddress = StringCache.intern(vipAddress);
result.vipAddress = intern.apply(vipAddress);
return this;
}

Expand All @@ -699,8 +723,8 @@ public Builder setVIPAddressDeser(String vipAddress) {
* @return - Builder instance
*/
public Builder setSecureVIPAddress(final String secureVIPAddress) {
result.secureVipAddressUnresolved = StringCache.intern(secureVIPAddress);
result.secureVipAddress = StringCache.intern(
result.secureVipAddressUnresolved = intern.apply(secureVIPAddress);
result.secureVipAddress = intern.apply(
vipAddressResolver.resolveDeploymentContextBasedVipAddresses(secureVIPAddress));
return this;
}
Expand All @@ -709,7 +733,7 @@ public Builder setSecureVIPAddress(final String secureVIPAddress) {
* Setter used during deserialization process, that does not do macro expansion on the provided value.
*/
public Builder setSecureVIPAddressDeser(String secureVIPAddress) {
result.secureVipAddress = StringCache.intern(secureVIPAddress);
result.secureVipAddress = intern.apply(secureVIPAddress);
return this;
}

Expand Down Expand Up @@ -791,7 +815,7 @@ public boolean isInitialized() {
* @return the instance info builder.
*/
public Builder setASGName(String asgName) {
result.asgName = StringCache.intern(asgName);
result.asgName = intern.apply(asgName);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public synchronized void setRegionsToFetch(String[] regionsToFetch) {
for (String remoteRegion : regionsToFetch) {
Set<String> availabilityZones = getZonesForARegion(remoteRegion);
if (null == availabilityZones
|| (availabilityZones.size() == 1 && availabilityZones.iterator().next().equals(DEFAULT_ZONE))
|| (availabilityZones.size() == 1 && availabilityZones.contains(DEFAULT_ZONE))
|| availabilityZones.isEmpty()) {
logger.info("No availability zone information available for remote region: " + remoteRegion
+ ". Now checking in the default mapping.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ public InstanceInfo getNextServerFromEureka(String virtualHostname, boolean secu
+ virtualHostname);
}
Applications apps = this.localRegionApps.get();
int index = (int) (apps.getNextIndex(virtualHostname.toUpperCase(Locale.ROOT),
int index = (int) (apps.getNextIndex(virtualHostname,
secure).incrementAndGet() % instanceInfoList.size());
return instanceInfoList.get(index);
}
Expand Down Expand Up @@ -1135,24 +1135,6 @@ private void reconcileAndLogDifference(Applications delta, String reconcileHashC
return;
}

if (logger.isDebugEnabled()) {
try {
Map<String, List<String>> reconcileDiffMap = getApplications().getReconcileMapDiff(serverApps);
StringBuilder reconcileBuilder = new StringBuilder("");
for (Map.Entry<String, List<String>> mapEntry : reconcileDiffMap.entrySet()) {
reconcileBuilder.append(mapEntry.getKey()).append(": ");
for (String displayString : mapEntry.getValue()) {
reconcileBuilder.append(displayString);
}
reconcileBuilder.append('\n');
}
String reconcileString = reconcileBuilder.toString();
logger.debug("The reconcile string is {}", reconcileString);
} catch (Throwable e) {
logger.error("Could not calculate reconcile string ", e);
}
}

if (fetchRegistryGeneration.compareAndSet(currentUpdateGeneration, currentUpdateGeneration + 1)) {
localRegionApps.set(this.filterAndShuffle(serverApps));
getApplications().setVersion(delta.getVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public TimedSupervisorTask(String name, ScheduledExecutorService scheduler, Thre
Monitors.registerObject(name, this);
}

@Override
public void run() {
Future future = null;
Future<?> future = null;
try {
future = executor.submit(task);
threadPoolLevelGauge.set((long) executor.getActiveCount());
Expand Down
Loading

0 comments on commit 3677ac7

Please sign in to comment.