Skip to content

Commit

Permalink
Info on compressed ordinary object pointers
Browse files Browse the repository at this point in the history
This commit adds to JvmInfo the status of whether or not compressed
ordinary object pointers are enabled. Additionally, logging of the max
heap size and the status of the compressed ordinary object pointers flag
are provided on startup.

Relates #13187, relates elastic/elasticsearch-definitive-guide#455
  • Loading branch information
jasontedor committed Dec 16, 2015
1 parent 709740e commit 9aa41d0
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 6 deletions.
38 changes: 33 additions & 5 deletions core/src/main/java/org/elasticsearch/env/NodeEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@

import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.SegmentInfos;
import org.apache.lucene.store.*;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.Lock;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.store.NativeFSLockFactory;
import org.apache.lucene.store.SimpleFSDirectory;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.cluster.metadata.IndexMetaData;
Expand All @@ -31,18 +36,33 @@
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.store.FsDirectoryService;
import org.elasticsearch.monitor.fs.FsInfo;
import org.elasticsearch.monitor.fs.FsProbe;
import org.elasticsearch.monitor.jvm.JvmInfo;

import java.io.Closeable;
import java.io.IOException;
import java.nio.file.*;
import java.util.*;
import java.nio.file.AtomicMoveNotSupportedException;
import java.nio.file.DirectoryStream;
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -145,7 +165,7 @@ public NodeEnvironment(Settings settings, Environment environment) throws IOExce
for (int dirIndex = 0; dirIndex < environment.dataWithClusterFiles().length; dirIndex++) {
Path dir = environment.dataWithClusterFiles()[dirIndex].resolve(NODES_FOLDER).resolve(Integer.toString(possibleLockId));
Files.createDirectories(dir);

try (Directory luceneDir = FSDirectory.open(dir, NativeFSLockFactory.INSTANCE)) {
logger.trace("obtaining node lock on {} ...", dir.toAbsolutePath());
try {
Expand Down Expand Up @@ -187,6 +207,7 @@ public NodeEnvironment(Settings settings, Environment environment) throws IOExce
}

maybeLogPathDetails();
maybeLogHeapDetails();

if (settings.getAsBoolean(SETTING_ENABLE_LUCENE_SEGMENT_INFOS_TRACE, false)) {
SegmentInfos.setInfoStream(System.out);
Expand Down Expand Up @@ -274,6 +295,13 @@ private void maybeLogPathDetails() throws IOException {
}
}

private void maybeLogHeapDetails() {
ByteSizeValue maxHeapSize = JvmInfo.jvmInfo().getMem().getHeapMax();
Boolean usingCompressedOops = JvmInfo.jvmInfo().usingCompressedOops();
String usingCompressedOopsStatus = usingCompressedOops == null ? "unknown" : Boolean.toString(usingCompressedOops);
logger.info("heap size [{}], compressed ordinary object pointers [{}]", maxHeapSize, usingCompressedOopsStatus);
}

private static String toString(Collection<String> items) {
StringBuilder b = new StringBuilder();
for(String item : items) {
Expand Down Expand Up @@ -811,7 +839,7 @@ public static Path shardStatePathToDataPath(Path shardPath) {
// Sanity check:
assert Integer.parseInt(shardPath.getName(count-1).toString()) >= 0;
assert "indices".equals(shardPath.getName(count-3).toString());

return shardPath.getParent().getParent().getParent();
}
}
44 changes: 43 additions & 1 deletion core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@
import org.elasticsearch.common.xcontent.XContentBuilderString;

import java.io.IOException;
import java.lang.management.*;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.ManagementPermission;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.PlatformManagedObject;
import java.lang.management.RuntimeMXBean;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -101,6 +108,21 @@ public class JvmInfo implements Streamable, ToXContent {
info.memoryPools[i] = memoryPoolMXBean.getName();
}

try {
@SuppressWarnings("unchecked") Class<? extends PlatformManagedObject> clazz =
(Class<? extends PlatformManagedObject>)Class.forName("com.sun.management.HotSpotDiagnosticMXBean");
Class<?> vmOptionClazz = Class.forName("com.sun.management.VMOption");
PlatformManagedObject hotSpotDiagnosticMXBean = ManagementFactory.getPlatformMXBean(clazz);
Method vmOptionMethod = clazz.getMethod("getVMOption", String.class);
Object useCompressedOopsVmOption = vmOptionMethod.invoke(hotSpotDiagnosticMXBean, "UseCompressedOops");
Method valueMethod = vmOptionClazz.getMethod("getValue");
String value = (String)valueMethod.invoke(useCompressedOopsVmOption);
info.usingCompressedOops = Boolean.parseBoolean(value);
} catch (Throwable t) {
// unable to deduce the state of compressed oops
// usingCompressedOops will hold its default value of null
}

INSTANCE = info;
}

Expand Down Expand Up @@ -135,6 +157,8 @@ public static JvmInfo jvmInfo() {
String[] gcCollectors = Strings.EMPTY_ARRAY;
String[] memoryPools = Strings.EMPTY_ARRAY;

private Boolean usingCompressedOops;

private JvmInfo() {
}

Expand Down Expand Up @@ -258,6 +282,10 @@ public Map<String, String> getSystemProperties() {
return this.systemProperties;
}

public Boolean usingCompressedOops() {
return this.usingCompressedOops;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(Fields.JVM);
Expand All @@ -279,6 +307,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field(Fields.GC_COLLECTORS, gcCollectors);
builder.field(Fields.MEMORY_POOLS, memoryPools);

builder.field(Fields.USING_COMPRESSED_OOPS, usingCompressedOops == null ? "unknown" : usingCompressedOops);

builder.endObject();
return builder;
}
Expand Down Expand Up @@ -306,6 +336,7 @@ static final class Fields {
static final XContentBuilderString DIRECT_MAX_IN_BYTES = new XContentBuilderString("direct_max_in_bytes");
static final XContentBuilderString GC_COLLECTORS = new XContentBuilderString("gc_collectors");
static final XContentBuilderString MEMORY_POOLS = new XContentBuilderString("memory_pools");
static final XContentBuilderString USING_COMPRESSED_OOPS = new XContentBuilderString("using_compressed_ordinary_object_pointers");
}

public static JvmInfo readJvmInfo(StreamInput in) throws IOException {
Expand Down Expand Up @@ -337,6 +368,11 @@ public void readFrom(StreamInput in) throws IOException {
mem.readFrom(in);
gcCollectors = in.readStringArray();
memoryPools = in.readStringArray();
if (in.readBoolean()) {
usingCompressedOops = in.readBoolean();
} else {
usingCompressedOops = null;
}
}

@Override
Expand All @@ -361,6 +397,12 @@ public void writeTo(StreamOutput out) throws IOException {
mem.writeTo(out);
out.writeStringArray(gcCollectors);
out.writeStringArray(memoryPools);
if (usingCompressedOops != null) {
out.writeBoolean(true);
out.writeBoolean(usingCompressedOops);
} else {
out.writeBoolean(false);
}
}

public static class Mem implements Streamable {
Expand Down

0 comments on commit 9aa41d0

Please sign in to comment.