~maxb/connectorj/5.0

« back to all changes in this revision

Viewing changes to src/testsuite/perf/RetrievalPerfTest.java

  • Committer: mmatthews
  • Date: 2007-10-11 20:04:05 UTC
  • Revision ID: svn-v3-trunk0:bce1ec22-edf6-0310-a851-a6aae2aa6c29:branches%2Fbranch_5_0:6637
Changed layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 Copyright (C) 2002-2004 MySQL AB
 
3
 
 
4
 This program is free software; you can redistribute it and/or modify
 
5
 it under the terms of version 2 of the GNU General Public License as 
 
6
 published by the Free Software Foundation.
 
7
 
 
8
 There are special exceptions to the terms and conditions of the GPL 
 
9
 as it is applied to this software. View the full text of the 
 
10
 exception in file EXCEPTIONS-CONNECTOR-J in the directory of this 
 
11
 software distribution.
 
12
 
 
13
 This program is distributed in the hope that it will be useful,
 
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 GNU General Public License for more details.
 
17
 
 
18
 You should have received a copy of the GNU General Public License
 
19
 along with this program; if not, write to the Free Software
 
20
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
 
 
22
 
 
23
 
 
24
 */
 
25
package testsuite.perf;
 
26
 
 
27
import testsuite.BaseTestCase;
 
28
 
 
29
/**
 
30
 * Simplistic test for performance regression.
 
31
 * 
 
32
 * @author Mark Matthews
 
33
 */
 
