Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions deploy/adsabs/server/solr/collection1/conf/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@

</requestDispatcher>

<searchComponent name="requestMemoryStart" class="org.adsabs.solr.metrics.memory.RequestMemoryStartComponent"/>
<searchComponent name="requestMemoryEnd" class="org.adsabs.solr.metrics.memory.RequestMemoryEndComponent"/>
<requestHandler name="/select" class="solr.SearchHandler">
<lst name="defaults">
<str name="wt">json</str>
Expand Down Expand Up @@ -344,8 +346,12 @@
<str name="aqp.allow.leading_wildcard">false</str>
<str name="aqp.maxAbsolutePhraseLength">500</str>
</lst>
<arr name="first-components">
<str>requestMemoryStart</str>
</arr>
<arr name="last-components">
<str>wordcloud</str>
<str>requestMemoryEnd</str>
</arr>
</requestHandler>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.adsabs.solr.metrics.memory;

import com.sun.management.ThreadMXBean;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.SearchComponent;

import java.io.IOException;
import java.lang.management.ManagementFactory;

public class RequestMemoryEndComponent extends SearchComponent {
private static final ThreadMXBean THREAD_MX_BEAN =
(ThreadMXBean) ManagementFactory.getThreadMXBean();

@Override
public void prepare(ResponseBuilder rb) throws IOException {
// no-op
}

@Override
public void process(ResponseBuilder rb) throws IOException {
Long startAlloc = (Long) rb.req.getContext().get(RequestMemoryStartComponent.ALLOC_START_KEY);
if (startAlloc == null) return;

long allocated = THREAD_MX_BEAN.getCurrentThreadAllocatedBytes() - startAlloc;
rb.rsp.add("allocatedBytes", allocated);
rb.rsp.addHttpHeader("X-Allocated-Bytes", String.valueOf(allocated));
}

@Override
public String getDescription() {
return "Reports allocation delta at the end of a request.";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.adsabs.solr.metrics.memory;

import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.SearchComponent;

import java.io.IOException;
import java.lang.management.ManagementFactory;
import com.sun.management.ThreadMXBean;

public class RequestMemoryStartComponent extends SearchComponent {
static final String ALLOC_START_KEY = "allocation.tracking.start";
private static final ThreadMXBean THREAD_MX_BEAN =
(ThreadMXBean) ManagementFactory.getThreadMXBean();

static {
THREAD_MX_BEAN.setThreadAllocatedMemoryEnabled(true);
}

@Override
public void prepare(ResponseBuilder rb) throws IOException {
rb.req.getContext().put(ALLOC_START_KEY,
THREAD_MX_BEAN.getCurrentThreadAllocatedBytes());
}

@Override
public void process(ResponseBuilder rb) throws IOException {
// no-op
}

@Override
public String getDescription() {
return "Records allocated bytes at the start of a request.";
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add a comment that describes this line and why it is currently excluded?

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public LeafCollector getLeafCollector(LeafReaderContext context) throws IOExcept

public boolean searcherInitialization(IndexSearcher searcher, Weight firstOrderWeight) throws IOException {
// this is pretty arbitrary, but 2nd order queries may return many hits...
((ArrayList<CollectorDoc>) hits).ensureCapacity((int) (searcher.getIndexReader().maxDoc() * ensureCapacityRatio));
//((ArrayList<CollectorDoc>) hits).ensureCapacity((int) (searcher.getIndexReader().maxDoc() * ensureCapacityRatio));
return true;
}

Expand Down
Loading