KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > prevayler > demos > scalability > Main


1 package org.prevayler.demos.scalability;
2
3 import org.prevayler.demos.scalability.prevayler.*;
4 import org.prevayler.demos.scalability.jdbc.*;
5
6 import java.io.*;
7 import java.util.*;
8
9 public class Main {
10
11     static private final Properties properties = new Properties();
12
13
14     static public void main(String JavaDoc[] args) {
15
16         out("\n=============================================================");
17         out( " Prevayler vs JDBC Scalability Tests ");
18         out( "=============================================================\n");
19         out("If you have any trouble running the tests, just write to");
20         out("prevayler-scalability@lists.sourceforge.net and we will be glad to help.\n");
21
22         try {
23             out("Reading the properties file:\n" + propertiesFile().getAbsolutePath());
24             out("You can edit this file to configure the tests for the next run.\n");
25
26             properties.load(new FileInputStream(propertiesFile()));
27
28             if (isPrevaylerQueryChosen()) runPrevaylerQuery();
29             if (isPrevaylerTransactionChosen()) runPrevaylerTransaction();
30             if (isJdbcQueryChosen()) runJdbcQuery();
31             if (isJdbcTransactionChosen()) runJdbcTransaction();
32
33             out("\n\n\nFor better results, edit the properties file:");
34             out(propertiesFile().getAbsolutePath());
35             out("\nYou can publish your best results by mail to:");
36             out("prevayler-scalability@lists.sourceforge.net. Please include info about your");
37             out("processors (quantity, type, speed), compiler, VM, operating system and DBMS.");
38             out("");
39             out("Scalability test results are published on www.prevayler.org.");
40             out("See you there.\n");
41             out("Klaus Wuestefeld and Daniel Santos.\n\n");
42
43         } catch (Exception JavaDoc ex) {
44             ex.printStackTrace();
45         } catch (OutOfMemoryError JavaDoc err) {
46             ScalabilityTestRun.outOfMemory();
47         }
48
49     }
50
51
52     static private void runPrevaylerQuery() throws Exception JavaDoc {
53         new QueryTestRun(
54             new PrevaylerQuerySubject(),
55             numberOfObjects(),
56             prevaylerQueryThreadsMin(),
57             prevaylerQueryThreadsMax()
58         );
59     }
60
61     static private void runPrevaylerTransaction() throws Exception JavaDoc {
62         PrevaylerTransactionSubject subject = new PrevaylerTransactionSubject(prevaylerTransactionLogDirectory());
63         new TransactionTestRun(
64             subject,
65             numberOfObjects(),
66             prevaylerTransactionThreadsMin(),
67             prevaylerTransactionThreadsMax()
68         );
69         if (isPrevaylerTransactionConsistencyChecked()) {
70             out("Checking transaction log consistency.");
71             if (!subject.isConsistent()) throw new RuntimeException JavaDoc("Transaction log consistency check failed.");
72             out("Transaction log OK.\n");
73         }
74     }
75
76     static private void runJdbcQuery() {
77         new QueryTestRun(
78             new JDBCQuerySubject(jdbcDriverClassName(), jdbcConnectionURL(), jdbcUser(), jdbcPassword()),
79             numberOfObjects(),
80             jdbcQueryThreadsMin(),
81             jdbcQueryThreadsMax()
82         );
83     }
84
85     static private void runJdbcTransaction() {
86         new TransactionTestRun(
87             new JDBCTransactionSubject(jdbcDriverClassName(), jdbcConnectionURL(), jdbcUser(), jdbcPassword()),
88             numberOfObjects(),
89             jdbcTransactionThreadsMin(),
90             jdbcTransactionThreadsMax()
91         );
92     }
93
94
95     static private File propertiesFile() throws IOException {
96         File result = new File("ScalabilityTest.properties");
97         if (!result.exists()) {
98             out("Creating the properties file.");
99             createPropertiesFile(result);
100         }
101         return result;
102     }
103
104     static private void createPropertiesFile(File file) throws IOException {
105         PrintStream stream = new PrintStream(new FileOutputStream(file));
106         stream.println(
107             "###########################################################\n" +
108             "# #\n" +
109             "# PREVAYLER VS JDBC SCALABILITY TEST PROPERTIES #\n" +
110             "# #\n" +
111             "###########################################################\n" +
112             "\n" +
113             "NumberOfObjects = ONE_HUNDRED_THOUSAND\n" +
114             "# NumberOfObjects = ONE_MILLION\n" +
115             "# NumberOfObjects = TEN_MILLION\n" +
116             "# NumberOfObjects = TWENTY_MILLION\n" +
117             "#\n" +
118             "# The results are only valid if both Prevayler and the\n" +
119             "# database can run the tests without paging memory to disk.\n" +
120             "#\n" +
121             "# Running the tests with one hundred thousand objects\n" +
122             "# (default option) requires approx. 128MB free RAM.\n" +
123             "# The VM must be started with a sufficient maximum heap" +
124             "# size or you will get an OutOfMemoryError.\n" +
125             "# Example for Linux and Windows: java -Xmx128000000 ...\n" +
126             "#\n" +
127             "# Running the tests with one million objects requires\n" +
128             "# approx. 940MB free RAM." +
129             "# Running the tests with ten million objects requires\n" +
130             "# approx. 9.4GB free RAM and a 64bit VM.\n" +
131             "#\n" +
132             "# IMPORTANT: Remember to shutdown all other non-vital\n" +
133             "# processes before running the tests. Even the database\n" +
134             "# process should be down while running the Prevayler tests\n" +
135             "# that do not use it.\n" +
136             "\n" +
137             "\n" +
138             "###########################################################\n" +
139             "# PREVAYLER QUERY TEST\n" +
140             "\n" +
141             "RunPrevaylerQueryTest = YES\n" +
142             "# RunPrevaylerQueryTest = NO\n" +
143             "\n" +
144             "PrevaylerQueryThreadsMinimum = 1\n" +
145             "PrevaylerQueryThreadsMaximum = 5\n" +
146             "# More threads can produce better results on\n" +
147             "# multi-processor machines.\n" +
148             "\n" +
149             "\n" +
150             "###########################################################\n" +
151             "# PREVAYLER TRANSACTION TEST\n" +
152             "\n" +
153             "RunPrevaylerTransactionTest = YES\n" +
154             "# RunPrevaylerTransactionTest = NO\n" +
155             "\n" +
156             "PrevaylerTransactionThreadsMinimum = 1\n" +
157             "PrevaylerTransactionThreadsMaximum = 5\n" +
158             "#\n" +
159             "# More threads can produce better results on machines with\n" +
160             "# multiple disks.\n" +
161             "\n" +
162             "TransactionTestCheckConsistency = YES\n" +
163             "# TransactionTestCheckConsistency = NO\n" +
164             "#\n" +
165             "# Verifies the integrity of the journal files produced in\n" +
166             "# your particular environment.\n" +
167             "\n" +
168             "TransactionLogDirectory = TransactionTest\n" +
169             "#\n" +
170             "# The full path name can be used. Example for Windows:\n" +
171             "# TransactionLogDirectory1 = c:\\\\temp\\\\TransactionTest\n" +
172             "# The back-slash (\\) is the escape character so you must\n" +
173             "# use two back-slashes (\\\\).\n" +
174             "\n" +
175             "\n" +
176             "###########################################################\n" +
177             "# JDBC QUERY TEST\n" +
178             "\n" +
179             "RunJdbcQueryTest = NO\n" +
180             "# RunJdbcQueryTest = YES\n" +
181             "\n" +
182             "JdbcQueryThreadsMinimum = 1\n" +
183             "JdbcQueryThreadsMaximum = 5\n" +
184             "# More threads can produce better results on some machines.\n" +
185             "\n" +
186             "\n" +
187             "###########################################################\n" +
188             "# JDBC TRANSACTION TEST\n" +
189             "\n" +
190             "RunJdbcTransactionTest = NO\n" +
191             "# RunJdbcTransactionTest = YES\n" +
192             "\n" +
193             "JdbcTransactionThreadsMinimum = 1\n" +
194             "JdbcTransactionThreadsMaximum = 5\n" +
195             "# More threads can produce better results on some machines.\n" +
196             "\n" +
197             "\n" +
198             "###########################################################\n" +
199             "# JDBC CONNECTION\n" +
200             "# (necessary to run the JDBC tests)\n" +
201             "\n" +
202             "JdbcDriverClassName =\n" +
203             "JdbcConnectionURL =\n" +
204             "JdbcUser =\n" +
205             "JdbcPassword =\n" +
206             "# These two tables are necessary for the JDBC tests:\n" +
207             "# QUERY_TEST and TRANSACTION_TEST.\n" +
208             "# Both tables have the same column structure:\n" +
209             "# ID DECIMAL,\n" +
210             "# NAME VARCHAR2(8),\n" +
211             "# STRING1 VARCHAR2(1000),\n" +
212             "# BIGDECIMAL1 DECIMAL,\n" +
213             "# BIGDECIMAL2 DECIMAL,\n" +
214             "# DATE1 DATE,\n" +
215             "# DATE2 DATE.\n" +
216             "\n" +
217             "# IMPORTANT: For best results, create indices on the\n" +
218             "# QUERY_TEST.NAME and TRANSACTION_TEST.ID columns.\n" +
219             "# Do not create indices on any other column.\n"
220         );
221     }
222
223
224     static private int numberOfObjects() {
225         String JavaDoc property = property("NumberOfObjects");
226         if ("ONE_HUNDRED_THOUSAND".equals(property)) return 100000;
227         if ("ONE_MILLION" .equals(property)) return 1000000;
228         if ("TEN_MILLION" .equals(property)) return 10000000;
229         if ("TWENTY_MILLION" .equals(property)) return 20000000;
230         throw new RuntimeException JavaDoc("NumberOfObjects property must be equal to ONE_HUNDRED_THOUSAND, ONE_MILLION, TEN_MILLION or TWENTY_MILLION.");
231     }
232
233     static private boolean isPrevaylerQueryChosen() {
234         return booleanProperty("RunPrevaylerQueryTest");
235     }
236
237     static private int prevaylerQueryThreadsMin() {
238         return intProperty("PrevaylerQueryThreadsMinimum");
239     }
240
241     static private int prevaylerQueryThreadsMax() {
242         return intProperty("PrevaylerQueryThreadsMaximum");
243     }
244
245
246     static private boolean isPrevaylerTransactionChosen() {
247         return booleanProperty("RunPrevaylerTransactionTest");
248     }
249
250     static private int prevaylerTransactionThreadsMin() {
251         return intProperty("PrevaylerTransactionThreadsMinimum");
252     }
253
254     static private int prevaylerTransactionThreadsMax() {
255         return intProperty("PrevaylerTransactionThreadsMaximum");
256     }
257
258     static private boolean isPrevaylerTransactionConsistencyChecked() {
259         return booleanProperty("TransactionTestCheckConsistency");
260     }
261     
262     static private String JavaDoc prevaylerTransactionLogDirectory() {
263         String JavaDoc result = property("TransactionLogDirectory");
264         out("\n\nPrevayler TransactionLog Directory: " + result);
265         return result;
266     }
267
268     static private boolean isJdbcQueryChosen() {
269         return booleanProperty("RunJdbcQueryTest");
270     }
271
272     static private int jdbcQueryThreadsMin() {
273         return intProperty("JdbcQueryThreadsMinimum");
274     }
275
276     static private int jdbcQueryThreadsMax() {
277         return intProperty("JdbcQueryThreadsMaximum");
278     }
279
280
281     static private boolean isJdbcTransactionChosen() {
282         return booleanProperty("RunJdbcTransactionTest");
283     }
284
285     static private int jdbcTransactionThreadsMin() {
286         return intProperty("JdbcTransactionThreadsMinimum");
287     }
288
289     static private int jdbcTransactionThreadsMax() {
290         return intProperty("JdbcTransactionThreadsMaximum");
291     }
292
293
294     static private String JavaDoc jdbcDriverClassName() {
295         return property("JdbcDriverClassName");
296     }
297
298     static private String JavaDoc jdbcConnectionURL() {
299         return property("JdbcConnectionURL");
300     }
301
302     static private String JavaDoc jdbcUser() {
303         return property("JdbcUser");
304     }
305
306     static private String JavaDoc jdbcPassword() {
307         return property("JdbcPassword");
308     }
309
310
311     static private String JavaDoc property(String JavaDoc name) {
312         String JavaDoc result = properties.getProperty(name);
313         if (result == null) throw new RuntimeException JavaDoc("Property " + name + " not found.");
314         return result;
315     }
316
317     static private int intProperty(String JavaDoc name) {
318         try {
319             return Integer.valueOf(property(name)).intValue();
320         } catch (NumberFormatException JavaDoc nfx) {
321             out("NumberFormatException reading property " + name);
322             throw nfx;
323         }
324     }
325
326     static private boolean booleanProperty(String JavaDoc name) {
327         boolean result = "yes".equalsIgnoreCase(property(name));
328         if (result) return true;
329         out("\n\n\n" + name + " property is set to " + property(name) + ".");
330         out("This test will be skipped (see properties file).");
331         return false;
332     }
333
334
335     static private void out(Object JavaDoc message) {
336         System.out.println(message);
337     }
338 }
339
Popular Tags