r587 - in trunk: . wikitty-perf-test wikitty-perf-test/src wikitty-perf-test/src/main wikitty-perf-test/src/main/java wikitty-perf-test/src/main/java/org wikitty-perf-test/src/main/java/org/nuiton wikitty-perf-test/src/main/java/org/nuiton/wikitty wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest
Author: vbriand Date: 2010-12-09 16:14:22 +0100 (Thu, 09 Dec 2010) New Revision: 587 Url: http://nuiton.org/repositories/revision/wikitty/587 Log: Added wikitty-perf-test module Added: trunk/wikitty-perf-test/ trunk/wikitty-perf-test/LICENSE.txt trunk/wikitty-perf-test/README.txt trunk/wikitty-perf-test/changelog.txt trunk/wikitty-perf-test/pom.xml trunk/wikitty-perf-test/src/ trunk/wikitty-perf-test/src/main/ trunk/wikitty-perf-test/src/main/java/ trunk/wikitty-perf-test/src/main/java/org/ trunk/wikitty-perf-test/src/main/java/org/nuiton/ trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/ trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/ 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/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-12-09 11:26:31 UTC (rev 586) +++ trunk/pom.xml 2010-12-09 15:14:22 UTC (rev 587) @@ -30,6 +30,7 @@ <module>wikitty-ui-zk</module> <module>wikitty-hessian-client</module> <module>wikitty-hessian-server</module> + <module>wikitty-perf-test</module> </modules> Added: trunk/wikitty-perf-test/LICENSE.txt =================================================================== --- trunk/wikitty-perf-test/LICENSE.txt (rev 0) +++ trunk/wikitty-perf-test/LICENSE.txt 2010-12-09 15:14:22 UTC (rev 587) @@ -0,0 +1,166 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + Added: trunk/wikitty-perf-test/pom.xml =================================================================== --- trunk/wikitty-perf-test/pom.xml (rev 0) +++ trunk/wikitty-perf-test/pom.xml 2010-12-09 15:14:22 UTC (rev 587) @@ -0,0 +1,90 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.nuiton</groupId> + <artifactId>wikitty</artifactId> + <version>3.0-SNAPSHOT</version> + </parent> + + <groupId>org.nuiton.wikitty</groupId> + <artifactId>wikitty-perf-test</artifactId> + + <dependencies> + + <!-- sibling dependencies --> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>wikitty-api</artifactId> + <version>${project.version}</version> + </dependency> + + <!-- TEST --> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + <dependency> + <groupId>commons-dbcp</groupId> + <artifactId>commons-dbcp</artifactId> + </dependency> + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + + <dependency> + <groupId>javax.transaction</groupId> + <artifactId>jta</artifactId> + </dependency> + + <dependency> + <groupId>jboss.jbossts</groupId> + <artifactId>jbossjta</artifactId> + </dependency> + + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-utils</artifactId> + </dependency> + + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> + </dependencies> + + <!-- ************************************************************* --> + <!-- *** Project Information ************************************* --> + <!-- ************************************************************* --> + <name>Wikitty :: wikitty-perf-test</name> + <description>Wikitty performance tests</description> + <inceptionYear>2010</inceptionYear> +</project> \ No newline at end of file Added: 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 (rev 0) +++ trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTest.java 2010-12-09 15:14:22 UTC (rev 587) @@ -0,0 +1,100 @@ +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.nuiton.wikitty.WikittyProxy; +import org.nuiton.wikitty.WikittyConfig; +import org.nuiton.wikitty.WikittyService; +import org.nuiton.wikitty.WikittyServiceFactory; + +import org.nuiton.wikitty.entities.Wikitty; +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; + +public class PerfTest { + 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; + + 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); + } + + 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("== 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("== 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 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"); + } + } +} Added: 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 (rev 0) +++ trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestLabelAdd.java 2010-12-09 15:14:22 UTC (rev 587) @@ -0,0 +1,89 @@ +package org.nuiton.wikitty.perftest; + +import java.util.ArrayList; +import java.util.List; +import org.nuiton.wikitty.WikittyProxy; +import org.nuiton.wikitty.addons.WikittyLabelUtil; + +public class PerfTestLabelAdd { + private static class PerfTestLabelAddThread extends Thread { + 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; + } + + @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); + } + } + } + + /** + * Adds labels on the wikitties ids and stores them in the proxy + * + * @param proxy : the WikittyProxy to add labels in + * @param ids : the wikitties ids to add labels on + * @param loopsToAvg : the number of times the labels will be added in order to give a more accurate result + * @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(); + + 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>(); + + 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"); + } +} Added: 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 (rev 0) +++ trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestLabelSearch.java 2010-12-09 15:14:22 UTC (rev 587) @@ -0,0 +1,101 @@ +package org.nuiton.wikitty.perftest; + +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 { + private static class PerfTestLabelSearchThread extends Thread { + 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; + } + + @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); + } + } + } + + /** + * Searches all labels applied to a wikitty and then retrieves the wikitties associated with these labels + * + * @param proxy : the WikittyProxy to search in + * @param ids : the wikitties ids to search labels on + * @param loopsToAvg : the number of times the searches will be made in order to give a more accurate result + * @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>(); + + 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"); + + 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"); + } +} Added: 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 (rev 0) +++ trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestSearch.java 2010-12-09 15:14:22 UTC (rev 587) @@ -0,0 +1,156 @@ +package org.nuiton.wikitty.perftest; + +import java.util.ArrayList; +import java.util.List; + +import org.nuiton.wikitty.WikittyService; +import org.nuiton.wikitty.entities.Wikitty; +import org.nuiton.wikitty.entities.WikittyExtension; +import org.nuiton.wikitty.search.Criteria; +import org.nuiton.wikitty.search.PagedResult; +import org.nuiton.wikitty.search.Search; +import org.nuiton.wikitty.services.WikittyServiceEnhanced; + +public class PerfTestSearch { + 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; + } + + @Override + public void run() { + searchGt(researches, ws, ext, searchIn, searched, withRestore); + } + } + + /** + * Searches everything greater than the value `searched` in the field `searchIn` + * + * @param researches : the number of researches to do + * @param ws : the wikitty service + * @param ext : the wikitty extension + * @param searchIn : the field name + * @param searched : the field value to search + * @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); + } + } + } + } + + /** + * Searches with one thread and then displays the result + * + * @param ws : the wikitty service + * @param ext : the wikitty extension + * @param loopsToAvg : the number of times the labels searches will be made in order to give a more accurate result + * @param researches : the number of researches + * @param wikittiesCreated : the number of wikitties in the proxy + * @param searchIn : the field name + * @param searched : the field value to search + * @param withRestore : if the wikitty will be restored after the search + */ + 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"); + } + + /** + * Searches with n threads and then displays the result + * + * @param ws : the wikitty service + * @param ext : the wikitty extension + * @param loopsToAvg : the number of times the labels searches will be made in order to give a more accurate result + * @param researches : the number of researches + * @param wikittiesCreated : the number of wikitties in the proxy + * @param threadsNb : the number of threads that will be created to do a part of the search + * @param searchIn : the field name + * @param searched : the field value to search + * @param withRestore : if the wikitty will be restored after the search + */ + 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"); + } + + /** + * Launches the searches with one thread and then with n threads + * + * @param ws : the wikitty service + * @param ext : the wikitty extension + * @param loopsToAvg : the number of times the labels searches will be made in order to give a more accurate result + * @param researches : the number of researches + * @param wikittiesCreated : the number of wikitties in the proxy + * @param threadsNb : the number of threads that will be created to do a part of the search + * @param searchIn : the field name + * @param searched : the field value to search + * @param withRestore : if the wikitty will be restored after the search + */ + 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); + } +} Added: 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 (rev 0) +++ trunk/wikitty-perf-test/src/main/java/org/nuiton/wikitty/perftest/PerfTestUtils.java 2010-12-09 15:14:22 UTC (rev 587) @@ -0,0 +1,7 @@ +package org.nuiton.wikitty.perftest; + +public class PerfTestUtils { + public static void out(Object msg) { + System.out.println(msg); + } +}
participants (1)
-
vbriand@users.nuiton.org