use of org.apache.solr.util.RTimer in project lucene-solr by apache.
the class ManagedIndexSchema method waitForSchemaZkVersionAgreement.
/**
* Block up to a specified maximum time until we see agreement on the schema
* version in ZooKeeper across all replicas for a collection.
*/
public static void waitForSchemaZkVersionAgreement(String collection, String localCoreNodeName, int schemaZkVersion, ZkController zkController, int maxWaitSecs) {
RTimer timer = new RTimer();
// get a list of active replica cores to query for the schema zk version (skipping this core of course)
List<GetZkSchemaVersionCallable> concurrentTasks = new ArrayList<>();
for (String coreUrl : getActiveReplicaCoreUrls(zkController, collection, localCoreNodeName)) concurrentTasks.add(new GetZkSchemaVersionCallable(coreUrl, schemaZkVersion));
if (concurrentTasks.isEmpty())
// nothing to wait for ...
return;
log.info("Waiting up to " + maxWaitSecs + " secs for " + concurrentTasks.size() + " replicas to apply schema update version " + schemaZkVersion + " for collection " + collection);
// use an executor service to invoke schema zk version requests in parallel with a max wait time
int poolSize = Math.min(concurrentTasks.size(), 10);
ExecutorService parallelExecutor = ExecutorUtil.newMDCAwareFixedThreadPool(poolSize, new DefaultSolrThreadFactory("managedSchemaExecutor"));
try {
List<Future<Integer>> results = parallelExecutor.invokeAll(concurrentTasks, maxWaitSecs, TimeUnit.SECONDS);
// determine whether all replicas have the update
// lazily init'd
List<String> failedList = null;
for (int f = 0; f < results.size(); f++) {
int vers = -1;
Future<Integer> next = results.get(f);
if (next.isDone() && !next.isCancelled()) {
// looks to have finished, but need to check the version value too
try {
vers = next.get();
} catch (ExecutionException e) {
// shouldn't happen since we checked isCancelled
}
}
if (vers == -1) {
String coreUrl = concurrentTasks.get(f).coreUrl;
log.warn("Core " + coreUrl + " version mismatch! Expected " + schemaZkVersion + " but got " + vers);
if (failedList == null)
failedList = new ArrayList<>();
failedList.add(coreUrl);
}
}
// if any tasks haven't completed within the specified timeout, it's an error
if (failedList != null)
throw new SolrException(ErrorCode.SERVER_ERROR, failedList.size() + " out of " + (concurrentTasks.size() + 1) + " replicas failed to update their schema to version " + schemaZkVersion + " within " + maxWaitSecs + " seconds! Failed cores: " + failedList);
} catch (InterruptedException ie) {
log.warn("Core " + localCoreNodeName + " was interrupted waiting for schema version " + schemaZkVersion + " to propagate to " + concurrentTasks.size() + " replicas for collection " + collection);
Thread.currentThread().interrupt();
} finally {
if (!parallelExecutor.isShutdown())
parallelExecutor.shutdown();
}
log.info("Took {}ms for {} replicas to apply schema update version {} for collection {}", timer.getTime(), concurrentTasks.size(), schemaZkVersion, collection);
}
use of org.apache.solr.util.RTimer in project lucene-solr by apache.
the class UpdateLog method seedBucketsWithHighestVersion.
/**
* Used to seed all version buckets with the max value of the version field in the index.
*/
protected Long seedBucketsWithHighestVersion(SolrIndexSearcher newSearcher, VersionInfo versions) {
Long highestVersion = null;
final RTimer timer = new RTimer();
try (RecentUpdates recentUpdates = getRecentUpdates()) {
long maxVersionFromRecent = recentUpdates.getMaxRecentVersion();
long maxVersionFromIndex = versions.getMaxVersionFromIndex(newSearcher);
long maxVersion = Math.max(maxVersionFromIndex, maxVersionFromRecent);
if (maxVersion == 0L) {
maxVersion = versions.getNewClock();
log.info("Could not find max version in index or recent updates, using new clock {}", maxVersion);
}
// seed all version buckets with the highest value from recent and index
versions.seedBucketsWithHighestVersion(maxVersion);
highestVersion = maxVersion;
} catch (IOException ioExc) {
log.warn("Failed to determine the max value of the version field due to: " + ioExc, ioExc);
}
log.debug("Took {}ms to seed version buckets with highest version {}", timer.getTime(), String.valueOf(highestVersion));
return highestVersion;
}
use of org.apache.solr.util.RTimer in project lucene-solr by apache.
the class TestWriterPerf method doPerf.
void doPerf(String writerName, SolrQueryRequest req, int encIter, int decIter) throws Exception {
SolrQueryResponse rsp = getResponse(req);
QueryResponseWriter w = h.getCore().getQueryResponseWriter(writerName);
ByteArrayOutputStream out = null;
System.gc();
RTimer timer = new RTimer();
for (int i = 0; i < encIter; i++) {
if (w instanceof BinaryQueryResponseWriter) {
BinaryQueryResponseWriter binWriter = (BinaryQueryResponseWriter) w;
out = new ByteArrayOutputStream();
binWriter.write(out, req, rsp);
out.close();
} else {
out = new ByteArrayOutputStream();
// to be fair, from my previous tests, much of the performance will be sucked up
// by java's UTF-8 encoding/decoding, not the actual writing
Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
w.write(writer, req, rsp);
writer.close();
}
}
double encodeTime = timer.getTime();
byte[] arr = out.toByteArray();
timer = new RTimer();
writerName = writerName.intern();
for (int i = 0; i < decIter; i++) {
ResponseParser rp = null;
if (writerName == "xml") {
rp = new XMLResponseParser();
} else if (writerName == "javabin") {
rp = new BinaryResponseParser();
} else {
break;
}
ByteArrayInputStream in = new ByteArrayInputStream(arr);
rp.processResponse(in, "UTF-8");
}
double decodeTime = timer.getTime();
log.info("writer " + writerName + ", size=" + out.size() + ", encodeRate=" + (encIter * 1000L / encodeTime) + ", decodeRate=" + (decIter * 1000L / decodeTime));
req.close();
}
use of org.apache.solr.util.RTimer in project lucene-solr by apache.
the class TestSolrJ method doCommitPerf.
public void doCommitPerf() throws Exception {
try (HttpSolrClient client = getHttpSolrClient("http://127.0.0.1:8983/solr")) {
final RTimer timer = new RTimer();
for (int i = 0; i < 10000; i++) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", Integer.toString(i % 13));
client.add(doc);
client.commit(true, true, true);
}
System.out.println("TIME: " + timer.getTime());
}
}
use of org.apache.solr.util.RTimer in project lucene-solr by apache.
the class ChaosMonkey method startTheMonkey.
// synchronously starts and stops shards randomly, unless there is only one
// active shard up for a slice or if there is one active and others recovering
public void startTheMonkey(boolean killLeaders, final int roundPauseUpperLimit) {
if (!MONKEY_ENABLED) {
monkeyLog("The Monkey is disabled and will not start");
return;
}
monkeyLog("starting");
if (chaosRandom.nextBoolean()) {
monkeyLog("Jetty will not commit on close");
DirectUpdateHandler2.commitOnClose = false;
}
this.aggressivelyKillLeaders = killLeaders;
runTimer = new RTimer();
// TODO: when kill leaders is on, lets kill a higher percentage of leaders
stop = false;
monkeyThread = new Thread() {
@Override
public void run() {
while (!stop) {
try {
Thread.sleep(chaosRandom.nextInt(roundPauseUpperLimit));
causeSomeChaos();
} catch (InterruptedException e) {
//
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
monkeyLog("finished");
monkeyLog("I ran for " + runTimer.getTime() / 1000 + "s. I stopped " + stops + " and I started " + starts + ". I also expired " + expires.get() + " and caused " + connloss + " connection losses");
}
};
monkeyThread.start();
}
Aggregations