added setting of cache configuration for solr

according to recommendation from
https://community.searchlab.eu/t/yacy-support-gpt-chatgpt-assistant/1622
However it is not clear if this configuration actually works (has an
effect at all) or is the solution for performance issues.
pull/649/head
Michael Peter Christen 6 months ago
parent b8479430b6
commit 71a6074cc5

@ -26,6 +26,8 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -47,8 +49,10 @@ import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap; import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.PluginInfo;
import org.apache.solr.core.SolrConfig; import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.component.SearchComponent;
import org.apache.solr.handler.component.SearchHandler; import org.apache.solr.handler.component.SearchHandler;
import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryRequestBase; import org.apache.solr.request.SolrQueryRequestBase;
@ -80,7 +84,7 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
private final EmbeddedInstance instance; private final EmbeddedInstance instance;
private final SolrCore core; private final SolrCore core;
public EmbeddedSolrConnector(EmbeddedInstance instance) { public EmbeddedSolrConnector(final EmbeddedInstance instance) {
super(); super();
this.instance = instance; this.instance = instance;
this.core = this.instance.getDefaultCore(); this.core = this.instance.getDefaultCore();
@ -90,10 +94,12 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
//this.suggestHandler = new SuggestComponent(); //this.suggestHandler = new SuggestComponent();
//this.suggestHandler.init(new NamedList<Object>()); //this.suggestHandler.init(new NamedList<Object>());
//this.suggestHandler.inform(this.core); //this.suggestHandler.inform(this.core);
config();
super.init(this.instance.getDefaultServer()); super.init(this.instance.getDefaultServer());
} }
public EmbeddedSolrConnector(EmbeddedInstance instance, String coreName) { public EmbeddedSolrConnector(final EmbeddedInstance instance, final String coreName) {
super(); super();
this.instance = instance; this.instance = instance;
this.core = this.instance.getCore(coreName); this.core = this.instance.getCore(coreName);
@ -103,16 +109,52 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
//this.suggestHandler = new SuggestComponent(); //this.suggestHandler = new SuggestComponent();
//this.suggestHandler.init(new NamedList<Object>()); //this.suggestHandler.init(new NamedList<Object>());
//this.suggestHandler.inform(this.core); //this.suggestHandler.inform(this.core);
config();
super.init(this.instance.getServer(coreName)); super.init(this.instance.getServer(coreName));
} }
private void config() {
// Define cache configuration parameters
final Map<String, Object> cacheConfig = Map.of(
"name", "documentCache",
"class", "solr.LRUCache",
"size", "10240",
"initialSize", "512",
"autowarmCount", "0"
);
// Retrieve the Solr configuration
final SolrConfig solrConfig = this.core.getSolrConfig();
// Get the list of plugin infos for SearchComponent
final List<PluginInfo> pluginInfos = solrConfig.getPluginInfos(SearchComponent.class.getName());
boolean changed = false;
// Iterate over pluginInfos to find and update documentCache
for (final PluginInfo pluginInfo : pluginInfos) {
if (pluginInfo.name.equals("documentCache")) {
pluginInfo.initArgs.addAll(cacheConfig);
changed = true;
}
}
// If documentCache is not found, create and add it
if (!changed) {
final Map<String, String> attrs = new HashMap<>();
final PluginInfo pi = new PluginInfo("documentCache", attrs, new NamedList<>(cacheConfig), null);
pluginInfos.add(pi);
}
// Ensure the changes are applied to Solr configuration if needed
// This part may vary based on how SolrConfig applies updates
}
@Override @Override
public int hashCode() { public int hashCode() {
return this.instance.hashCode(); return this.instance.hashCode();
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(final Object o) {
return o instanceof EmbeddedSolrConnector && this.instance.equals(((EmbeddedSolrConnector) o).instance); return o instanceof EmbeddedSolrConnector && this.instance.equals(((EmbeddedSolrConnector) o).instance);
} }
@ -186,7 +228,7 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
return req; return req;
} }
public SolrQueryResponse query(SolrQueryRequest req) throws SolrException { public SolrQueryResponse query(final SolrQueryRequest req) throws SolrException {
final long startTime = System.currentTimeMillis(); final long startTime = System.currentTimeMillis();
// during the solr query we set the thread name to the query string to get more debugging info in thread dumps // during the solr query we set the thread name to the query string to get more debugging info in thread dumps
@ -266,7 +308,7 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
return sf; return sf;
} }
public SolrDocument doc2SolrDoc(Document doc) { public SolrDocument doc2SolrDoc(final Document doc) {
final SolrDocument solrDoc = new SolrDocument(); final SolrDocument solrDoc = new SolrDocument();
for (final IndexableField field : doc) { for (final IndexableField field : doc) {
final String fieldName = field.name(); final String fieldName = field.name();
@ -312,7 +354,7 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
* Reason: Solr makes a very complex folding/unfolding including data compression for SolrQueryResponses. * Reason: Solr makes a very complex folding/unfolding including data compression for SolrQueryResponses.
*/ */
@Override @Override
public QueryResponse getResponseByParams(ModifiableSolrParams params) throws IOException { public QueryResponse getResponseByParams(final ModifiableSolrParams params) throws IOException {
if (this.server == null) throw new IOException("server disconnected"); if (this.server == null) throw new IOException("server disconnected");
// during the solr query we set the thread name to the query string to get more debugging info in thread dumps // during the solr query we set the thread name to the query string to get more debugging info in thread dumps
final String threadname = Thread.currentThread().getName(); final String threadname = Thread.currentThread().getName();
@ -345,7 +387,7 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
* @throws SolrException * @throws SolrException
*/ */
@Override @Override
public SolrDocumentList getDocumentListByParams(ModifiableSolrParams params) throws IOException, SolrException { public SolrDocumentList getDocumentListByParams(final ModifiableSolrParams params) throws IOException, SolrException {
final SolrQueryRequest req = this.request(params); final SolrQueryRequest req = this.request(params);
SolrQueryResponse response = null; SolrQueryResponse response = null;
final String q = params.get(CommonParams.Q); final String q = params.get(CommonParams.Q);
@ -368,7 +410,7 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
private SolrQueryRequest request; private SolrQueryRequest request;
private DocList response; private DocList response;
public DocListSearcher(final String querystring, String sort, final int offset, final int count, final String ... fields) { public DocListSearcher(final String querystring, final String sort, final int offset, final int count, final String ... fields) {
// construct query // construct query
final SolrQuery params = AbstractSolrConnector.getSolrQuery(querystring, sort, offset, count, fields); final SolrQuery params = AbstractSolrConnector.getSolrQuery(querystring, sort, offset, count, fields);
@ -390,7 +432,7 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
} }
@Override @Override
public long getCountByQuery(String querystring) { public long getCountByQuery(final String querystring) {
long numFound = 0; long numFound = 0;
DocListSearcher docListSearcher = null; DocListSearcher docListSearcher = null;
try { try {
@ -425,7 +467,7 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
* @throws IOException * @throws IOException
*/ */
@Override @Override
public String getURL(String id) throws IOException { public String getURL(final String id) throws IOException {
int responseCount = 0; int responseCount = 0;
DocListSearcher docListSearcher = null; DocListSearcher docListSearcher = null;
try { try {

Loading…
Cancel
Save