34
public class RetrievalPerfTest extends BaseTestCase {
 
35
        // ~ Static fields/initializers
 
36
        // ---------------------------------------------
 
37
 
 
38
        private static final int NUM_TESTS = 10000;
 
39
 
 
40
        private static final int NUM_ROWS = 80;
 
41
 
 
42
        // ~ Constructors
 
43
        // -----------------------------------------------------------
 
44
 
 
45
        /**
 
46
         * Constructor for RetrievalPerfTest.
 
47
         * 
 
48
         * @param name
 
49
         *            name of the test to run
 
50
         */
 
51
        public RetrievalPerfTest(String name) {
 
52
                super(name);
 
53
        }
 
54
 
 
55
        // ~ Methods
 
56
        // ----------------------------------------------------------------
 
57
 
 
58
        /**
 
59
         * Runs all tests.
 
60
         * 
 
61
         * @param args
 
62
         *            ignored
 
63
         */
 
64
        public static void main(String[] args) {
 
65
                new RetrievalPerfTest("testRetrievalMyIsam").run();
 
66
                new RetrievalPerfTest("testRetrievalHeap").run();
 
67
                new RetrievalPerfTest("testRetrievalCached").run();
 
68
        }
 
69
 
 
70
        /**
 
71
         * @see junit.framework.TestCase#setUp()
 
72
         */
 
73
        public void setUp() throws Exception {
 
74
                super.setUp();
 
75
                this.stmt.executeUpdate("DROP TABLE IF EXISTS retrievalPerfTestHeap");
 
76
                this.stmt.executeUpdate("DROP TABLE IF EXISTS retrievalPerfTestMyIsam");
 
77
                this.stmt
 
78
                                .executeUpdate("CREATE TABLE retrievalPerfTestHeap (priKey INT NOT NULL PRIMARY KEY,"
 
79
                                                + "charField VARCHAR(80)) TYPE=HEAP");
 
80
                this.stmt
 
81
                                .executeUpdate("CREATE TABLE retrievalPerfTestMyIsam (priKey INT NOT NULL PRIMARY KEY,"
 
82
                                                + "charField VARCHAR(80)) TYPE=MyISAM");
 
83
 
 
84
                for (int i = 0; i < NUM_ROWS; i++) {
 
85
                        this.stmt
 
86
                                        .executeUpdate("INSERT INTO retrievalPerfTestHeap (priKey, charField) VALUES ("
 
87
                                                        + i
 
88
                                                        + ",'abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')");
 
89
                        this.stmt
 
90
                                        .executeUpdate("INSERT INTO retrievalPerfTestMyIsam (priKey, charField) VALUES ("
 
91
                                                        + i
 
92
                                                        + ",'abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')");
 
93
                }
 
94
        }
 
95
 
 
96
        /**
 
97
         * @see junit.framework.TestCase#tearDown()
 
98
         */
 
99
        public void tearDown() throws Exception {
 
100
                this.stmt.executeUpdate("DROP TABLE IF EXISTS retrievalPerfTestHeap");
 
101
                this.stmt.executeUpdate("DROP TABLE IF EXISTS retrievalPerfTestMyIsam");
 
102
                super.tearDown();
 
103
        }
 
104
 
 
105
        /**
 
106
         * Tests retrieval from the query cache
 
107
         * 
 
108
         * @throws Exception
 
109
         *             if an error occurs
 
110
         */
 
111
        public void testRetrievalCached() throws Exception {
 
112
                this.stmt.executeUpdate("SET QUERY_CACHE_TYPE = DEMAND");
 
113
 
 
114
                double fullBegin = System.currentTimeMillis();
 
115
                double averageQueryTimeMs = 0;
 
116
                double averageTraversalTimeMs = 0;
 
117
 
 
118
                for (int i = 0; i < NUM_TESTS; i++) {
 
119
                        long queryBegin = System.currentTimeMillis();
 
120
                        this.rs = this.stmt
 
121
                                        .executeQuery("SELECT SQL_CACHE * FROM retrievalPerfTestHeap");
 
122
 
 
123
                        long queryEnd = System.currentTimeMillis();
 
124
                        averageQueryTimeMs += ((double) (queryEnd - queryBegin) / NUM_TESTS);
 
125
 
 
126
                        long traverseBegin = System.currentTimeMillis();
 
127
 
 
128
                        while (this.rs.next()) {
 
129
                                this.rs.getInt(1);
 
130
                                this.rs.getString(2);
 
131
                        }
 
132
 
 
133
                        long traverseEnd = System.currentTimeMillis();
 
134
                        averageTraversalTimeMs += ((double) (traverseEnd - traverseBegin) / NUM_TESTS);
 
135
                }
 
136
 
 
137
                double fullEnd = System.currentTimeMillis();
 
138
                double fullTime = (fullEnd - fullBegin) / 1000;
 
139
                double queriesPerSec = NUM_TESTS / fullTime;
 
140
                double rowsPerSec = (NUM_ROWS * NUM_TESTS) / fullTime;
 
141
                System.out.println("\nQuery Cache From Heap Retrieval\n");
 
142
                System.out.println("Full test took: " + fullTime + " seconds.");
 
143
                System.out.println("Queries/second: " + queriesPerSec);
 
144
                System.out.println("Rows/second: " + rowsPerSec);
 
145
                System.out.println("Avg. Query Exec Time: " + averageQueryTimeMs
 
146
                                + " ms");
 
147
                System.out.println("Avg. Traversal Time: " + averageTraversalTimeMs
 
148
                                + " ms");
 
149
 
 
150
                // We're doing something wrong if we can't beat 45 seconds :(
 
151
                assertTrue(fullTime < 45);
 
152
        }
 
153
 
 
154
        /**
 
155
         * Tests retrieval from HEAP tables
 
156
         * 
 
157
         * @throws Exception
 
158
         *             if an error occurs
 
159
         */
 
160
        public void testRetrievalHeap() throws Exception {
 
161
                double fullBegin = System.currentTimeMillis();
 
162
                double averageQueryTimeMs = 0;
 
163
                double averageTraversalTimeMs = 0;
 
164
 
 
165
                for (int i = 0; i < NUM_TESTS; i++) {
 
166
                        long queryBegin = System.currentTimeMillis();
 
167
                        this.rs = this.stmt
 
168
                                        .executeQuery("SELECT * FROM retrievalPerfTestHeap");
 
169
 
 
170
                        long queryEnd = System.currentTimeMillis();
 
171
                        averageQueryTimeMs += ((double) (queryEnd - queryBegin) / NUM_TESTS);
 
172
 
 
173
                        long traverseBegin = System.currentTimeMillis();
 
174
 
 
175
                        while (this.rs.next()) {
 
176
                                this.rs.getInt(1);
 
177
                                this.rs.getString(2);
 
178
                        }
 
179
 
 
180
                        long traverseEnd = System.currentTimeMillis();
 
181
                        averageTraversalTimeMs += ((double) (traverseEnd - traverseBegin) / NUM_TESTS);
 
182
                }
 
183
 
 
184
                double fullEnd = System.currentTimeMillis();
 
185
                double fullTime = (fullEnd - fullBegin) / 1000;
 
186
                double queriesPerSec = NUM_TESTS / fullTime;
 
187
                double rowsPerSec = (NUM_ROWS * NUM_TESTS) / fullTime;
 
188
                System.out.println("\nHEAP Table Retrieval\n");
 
189
                System.out.println("Full test took: " + fullTime + " seconds.");
 
190
                System.out.println("Queries/second: " + queriesPerSec);
 
191
                System.out.println("Rows/second: " + rowsPerSec);
 
192
                System.out.println("Avg. Query Exec Time: " + averageQueryTimeMs
 
193
                                + " ms");
 
194
                System.out.println("Avg. Traversal Time: " + averageTraversalTimeMs
 
195
                                + " ms");
 
196
 
 
197
                // We're doing something wrong if we can't beat 45 seconds :(
 
198
                assertTrue(fullTime < 45);
 
199
        }
 
200
 
 
201
        /**
 
202
         * Tests retrieval speed from MyISAM type tables
 
203
         * 
 
204
         * @throws Exception
 
205
         *             if an error occurs
 
206
         */
 
207
        public void testRetrievalMyIsam() throws Exception {
 
208
                double fullBegin = System.currentTimeMillis();
 
209
                double averageQueryTimeMs = 0;
 
210
                double averageTraversalTimeMs = 0;
 
211
 
 
212
                for (int i = 0; i < NUM_TESTS; i++) {
 
213
                        long queryBegin = System.currentTimeMillis();
 
214
                        this.rs = this.stmt
 
215
                                        .executeQuery("SELECT * FROM retrievalPerfTestMyIsam");
 
216
 
 
217
                        long queryEnd = System.currentTimeMillis();
 
218
                        averageQueryTimeMs += ((double) (queryEnd - queryBegin) / NUM_TESTS);
 
219
 
 
220
                        long traverseBegin = System.currentTimeMillis();
 
221
 
 
222
                        while (this.rs.next()) {
 
223
                                this.rs.getInt(1);
 
224
                                this.rs.getString(2);
 
225
                        }
 
226
 
 
227
                        long traverseEnd = System.currentTimeMillis();
 
228
                        averageTraversalTimeMs += ((double) (traverseEnd - traverseBegin) / NUM_TESTS);
 
229
                }
 
230
 
 
231
                double fullEnd = System.currentTimeMillis();
 
232
                double fullTime = (fullEnd - fullBegin) / 1000;
 
233
                double queriesPerSec = NUM_TESTS / fullTime;
 
234
                double rowsPerSec = (NUM_ROWS * NUM_TESTS) / fullTime;
 
235
                System.out.println("\nMyIsam Retrieval\n");
 
236
                System.out.println("Full test took: " + fullTime + " seconds.");
 
237
                System.out.println("Queries/second: " + queriesPerSec);
 
238
                System.out.println("Rows/second: " + rowsPerSec);
 
239
                System.out.println("Avg. Query Exec Time: " + averageQueryTimeMs
 
240
                                + " ms");
 
241
                System.out.println("Avg. Traversal Time: " + averageTraversalTimeMs
 
242
                                + " ms");
 
243
 
 
244
                // We're doing something wrong if we can't beat 45 seconds :(
 
245
                assertTrue(fullTime < 45);
 
246
        }
 
247
}