Search in sources :

Example 1 with RTimer

use of org.apache.solr.util.RTimer in project lucene-solr by apache.

the class TestIndexingPerformance method testIndexingPerf.

public void testIndexingPerf() throws IOException {
    int iter = 1000;
    String iterS = System.getProperty("iter");
    if (iterS != null)
        iter = Integer.parseInt(iterS);
    boolean overwrite = Boolean.parseBoolean(System.getProperty("overwrite", "false"));
    String doc = System.getProperty("doc");
    if (doc != null) {
        StrUtils.splitSmart(doc, ",", true);
    }
    SolrQueryRequest req = lrf.makeRequest();
    UpdateHandler updateHandler = req.getCore().getUpdateHandler();
    String field = "textgap";
    String[] fields = { field, "simple", field, "test", field, "how now brown cow", field, "what's that?", field, "radical!", field, "what's all this about, anyway?", field, "just how fast is this text indexing?" };
    /***
    String[] fields = {
            "a_i","1"
            ,"b_i","2"
            ,"c_i","3"
            ,"d_i","4"
            ,"e_i","5"
            ,"f_i","6"
            ,"g_i","7"
            ,"h_i","8"
            ,"i_i","9"
            ,"j_i","0"
            ,"k_i","0"
    };
   ***/
    final RTimer timer = new RTimer();
    AddUpdateCommand add = new AddUpdateCommand(req);
    add.overwrite = overwrite;
    for (int i = 0; i < iter; i++) {
        add.clear();
        add.solrDoc = new SolrInputDocument();
        add.solrDoc.addField("id", Integer.toString(i));
        for (int j = 0; j < fields.length; j += 2) {
            String f = fields[j];
            String val = fields[j + 1];
            add.solrDoc.addField(f, val);
        }
        updateHandler.addDoc(add);
    }
    log.info("doc=" + Arrays.toString(fields));
    double elapsed = timer.getTime();
    log.info("iter=" + iter + " time=" + elapsed + " throughput=" + ((long) iter * 1000) / elapsed);
    //discard all the changes
    updateHandler.rollback(new RollbackUpdateCommand(req));
    req.close();
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) RTimer(org.apache.solr.util.RTimer)

Example 2 with RTimer

use of org.apache.solr.util.RTimer in project lucene-solr by apache.

the class TestSearchPerf method doSetGen.

int doSetGen(int iter, Query q) 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++) {
        DocSet set = searcher.getDocSetNC(q, null);
        ret += set.size();
    }
    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;
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) RTimer(org.apache.solr.util.RTimer)

Example 3 with RTimer

use of org.apache.solr.util.RTimer in project lucene-solr by apache.

the class TestSolrJ method main.

public static void main(String[] args) throws Exception {
    // String addr = "http://odin.local:80/solr";
    // String addr = "http://odin.local:8983/solr";
    String addr = "http://127.0.0.1:8983/solr";
    int i = 0;
    final int nDocs = Integer.parseInt(args[i++]);
    final int nProducers = Integer.parseInt(args[i++]);
    final int nConnections = Integer.parseInt(args[i++]);
    final int maxSleep = Integer.parseInt(args[i++]);
    ConcurrentUpdateSolrClient concurrentClient = null;
    // server = concurrentClient = new ConcurrentUpdateSolrServer(addr,32,8);
    client = concurrentClient = getConcurrentUpdateSolrClient(addr, 64, nConnections);
    client.deleteByQuery("*:*");
    client.commit();
    final RTimer timer = new RTimer();
    final int docsPerThread = nDocs / nProducers;
    Thread[] threads = new Thread[nProducers];
    for (int threadNum = 0; threadNum < nProducers; threadNum++) {
        final int base = threadNum * docsPerThread;
        threads[threadNum] = new Thread("add-thread" + i) {

            @Override
            public void run() {
                try {
                    indexDocs(base, docsPerThread, maxSleep);
                } catch (Exception e) {
                    System.out.println("###############################CAUGHT EXCEPTION");
                    e.printStackTrace();
                    ex = e;
                }
            }
        };
        threads[threadNum].start();
    }
    for (int threadNum = 0; threadNum < nProducers; threadNum++) {
        threads[threadNum].join();
    }
    if (concurrentClient != null) {
        concurrentClient.blockUntilFinished();
    }
    double elapsed = timer.getTime();
    System.out.println("time=" + elapsed + " throughput=" + (nDocs * 1000 / elapsed) + " Exception=" + ex);
// should server threads be marked as daemon?
// need a server.close()!!!
}
Also used : ConcurrentUpdateSolrClient(org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient) RTimer(org.apache.solr.util.RTimer) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 4 with RTimer

