use of org.apache.solr.util.RTimer in project lucene-solr by apache.
the class TestSearchPerf method doListGen.
int doListGen(int iter, Query q, List<Query> filt, boolean cacheQuery, boolean cacheFilt) throws Exception {
SolrQueryRequest req = lrf.makeRequest();
SolrIndexSearcher searcher = req.getSearcher();
final RTimer timer = new RTimer();
int ret = 0;
for (int i = 0; i < iter; i++) {
DocList l = searcher.getDocList(q, filt, (Sort) null, 0, 10, (cacheQuery ? 0 : SolrIndexSearcher.NO_CHECK_QCACHE) | (cacheFilt ? 0 : SolrIndexSearcher.NO_CHECK_FILTERCACHE));
ret += l.matches();
}
double elapsed = timer.getTime();
System.out.println("ret=" + ret + " time=" + elapsed + " throughput=" + iter * 1000 / (elapsed + 1));
req.close();
// make sure we did some work
assertTrue(ret > 0);
return ret;
}
use of org.apache.solr.util.RTimer in project lucene-solr by apache.
the class DocSetPerf method main.
public static void main(String[] args) {
String bsSize = args[0];
boolean randSize = false;
if (bsSize.endsWith("-")) {
bsSize = bsSize.substring(0, bsSize.length() - 1);
randSize = true;
}
int bitSetSize = Integer.parseInt(bsSize);
int numSets = Integer.parseInt(args[1]);
int numBitsSet = Integer.parseInt(args[2]);
String test = args[3].intern();
int iter = Integer.parseInt(args[4]);
long ret = 0;
FixedBitSet[] sets = new FixedBitSet[numSets];
DocSet[] bset = new DocSet[numSets];
DocSet[] hset = new DocSet[numSets];
for (int i = 0; i < numSets; i++) {
generate(randSize ? rand.nextInt(bitSetSize) : bitSetSize, numBitsSet);
sets[i] = bs;
bset[i] = bds;
hset[i] = hds;
}
final RTimer timer = new RTimer();
if ("test".equals(test)) {
for (int it = 0; it < iter; it++) {
generate(randSize ? rand.nextInt(bitSetSize) : bitSetSize, numBitsSet);
FixedBitSet bs1 = bs;
BitDocSet bds1 = bds;
HashDocSet hds1 = hds;
generate(randSize ? rand.nextInt(bitSetSize) : bitSetSize, numBitsSet);
FixedBitSet res = bs1.clone();
res.and(bs);
int icount = res.cardinality();
test(bds1.intersection(bds).size() == icount);
test(bds1.intersectionSize(bds) == icount);
if (bds1.intersection(hds).size() != icount) {
DocSet ds = bds1.intersection(hds);
System.out.println("STOP");
}
test(bds1.intersection(hds).size() == icount);
test(bds1.intersectionSize(hds) == icount);
test(hds1.intersection(bds).size() == icount);
test(hds1.intersectionSize(bds) == icount);
test(hds1.intersection(hds).size() == icount);
test(hds1.intersectionSize(hds) == icount);
ret += icount;
}
}
String type = null;
String oper = null;
if (test.endsWith("B")) {
type = "B";
}
if (test.endsWith("H")) {
type = "H";
}
if (test.endsWith("M")) {
type = "M";
}
if (test.startsWith("intersect"))
oper = "intersect";
if (test.startsWith("intersectSize"))
oper = "intersectSize";
if (test.startsWith("intersectAndSize"))
oper = "intersectSize";
if (oper != null) {
for (int it = 0; it < iter; it++) {
int idx1 = rand.nextInt(numSets);
int idx2 = rand.nextInt(numSets);
DocSet a = null, b = null;
if (type == "B") {
a = bset[idx1];
b = bset[idx2];
} else if (type == "H") {
a = hset[idx1];
b = bset[idx2];
} else if (type == "M") {
if (idx1 < idx2) {
a = bset[idx1];
b = hset[idx2];
} else {
a = hset[idx1];
b = bset[idx2];
}
}
if (oper == "intersect") {
DocSet res = a.intersection(b);
ret += res.ramBytesUsed();
} else if (oper == "intersectSize") {
ret += a.intersectionSize(b);
} else if (oper == "intersectAndSize") {
DocSet res = a.intersection(b);
ret += res.size();
}
}
}
System.out.println("TIME=" + timer.getTime());
System.out.println("ret=" + ret);
}
use of org.apache.solr.util.RTimer in project lucene-solr by apache.
the class TestFastLRUCache method doPerfTest.
void doPerfTest(int iter, int cacheSize, int maxKey) {
final RTimer timer = new RTimer();
int lowerWaterMark = cacheSize;
int upperWaterMark = (int) (lowerWaterMark * 1.1);
Random r = random();
ConcurrentLRUCache cache = new ConcurrentLRUCache(upperWaterMark, lowerWaterMark, (upperWaterMark + lowerWaterMark) / 2, upperWaterMark, false, false, null);
boolean getSize = false;
int minSize = 0, maxSize = 0;
for (int i = 0; i < iter; i++) {
cache.put(r.nextInt(maxKey), "TheValue");
int sz = cache.size();
if (!getSize && sz >= cacheSize) {
getSize = true;
minSize = sz;
} else {
if (sz < minSize)
minSize = sz;
else if (sz > maxSize)
maxSize = sz;
}
}
cache.destroy();
System.out.println("time=" + timer.getTime() + ", minSize=" + minSize + ",maxSize=" + maxSize);
}
use of org.apache.solr.util.RTimer in project lucene-solr by apache.
the class TestJavaBinCodec method doDecodePerf.
public static void doDecodePerf(String[] args) throws Exception {
int arg = 0;
int nThreads = Integer.parseInt(args[arg++]);
int nBuffers = Integer.parseInt(args[arg++]);
final long iter = Long.parseLong(args[arg++]);
int cacheSz = Integer.parseInt(args[arg++]);
Random r = new Random(0);
final byte[][] buffers = new byte[nBuffers][];
for (int bufnum = 0; bufnum < nBuffers; bufnum++) {
SolrDocument sdoc = new SolrDocument();
sdoc.put("id", "my_id_" + bufnum);
sdoc.put("author", str(r, 10 + r.nextInt(10)));
sdoc.put("address", str(r, 20 + r.nextInt(20)));
sdoc.put("license", str(r, 10));
sdoc.put("title", str(r, 5 + r.nextInt(10)));
sdoc.put("modified_dt", r.nextInt(1000000));
sdoc.put("creation_dt", r.nextInt(1000000));
sdoc.put("birthdate_dt", r.nextInt(1000000));
sdoc.put("clean", r.nextBoolean());
sdoc.put("dirty", r.nextBoolean());
sdoc.put("employed", r.nextBoolean());
sdoc.put("priority", r.nextInt(100));
sdoc.put("dependents", r.nextInt(6));
sdoc.put("level", r.nextInt(101));
sdoc.put("education_level", r.nextInt(10));
// higher level of reuse for string values
sdoc.put("state", "S" + r.nextInt(50));
sdoc.put("country", "Country" + r.nextInt(20));
sdoc.put("some_boolean", "" + r.nextBoolean());
sdoc.put("another_boolean", "" + r.nextBoolean());
buffers[bufnum] = getBytes(sdoc);
}
int ret = 0;
final RTimer timer = new RTimer();
// the cache in the first version of the patch was 10000,9000,10000,1000,false,true,null
ConcurrentLRUCache underlyingCache = cacheSz > 0 ? new ConcurrentLRUCache<>(cacheSz, cacheSz - cacheSz / 10, cacheSz, cacheSz / 10, false, true, null) : null;
final JavaBinCodec.StringCache stringCache = underlyingCache == null ? null : new JavaBinCodec.StringCache(underlyingCache);
if (nThreads <= 0) {
ret += doDecode(buffers, iter, stringCache);
} else {
runInThreads(nThreads, () -> {
try {
doDecode(buffers, iter, stringCache);
} catch (IOException e) {
e.printStackTrace();
}
});
}
long n = iter * Math.max(1, nThreads);
System.out.println("ret=" + ret + " THROUGHPUT=" + (n * 1000 / timer.getTime()));
if (underlyingCache != null)
System.out.println("cache: hits=" + underlyingCache.getStats().getCumulativeHits() + " lookups=" + underlyingCache.getStats().getCumulativeLookups() + " size=" + underlyingCache.getStats().getCurrentSize());
}
use of org.apache.solr.util.RTimer in project lucene-solr by apache.
the class TestJavaBinCodec method testPerf.
private void testPerf() throws InterruptedException {
final ArrayList<JavaBinCodec.StringBytes> l = new ArrayList<>();
Cache<JavaBinCodec.StringBytes, String> cache = null;
/* cache = new ConcurrentLRUCache<JavaBinCodec.StringBytes,String>(10000, 9000, 10000, 1000, false, true, null){
@Override
public String put(JavaBinCodec.StringBytes key, String val) {
l.add(key);
return super.put(key, val);
}
};*/
Runtime.getRuntime().gc();
printMem("before cache init");
Cache<JavaBinCodec.StringBytes, String> cache1 = new MapBackedCache<>(new HashMap<>());
final JavaBinCodec.StringCache STRING_CACHE = new JavaBinCodec.StringCache(cache1);
// STRING_CACHE = new JavaBinCodec.StringCache(cache);
byte[] bytes = new byte[0];
JavaBinCodec.StringBytes stringBytes = new JavaBinCodec.StringBytes(null, 0, 0);
for (int i = 0; i < 10000; i++) {
String s = String.valueOf(random().nextLong());
int end = s.length();
int maxSize = end * 4;
if (bytes == null || bytes.length < maxSize)
bytes = new byte[maxSize];
int sz = ByteUtils.UTF16toUTF8(s, 0, end, bytes, 0);
STRING_CACHE.get(stringBytes.reset(bytes, 0, sz));
}
printMem("after cache init");
RTimer timer = new RTimer();
final int ITERS = 1000000;
int THREADS = 10;
runInThreads(THREADS, () -> {
JavaBinCodec.StringBytes stringBytes1 = new JavaBinCodec.StringBytes(new byte[0], 0, 0);
for (int i = 0; i < ITERS; i++) {
JavaBinCodec.StringBytes b = l.get(i % l.size());
stringBytes1.reset(b.bytes, 0, b.bytes.length);
if (STRING_CACHE.get(stringBytes1) == null)
throw new RuntimeException("error");
}
});
printMem("after cache test");
System.out.println("time taken by LRUCACHE " + timer.getTime());
timer = new RTimer();
runInThreads(THREADS, () -> {
String a = null;
CharArr arr = new CharArr();
for (int i = 0; i < ITERS; i++) {
JavaBinCodec.StringBytes sb = l.get(i % l.size());
arr.reset();
ByteUtils.UTF8toUTF16(sb.bytes, 0, sb.bytes.length, arr);
a = arr.toString();
}
});
printMem("after new string test");
System.out.println("time taken by string creation " + timer.getTime());
}
Aggregations