r640 - in trunk/wikitty-perf-test: . src/main src/main/java/org/nuiton/wikitty/perftest src/main/resources
Author: sletellier Date: 2010-12-21 16:33:48 +0100 (Tue, 21 Dec 2010) New Revision: 640 Url: http://nuiton.org/repositories/revision/wikitty/640 Log: - Reformat code - Update headers - Add log4j dependency - Use log4j Added: trunk/wikitty-perf-test/src/main/resources/ trunk/wikitty-perf-test/src/main/resources/log4j.properties Modified: trunk/wikitty-perf-test/pom.xml trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTest.java trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestLabelAdd.java trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestLabelSearch.java trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestSearch.java trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestUtils.java Modified: trunk/wikitty-perf-test/pom.xml =================================================================== --- trunk/wikitty-perf-test/pom.xml 2010-12-21 15:32:36 UTC (rev 639) +++ trunk/wikitty-perf-test/pom.xml 2010-12-21 15:33:48 UTC (rev 640) @@ -48,6 +48,10 @@ <artifactId>commons-logging</artifactId> </dependency> <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </dependency> + <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> </dependency> @@ -87,4 +91,17 @@ <name>Wikitty :: wikitty-perf-test</name> <description>Wikitty performance tests</description> <inceptionYear>2010</inceptionYear> + + <build> + + <resources> + <resource> + <directory>src/main/resources</directory> + <includes> + <include>**/*</include> + </includes> + <filtering>true</filtering> + </resource> + </resources> + </build> </project> \ No newline at end of file Modified: trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTest.java =================================================================== --- trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTest.java 2010-12-21 15:32:36 UTC (rev 639) +++ trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTest.java 2010-12-21 15:33:48 UTC (rev 640) @@ -1,100 +1,129 @@ +/* + * #%L + * Wikitty :: wikitty-perf-test + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 CodeLutin, Benjamin Poussin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ package org.nuiton.wikitty.perftest; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - import org.apache.commons.lang.RandomStringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.wikitty.WikittyConfig; import org.nuiton.wikitty.WikittyProxy; -import org.nuiton.wikitty.WikittyConfig; import org.nuiton.wikitty.WikittyService; import org.nuiton.wikitty.WikittyServiceFactory; - +import org.nuiton.wikitty.entities.ExtensionFactory; +import org.nuiton.wikitty.entities.FieldType.TYPE; import org.nuiton.wikitty.entities.Wikitty; +import org.nuiton.wikitty.entities.WikittyExtension; import org.nuiton.wikitty.entities.WikittyImpl; -import org.nuiton.wikitty.entities.FieldType.TYPE; -import org.nuiton.wikitty.entities.ExtensionFactory; -import org.nuiton.wikitty.entities.WikittyExtension; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + public class PerfTest { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(PerfTest.class); + public static void main(String[] args) { - WikittyConfig config = new WikittyConfig(args); - int threadsNb = 20; - int researches = 2001; - int loopsToAvg = 5; - int wikittiesToCreate = 70; - if (threadsNb > researches) - threadsNb = researches; - boolean skipSearchesTests = false; - boolean skipLabelsTests = false; + WikittyConfig config = new WikittyConfig(args); + int threadsNb = 20; + int researches = 2001; + int loopsToAvg = 5; + int wikittiesToCreate = 70; + if (threadsNb > researches) { + threadsNb = researches; + } + boolean skipSearchesTests = false; + boolean skipLabelsTests = false; - WikittyService ws = WikittyServiceFactory.buildWikittyService(config); - WikittyProxy proxy = new WikittyProxy(ws); - WikittyExtension ext = ExtensionFactory.create("perfTest", "1") - .addField("name", TYPE.STRING).addField("surname", TYPE.STRING) - .addField("age", TYPE.NUMERIC).addField("height", TYPE.NUMERIC) - .addField("birth", TYPE.DATE).addField("wedding", TYPE.DATE) - .addField("isTrue", TYPE.BOOLEAN).addField("isFalse", TYPE.BOOLEAN) - .addField("wiki1", TYPE.WIKITTY).addField("wiki2", TYPE.WIKITTY).extension(); + WikittyService ws = WikittyServiceFactory.buildWikittyService(config); + WikittyProxy proxy = new WikittyProxy(ws); + WikittyExtension ext = ExtensionFactory.create("perfTest", "1") + .addField("name", TYPE.STRING).addField("surname", TYPE.STRING) + .addField("age", TYPE.NUMERIC).addField("height", TYPE.NUMERIC) + .addField("birth", TYPE.DATE).addField("wedding", TYPE.DATE) + .addField("isTrue", TYPE.BOOLEAN).addField("isFalse", TYPE.BOOLEAN) + .addField("wiki1", TYPE.WIKITTY).addField("wiki2", TYPE.WIKITTY).extension(); - Wikitty w = new WikittyImpl(); - Random rand = new Random(); - List<String> ids = new ArrayList<String>(); - for (int i = 0; i < wikittiesToCreate; i++) { - w = new WikittyImpl(); - ids.add(w.getId()); - w.addExtension(ext); - w.setField(ext.getName(), "name", RandomStringUtils.randomAscii(15)); - w.setField(ext.getName(), "surname", RandomStringUtils.randomAscii(20)); - w.setField(ext.getName(), "age", rand.nextInt(110)); - w.setField(ext.getName(), "height", rand.nextInt(230)); - w.setField(ext.getName(), "isTrue", rand.nextInt(1) == 0 ? true : false); - w.setField(ext.getName(), "isFalse", rand.nextInt(1) == 1 ? true : false); - w.setField(ext.getName(), "birth", "01/01/" + rand.nextInt(2010)); - w.setField(ext.getName(), "wiki1", w); - proxy.store(w); - } + Random rand = new Random(); + List<String> ids = new ArrayList<String>(); + for (int i = 0; i < wikittiesToCreate; i++) { + Wikitty w = new WikittyImpl(); + ids.add(w.getId()); + w.addExtension(ext); + w.setField(ext.getName(), "name", RandomStringUtils.randomAscii(15)); + w.setField(ext.getName(), "surname", RandomStringUtils.randomAscii(20)); + w.setField(ext.getName(), "age", rand.nextInt(110)); + w.setField(ext.getName(), "height", rand.nextInt(230)); + w.setField(ext.getName(), "isTrue", rand.nextInt(1) == 0); + w.setField(ext.getName(), "isFalse", rand.nextInt(1) == 1); + w.setField(ext.getName(), "birth", "01/01/" + rand.nextInt(2010)); + w.setField(ext.getName(), "wiki1", w); + proxy.store(w); + } - PerfTestUtils.out("Tests on searches :"); - if (!skipSearchesTests) { - PerfTestUtils.out("== Tests on fields of type STRING =="); - PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "name", "toto", true); - PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "name", "toto", false); + PerfTestUtils.out("Tests on searches :"); + if (!skipSearchesTests) { + PerfTestUtils.out("== Tests on fields of type STRING =="); + PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "name", "toto", true); + PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "name", "toto", false); - PerfTestUtils.out("------------\n"); - PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "surname", "a", true); - PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "surname", "a", false); + PerfTestUtils.out("------------\n"); + PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "surname", "a", true); + PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "surname", "a", false); - PerfTestUtils.out("== Tests on fields of type NUMERIC =="); - PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "age", "40", true); - PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "age", "40", false); + PerfTestUtils.out("== Tests on fields of type NUMERIC =="); + PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "age", "40", true); + PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "age", "40", false); - PerfTestUtils.out("------------\n"); - PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "height", "100", true); - PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "height", "100", false); + PerfTestUtils.out("------------\n"); + PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "height", "100", true); + PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "height", "100", false); - PerfTestUtils.out("== Tests on a field of type BOOLEAN =="); - PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "isTrue", "true", true); - PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "isTrue", "true", false); + PerfTestUtils.out("== Tests on a field of type BOOLEAN =="); + PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "isTrue", "true", true); + PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "isTrue", "true", false); - PerfTestUtils.out("== Tests on a field of type DATE =="); - PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "birth", "06/07/1720", true); - PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "birth", "06/07/1720", false); + PerfTestUtils.out("== Tests on a field of type DATE =="); + PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "birth", "06/07/1720", true); + PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "birth", "06/07/1720", false); - PerfTestUtils.out("== Tests on a field of type WIKITTY =="); - String wikittySearched = proxy.restore(ids.get(rand.nextInt(wikittiesToCreate))).toString(); - PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "wiki1", wikittySearched, true); - PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "wiki1", wikittySearched, false); - } else { - PerfTestUtils.out("Skipped"); - } + PerfTestUtils.out("== Tests on a field of type WIKITTY =="); + String wikittySearched = proxy.restore(ids.get(rand.nextInt(wikittiesToCreate))).toString(); + PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "wiki1", wikittySearched, true); + PerfTestSearch.search(ws, ext, loopsToAvg, researches, wikittiesToCreate, threadsNb, "wiki1", wikittySearched, false); + } else { + PerfTestUtils.out("Skipped"); + } - PerfTestUtils.out("Tests on labels :"); - if (!skipLabelsTests) { - PerfTestLabelAdd.addLabel(proxy, ids, loopsToAvg, threadsNb); - PerfTestLabelSearch.searchLabel(proxy, ids, loopsToAvg, threadsNb); - } else { - PerfTestUtils.out("Skipped"); - } + PerfTestUtils.out("Tests on labels :"); + if (!skipLabelsTests) { + PerfTestLabelAdd.addLabel(proxy, ids, loopsToAvg, threadsNb); + PerfTestLabelSearch.searchLabel(proxy, ids, loopsToAvg, threadsNb); + } else { + PerfTestUtils.out("Skipped"); + } } } Modified: trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestLabelAdd.java =================================================================== --- trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestLabelAdd.java 2010-12-21 15:32:36 UTC (rev 639) +++ trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestLabelAdd.java 2010-12-21 15:33:48 UTC (rev 640) @@ -1,39 +1,70 @@ +/* + * #%L + * Wikitty :: wikitty-perf-test + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 CodeLutin, Benjamin Poussin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ package org.nuiton.wikitty.perftest; -import java.util.ArrayList; -import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.wikitty.WikittyProxy; import org.nuiton.wikitty.addons.WikittyLabelUtil; +import java.util.ArrayList; +import java.util.List; + public class PerfTestLabelAdd { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(PerfTestLabelAdd.class); + private static class PerfTestLabelAddThread extends Thread { - private int labelsToAdd; - private WikittyProxy proxy; - private List<String> ids; - private int startAt; + private int labelsToAdd; + private WikittyProxy proxy; + private List<String> ids; + private int startAt; - /** - * - * @param labelsToAdd - * @param proxy - * @param ids - * @param startAt - */ - PerfTestLabelAddThread(int labelsToAdd, WikittyProxy proxy, List<String> ids, int startAt) { - this.labelsToAdd = labelsToAdd; - this.proxy = proxy; - this.ids = ids; - this.startAt = startAt; - } + /** + * + * @param labelsToAdd + * @param proxy + * @param ids + * @param startAt + */ + PerfTestLabelAddThread(int labelsToAdd, WikittyProxy proxy, List<String> ids, int startAt) { + this.labelsToAdd = labelsToAdd; + this.proxy = proxy; + this.ids = ids; + this.startAt = startAt; + } - @Override - public void run() { - long time = System.currentTimeMillis(); + @Override + public void run() { + long time = System.currentTimeMillis(); - for (int i = startAt; i < (labelsToAdd + startAt); i++) { - WikittyLabelUtil.addLabel(proxy, ids.get(i), ids.get(i) + time); - } - } + for (int i = startAt; i < (labelsToAdd + startAt); i++) { + WikittyLabelUtil.addLabel(proxy, ids.get(i), ids.get(i) + time); + } + } } /** @@ -45,45 +76,47 @@ * @param threadsNb : the number of threads that will be created to add a part of the labels */ public static void addLabel(WikittyProxy proxy, List<String> ids, int loopsToAvg, int threadsNb) { - long time = System.currentTimeMillis(); - int wikittiesToCreate = ids.size(); + long time = System.currentTimeMillis(); + int wikittiesToCreate = ids.size(); - for (int k = 0; k < loopsToAvg; k++) { - for (String id : ids) { - WikittyLabelUtil.addLabel(proxy, id, id + time); - } - } - time = System.currentTimeMillis() - time; - PerfTestUtils.out("1 thread took (average on " + loopsToAvg + " loops) " + (time / loopsToAvg) + " ms to add " + wikittiesToCreate + - " labels on " + wikittiesToCreate + " wikitties\n"); + for (int k = 0; k < loopsToAvg; k++) { + for (String id : ids) { + WikittyLabelUtil.addLabel(proxy, id, id + time); + } + } + time = System.currentTimeMillis() - time; + PerfTestUtils.out("1 thread took (average on " + loopsToAvg + " loops) " + + (time / loopsToAvg) + " ms to add " + wikittiesToCreate + + " labels on " + wikittiesToCreate + " wikitties\n"); - List<PerfTestLabelAddThread> threads = new ArrayList<PerfTestLabelAddThread>(); + List<PerfTestLabelAddThread> threads = new ArrayList<PerfTestLabelAddThread>(); - time = System.currentTimeMillis(); - int threadMod = ((wikittiesToCreate % threadsNb) != 0 ? 1 : 0); - - for (int j = 0; j < loopsToAvg; j++) { - for (int i = 0; i < threadsNb; i++) { - threads.add(new PerfTestLabelAddThread(wikittiesToCreate / threadsNb, proxy, ids, i * (wikittiesToCreate / threadsNb))); - } - if (threadMod == 1) { - threads.add(new PerfTestLabelAddThread(wikittiesToCreate % threadsNb, proxy, ids, threadsNb * (wikittiesToCreate / threadsNb))); - } - for (int i = 0; i < (threadsNb + threadMod); i++) { - threads.get(i).start(); - } - for (int i = 0; i < (threadsNb + threadMod); i++) { - try { - threads.get(i).join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - threads.clear(); - } - time = System.currentTimeMillis() - time; - PerfTestUtils.out(threadsNb + (threadMod == 1 ? "(+1)" : "") + " threads took (average on " + loopsToAvg + " loops) " + (time / loopsToAvg) + - " ms to add " + (wikittiesToCreate / threadsNb) + " labels each " + (threadMod == 1 ? "(+" + (wikittiesToCreate % threadsNb) + - " labels) " : "") + "on " + wikittiesToCreate + " wikitties\n"); + time = System.currentTimeMillis(); + int threadMod = ((wikittiesToCreate % threadsNb) != 0 ? 1 : 0); + + for (int j = 0; j < loopsToAvg; j++) { + for (int i = 0; i < threadsNb; i++) { + threads.add(new PerfTestLabelAddThread(wikittiesToCreate / threadsNb, proxy, ids, i * (wikittiesToCreate / threadsNb))); + } + if (threadMod == 1) { + threads.add(new PerfTestLabelAddThread(wikittiesToCreate % threadsNb, proxy, ids, threadsNb * (wikittiesToCreate / threadsNb))); + } + for (int i = 0; i < (threadsNb + threadMod); i++) { + threads.get(i).start(); + } + for (int i = 0; i < (threadsNb + threadMod); i++) { + try { + threads.get(i).join(); + } catch (InterruptedException eee) { + // FIXME sletellier 21/12/10 : add some msg + log.error(eee); + } + } + threads.clear(); + } + time = System.currentTimeMillis() - time; + PerfTestUtils.out(threadsNb + (threadMod == 1 ? "(+1)" : "") + " threads took (average on " + loopsToAvg + " loops) " + (time / loopsToAvg) + + " ms to add " + (wikittiesToCreate / threadsNb) + " labels each " + (threadMod == 1 ? "(+" + (wikittiesToCreate % threadsNb) + + " labels) " : "") + "on " + wikittiesToCreate + " wikitties\n"); } } Modified: trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestLabelSearch.java =================================================================== --- trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestLabelSearch.java 2010-12-21 15:32:36 UTC (rev 639) +++ trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestLabelSearch.java 2010-12-21 15:33:48 UTC (rev 640) @@ -1,45 +1,75 @@ +/* + * #%L + * Wikitty :: wikitty-perf-test + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 CodeLutin, Benjamin Poussin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ package org.nuiton.wikitty.perftest; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.wikitty.WikittyProxy; +import org.nuiton.wikitty.addons.WikittyLabelUtil; + import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; -import org.nuiton.wikitty.WikittyProxy; -import org.nuiton.wikitty.addons.WikittyLabelUtil; +public class PerfTestLabelSearch { -public class PerfTestLabelSearch { + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(PerfTestLabelSearch.class); + private static class PerfTestLabelSearchThread extends Thread { - private int labelsToSearch; - private WikittyProxy proxy; - private List<String> ids; - private int startAt; + private int labelsToSearch; + private WikittyProxy proxy; + private List<String> ids; + private int startAt; - /** - * - * @param labelsToSearch - * @param proxy - * @param ids - * @param startAt - */ - PerfTestLabelSearchThread(int labelsToSearch, WikittyProxy proxy, List<String> ids, int startAt) { - this.labelsToSearch = labelsToSearch; - this.proxy = proxy; - this.ids = ids; - this.startAt = startAt; - } + /** + * + * @param labelsToSearch + * @param proxy + * @param ids + * @param startAt + */ + PerfTestLabelSearchThread(int labelsToSearch, WikittyProxy proxy, List<String> ids, int startAt) { + this.labelsToSearch = labelsToSearch; + this.proxy = proxy; + this.ids = ids; + this.startAt = startAt; + } - @Override - public void run() { - Set<String> labels = new HashSet<String>(); + @Override + public void run() { + Set<String> labels = new HashSet<String>(); - for (int i = startAt; i < (labelsToSearch + startAt); i++) { - labels.addAll(WikittyLabelUtil.findAllAppliedLabels(proxy, ids.get(i))); - } - for (String label : labels) { - WikittyLabelUtil.findAllByLabel(proxy, label, startAt, labelsToSearch + startAt); - } - } + for (int i = startAt; i < (labelsToSearch + startAt); i++) { + labels.addAll(WikittyLabelUtil.findAllAppliedLabels(proxy, ids.get(i))); + } + for (String label : labels) { + WikittyLabelUtil.findAllByLabel(proxy, label, startAt, labelsToSearch + startAt); + } + } } /** @@ -51,51 +81,52 @@ * @param threadsNb : the number of threads that will be created to do a part of the search */ public static void searchLabel(WikittyProxy proxy, List<String> ids, int loopsToAvg, int threadsNb) { - long time = System.currentTimeMillis(); - int wikittiesCreated = ids.size(); - Set<String> labels = new HashSet<String>(); + long time = System.currentTimeMillis(); + int wikittiesCreated = ids.size(); + Set<String> labels = new HashSet<String>(); - for (int k = 0; k < loopsToAvg; k++) { - for (String id : ids) { - labels.addAll(WikittyLabelUtil.findAllAppliedLabels(proxy, id)); - } - int size = labels.size(); + for (int k = 0; k < loopsToAvg; k++) { + for (String id : ids) { + labels.addAll(WikittyLabelUtil.findAllAppliedLabels(proxy, id)); + } + int size = labels.size(); - for (String label : labels) { - WikittyLabelUtil.findAllByLabel(proxy, label, 0, size); - } - } - time = System.currentTimeMillis() - time; - PerfTestUtils.out("1 thread took (average on " + loopsToAvg + " loops) " + (time / loopsToAvg) + " ms to find " + labels.size() + - " labels on " + wikittiesCreated + " wikitties\n"); + for (String label : labels) { + WikittyLabelUtil.findAllByLabel(proxy, label, 0, size); + } + } + time = System.currentTimeMillis() - time; + PerfTestUtils.out("1 thread took (average on " + loopsToAvg + " loops) " + + (time / loopsToAvg) + " ms to find " + labels.size() + + " labels on " + wikittiesCreated + " wikitties\n"); - List<PerfTestLabelSearchThread> threads = new ArrayList<PerfTestLabelSearchThread>(); + List<PerfTestLabelSearchThread> threads = new ArrayList<PerfTestLabelSearchThread>(); - time = System.currentTimeMillis(); - int threadMod = ((labels.size() % threadsNb) != 0 ? 1 : 0); - - for (int j = 0; j < loopsToAvg; j++) { - for (int i = 0; i < threadsNb; i++) { - threads.add(new PerfTestLabelSearchThread(wikittiesCreated / threadsNb, proxy, ids, i * (wikittiesCreated / threadsNb))); - } - if (threadMod == 1) { - threads.add(new PerfTestLabelSearchThread(wikittiesCreated % threadsNb, proxy, ids, threadsNb * (wikittiesCreated / threadsNb))); - } - for (int i = 0; i < (threadsNb + threadMod); i++) { - threads.get(i).start(); - } - for (int i = 0; i < (threadsNb + threadMod); i++) { - try { - threads.get(i).join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - threads.clear(); - } - time = System.currentTimeMillis() - time; - PerfTestUtils.out(threadsNb + (threadMod == 1 ? "(+1)" : "") + " threads took (average on " + loopsToAvg + " loops) " + - (time / loopsToAvg) + " ms to find " + (labels.size() / threadsNb) + " labels each " + - (threadMod == 1 ? "(+" + (labels.size() % threadsNb) + " labels)" : "") + " on " + wikittiesCreated + " wikitties\n"); + time = System.currentTimeMillis(); + int threadMod = ((labels.size() % threadsNb) != 0 ? 1 : 0); + + for (int j = 0; j < loopsToAvg; j++) { + for (int i = 0; i < threadsNb; i++) { + threads.add(new PerfTestLabelSearchThread(wikittiesCreated / threadsNb, proxy, ids, i * (wikittiesCreated / threadsNb))); + } + if (threadMod == 1) { + threads.add(new PerfTestLabelSearchThread(wikittiesCreated % threadsNb, proxy, ids, threadsNb * (wikittiesCreated / threadsNb))); + } + for (int i = 0; i < (threadsNb + threadMod); i++) { + threads.get(i).start(); + } + for (int i = 0; i < (threadsNb + threadMod); i++) { + try { + threads.get(i).join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + threads.clear(); + } + time = System.currentTimeMillis() - time; + PerfTestUtils.out(threadsNb + (threadMod == 1 ? "(+1)" : "") + " threads took (average on " + loopsToAvg + " loops) " + + (time / loopsToAvg) + " ms to find " + (labels.size() / threadsNb) + " labels each " + + (threadMod == 1 ? "(+" + (labels.size() % threadsNb) + " labels)" : "") + " on " + wikittiesCreated + " wikitties\n"); } } Modified: trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestSearch.java =================================================================== --- trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestSearch.java 2010-12-21 15:32:36 UTC (rev 639) +++ trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestSearch.java 2010-12-21 15:33:48 UTC (rev 640) @@ -1,8 +1,31 @@ +/* + * #%L + * Wikitty :: wikitty-perf-test + * * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 CodeLutin, Benjamin Poussin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ package org.nuiton.wikitty.perftest; -import java.util.ArrayList; -import java.util.List; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.wikitty.WikittyService; import org.nuiton.wikitty.entities.Wikitty; import org.nuiton.wikitty.entities.WikittyExtension; @@ -11,28 +34,36 @@ import org.nuiton.wikitty.search.Search; import org.nuiton.wikitty.services.WikittyServiceEnhanced; +import java.util.ArrayList; +import java.util.List; + public class PerfTestSearch { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(PerfTestSearch.class); + private static class PerfTestSearchThread extends Thread { - private int researches; - private WikittyService ws; - private WikittyExtension ext; - private boolean withRestore; - private String searchIn; - private String searched; - PerfTestSearchThread(int researches, WikittyService ws, WikittyExtension ext, boolean withRestore, String searchIn, String searched) { - this.researches = researches; - this.ws = ws; - this.ext = ext; - this.withRestore = withRestore; - this.searchIn = searchIn; - this.searched = searched; - } + private int researches; + private WikittyService ws; + private WikittyExtension ext; + private boolean withRestore; + private String searchIn; + private String searched; - @Override - public void run() { - searchGt(researches, ws, ext, searchIn, searched, withRestore); - } + PerfTestSearchThread(int researches, WikittyService ws, WikittyExtension ext, boolean withRestore, String searchIn, String searched) { + this.researches = researches; + this.ws = ws; + this.ext = ext; + this.withRestore = withRestore; + this.searchIn = searchIn; + this.searched = searched; + } + + @Override + public void run() { + searchGt(researches, ws, ext, searchIn, searched, withRestore); + } } /** @@ -46,17 +77,17 @@ * @param withRestore : if the wikitty will be restored after the search */ private static void searchGt(int researches, WikittyService ws, WikittyExtension ext, String searchIn, String searched, boolean withRestore) { - for (int i = 0; i < researches; i++) { - Criteria criteria = Search.query().gt(ext.getName() + "." + searchIn, searched).criteria(); - PagedResult<String> result = ws.findAllByCriteria(null, criteria); - List<String> found = result.getAll(); - for (int j = 0; j < found.size(); j++) { - if (withRestore) { - Wikitty wikittyFound = WikittyServiceEnhanced.restore(ws, null, found.get(j)); - wikittyFound.getFieldAsString(ext.getName(), searchIn); - } - } - } + for (int i = 0; i < researches; i++) { + Criteria criteria = Search.query().gt(ext.getName() + "." + searchIn, searched).criteria(); + PagedResult<String> result = ws.findAllByCriteria(null, criteria); + List<String> found = result.getAll(); + for (String aFound : found) { + if (withRestore) { + Wikitty wikittyFound = WikittyServiceEnhanced.restore(ws, null, aFound); + wikittyFound.getFieldAsString(ext.getName(), searchIn); + } + } + } } /** @@ -73,18 +104,20 @@ */ public static void oneThreadSearch(WikittyService ws, WikittyExtension ext, int loopsToAvg, int researches, int wikittiesCreated, String searchIn, String searched, boolean withRestore) { - long time = System.currentTimeMillis(); - for (int i = 0; i < loopsToAvg; i++) { - searchGt(researches, ws, ext, searchIn, searched, withRestore); - } - time = System.currentTimeMillis() - time; - if (withRestore) - PerfTestUtils.out("With WikittyServiceEnhanced.restore : "); - else - PerfTestUtils.out("Without WikittyServiceEnhanced.restore : "); - PerfTestUtils.out("1 thread took (average on " + loopsToAvg + " loops) " + (time / loopsToAvg) + " ms to do " + researches + - " researches on field " + searchIn + " in " + wikittiesCreated + " wikitties\n"); + long time = System.currentTimeMillis(); + + for (int i = 0; i < loopsToAvg; i++) { + searchGt(researches, ws, ext, searchIn, searched, withRestore); + } + time = System.currentTimeMillis() - time; + if (withRestore) { + PerfTestUtils.out("With WikittyServiceEnhanced.restore : "); + } else { + PerfTestUtils.out("Without WikittyServiceEnhanced.restore : "); + } + PerfTestUtils.out("1 thread took (average on " + loopsToAvg + " loops) " + (time / loopsToAvg) + " ms to do " + researches + + " researches on field " + searchIn + " in " + wikittiesCreated + " wikitties\n"); } /** @@ -102,37 +135,39 @@ */ public static void nThreadsSearch(WikittyService ws, WikittyExtension ext, int loopsToAvg, int researches, int wikittiesCreated, int threadsNb, String searchIn, String searched, boolean withRestore) { - List<PerfTestSearchThread> threads = new ArrayList<PerfTestSearchThread>(); - long time = System.currentTimeMillis(); - int threadMod = ((researches % threadsNb) != 0 ? 1 : 0); - - for (int j = 0; j < loopsToAvg; j++) { - for (int i = 0; i < threadsNb; i++) { - threads.add(new PerfTestSearchThread(researches / threadsNb, ws, ext, withRestore, searchIn, searched)); - } - if (threadMod == 1) { - threads.add(new PerfTestSearchThread(researches % threadsNb, ws, ext, withRestore, searchIn, searched)); - } - for (int i = 0; i < (threadsNb + threadMod); i++) { - threads.get(i).start(); - } - for (int i = 0; i < (threadsNb + threadMod); i++) { - try { - threads.get(i).join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - threads.clear(); - } - time = System.currentTimeMillis() - time; - if (withRestore) - PerfTestUtils.out("With WikittyServiceEnhanced.restore : "); - else - PerfTestUtils.out("Without WikittyServiceEnhanced.restore : "); - PerfTestUtils.out(threadsNb + (threadMod == 1 ? "(+1)" : "") + " threads took (average on " + loopsToAvg + " loops) " + (time / loopsToAvg) + - " ms to do " + (researches / threadsNb) + " researches each " + (threadMod == 1 ? "(+" + (researches % threadsNb) + " researches) " : "") + - "on field " + searchIn + " in " + wikittiesCreated + " wikitties\n"); + + List<PerfTestSearchThread> threads = new ArrayList<PerfTestSearchThread>(); + long time = System.currentTimeMillis(); + int threadMod = ((researches % threadsNb) != 0 ? 1 : 0); + + for (int j = 0; j < loopsToAvg; j++) { + for (int i = 0; i < threadsNb; i++) { + threads.add(new PerfTestSearchThread(researches / threadsNb, ws, ext, withRestore, searchIn, searched)); + } + if (threadMod == 1) { + threads.add(new PerfTestSearchThread(researches % threadsNb, ws, ext, withRestore, searchIn, searched)); + } + for (int i = 0; i < (threadsNb + threadMod); i++) { + threads.get(i).start(); + } + for (int i = 0; i < (threadsNb + threadMod); i++) { + try { + threads.get(i).join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + threads.clear(); + } + time = System.currentTimeMillis() - time; + if (withRestore) { + PerfTestUtils.out("With WikittyServiceEnhanced.restore : "); + } else { + PerfTestUtils.out("Without WikittyServiceEnhanced.restore : "); + } + PerfTestUtils.out(threadsNb + (threadMod == 1 ? "(+1)" : "") + " threads took (average on " + loopsToAvg + " loops) " + (time / loopsToAvg) + + " ms to do " + (researches / threadsNb) + " researches each " + (threadMod == 1 ? "(+" + (researches % threadsNb) + " researches) " : "") + + "on field " + searchIn + " in " + wikittiesCreated + " wikitties\n"); } /** @@ -150,7 +185,8 @@ */ public static void search(WikittyService ws, WikittyExtension ext, int loopsToAvg, int researches, int wikittiesCreated, int threadsNb, String searchIn, String searched, boolean withRestore) { - oneThreadSearch(ws, ext, loopsToAvg, researches, wikittiesCreated, searchIn, searched, withRestore); - nThreadsSearch(ws, ext, loopsToAvg, researches, wikittiesCreated, threadsNb, searchIn, searched, withRestore); + + oneThreadSearch(ws, ext, loopsToAvg, researches, wikittiesCreated, searchIn, searched, withRestore); + nThreadsSearch(ws, ext, loopsToAvg, researches, wikittiesCreated, threadsNb, searchIn, searched, withRestore); } } Modified: trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestUtils.java =================================================================== --- trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestUtils.java 2010-12-21 15:32:36 UTC (rev 639) +++ trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestUtils.java 2010-12-21 15:33:48 UTC (rev 640) @@ -1,7 +1,41 @@ +/* + * #%L + * Wikitty :: wikitty-perf-test + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ package org.nuiton.wikitty.perftest; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + public class PerfTestUtils { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(PerfTestUtils.class); + + // FIXME sletellier 21/12/10 : with not using directly log.info ? public static void out(Object msg) { - System.out.println(msg); + if (log.isInfoEnabled()) { + log.info(msg); + } } } Added: trunk/wikitty-perf-test/src/main/resources/log4j.properties =================================================================== --- trunk/wikitty-perf-test/src/main/resources/log4j.properties (rev 0) +++ trunk/wikitty-perf-test/src/main/resources/log4j.properties 2010-12-21 15:33:48 UTC (rev 640) @@ -0,0 +1,40 @@ +### +# #%L +# Wikitty :: wikitty-jdbc-impl +# +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2010 CodeLutin, Benjamin Poussin +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/lgpl-3.0.html>. +# #L% +### +# Global logging configuration +log4j.rootLogger=ERROR, stdout, file + +# Console output +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n + +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.file=vradi.log +log4j.appender.file.MaxFileSize=10MB +log4j.appender.file.MaxBackupIndex=4 +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %5p [%t] %c - %m%n + +log4j.logger.org.nuiton.wikitty.perftest=INFO
participants (1)
-
sletellier@users.nuiton.org