use of org.apache.solr.util.RTimer in project lucene-solr by apache.

the class AbstractCurrencyFieldTest method testPerformance.

@Ignore
public void testPerformance() throws Exception {
    clearIndex();
    Random r = random();
    int initDocs = 200000;
    for (int i = 1; i <= initDocs; i++) {
        assertU(adoc("id", "" + i, field(), (r.nextInt(10) + 1.00) + ",USD"));
        if (i % 1000 == 0)
            System.out.println(i);
    }
    assertU(commit());
    for (int i = 0; i < 1000; i++) {
        double lower = r.nextInt(10) + 1.00;
        assertQ(req("fl", "*,score", "q", field() + ":[" + lower + ",USD TO " + (lower + 10.00) + ",USD]"), "//*");
        assertQ(req("fl", "*,score", "q", field() + ":[" + lower + ",EUR TO " + (lower + 10.00) + ",EUR]"), "//*");
    }
    for (int j = 0; j < 3; j++) {
        final RTimer timer = new RTimer();
        for (int i = 0; i < 1000; i++) {
            double lower = r.nextInt(10) + 1.00;
            assertQ(req("fl", "*,score", "q", field() + ":[" + lower + ",USD TO " + (lower + (9.99 - (j * 0.01))) + ",USD]"), "//*");
        }
        System.out.println(timer.getTime());
    }
    System.out.println("---");
    for (int j = 0; j < 3; j++) {
        final RTimer timer = new RTimer();
        for (int i = 0; i < 1000; i++) {
            double lower = r.nextInt(10) + 1.00;
            assertQ(req("fl", "*,score", "q", field() + ":[" + lower + ",EUR TO " + (lower + (9.99 - (j * 0.01))) + ",EUR]"), "//*");
        }
        System.out.println(timer.getTime());
    }
}
Also used : Random(java.util.Random) RTimer(org.apache.solr.util.RTimer) Ignore(org.junit.Ignore)

Example 5 with RTimer

use of org.apache.solr.util.RTimer in project lucene-solr by apache.

the class TestFastLRUCache method cachePerfTest.

void cachePerfTest(final SolrCache sc, final int nThreads, final int numGets, int cacheSize, final int maxKey) {
    Map l = new HashMap();
    l.put("size", "" + cacheSize);
    l.put("initialSize", "" + cacheSize);
    Object o = sc.init(l, null, null);
    sc.setState(SolrCache.State.LIVE);
    fillCache(sc, cacheSize, maxKey);
    final RTimer timer = new RTimer();
    Thread[] threads = new Thread[nThreads];
    final AtomicInteger puts = new AtomicInteger(0);
    for (int i = 0; i < threads.length; i++) {
        final int seed = random().nextInt();
        threads[i] = new Thread() {

            @Override
            public void run() {
                int ret = useCache(sc, numGets / nThreads, maxKey, seed);
                puts.addAndGet(ret);
            }
        };
    }
    for (Thread thread : threads) {
        try {
            thread.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    for (Thread thread : threads) {
        try {
            thread.join();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    System.out.println("time=" + timer.getTime() + " impl=" + sc.getClass().getSimpleName() + " nThreads= " + nThreads + " size=" + cacheSize + " maxKey=" + maxKey + " gets=" + numGets + " hitRatio=" + (1 - (((double) puts.get()) / numGets)));
}
Also used : HashMap(java.util.HashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) HashMap(java.util.HashMap) MetricsMap(org.apache.solr.metrics.MetricsMap) RTimer(org.apache.solr.util.RTimer) IOException(java.io.IOException)

Aggregations

RTimer (org.apache.solr.util.RTimer)31 SolrException (org.apache.solr.common.SolrException)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)4 List (java.util.List)3 Random (java.util.Random)3 SolrServerException (org.apache.solr.client.solrj.SolrServerException)3 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)3 ClusterState (org.apache.solr.common.cloud.ClusterState)3 Replica (org.apache.solr.common.cloud.Replica)3 Slice (org.apache.solr.common.cloud.Slice)3 IdentityHashMap (java.util.IdentityHashMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 Future (java.util.concurrent.Future)2 NoHttpResponseException (org.apache.http.NoHttpResponseException)2 SolrInputDocument (org.apache.solr.common.SolrInputDocument)2