/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package org.apache.catalina.session;
privatevoid doTestManagerBaseGenerateSessionId(int threadCount, int iterCount) throws Exception {
// Create a default session manager
StandardManager mgr = new StandardManager(); try {
mgr.startInternal();
} catch (LifecycleException e) { // Ignore - this is expected
}
mgr.generateSessionId(); while (mgr.sessionCreationTiming.size() <
ManagerBase.TIMING_STATS_CACHE_SIZE) {
mgr.sessionCreationTiming.add(null);
} while (mgr.sessionExpirationTiming.size() <
ManagerBase.TIMING_STATS_CACHE_SIZE) {
mgr.sessionExpirationTiming.add(null);
}
Thread[] threads = newThread[threadCount];
for (int i = 0; i < threadCount; i++) {
threads[i] = newThread( new TestThreadGenerateSessionId(mgr, iterCount));
}
long start = System.currentTimeMillis();
for (int i = 0; i < threadCount; i++) {
threads[i].start();
} for (int i = 0; i < threadCount; i++) { try {
threads[i].join();
} catch (InterruptedException e) {
e.printStackTrace(); Assert.fail(e.getMessage());
}
} long end = System.currentTimeMillis();
StringBuilder result = new StringBuilder();
result.append("Threads: ");
result.append(threadCount);
result.append(", Time(ms): ");
result.append(end-start);
System.out.println(result.toString());
}
@Override publicvoid run() { for (int i = 0; i < count; i++) {
mgr.generateSessionId();
}
}
}
/* * Results on markt's 4-core Windows dev box * 1 thread - ~3,800ms * 2 threads - ~6,700ms * 4 threads - ~11,000ms * 16 threads - ~43,500ms * * Results on markt's 2-core OSX dev box * 1 thread - ~4,100ms * 2 threads - ~5,700ms * 4 threads - ~11,700ms * 16 threads - ~45,600ms
*/
@Test publicvoid testManagerBaseCreateSession() throws LifecycleException {
doTestManagerBaseCreateSession(1, 100000);
doTestManagerBaseCreateSession(2, 1000000);
doTestManagerBaseCreateSession(4, 1000000);
doTestManagerBaseCreateSession(16, 1000000); // Reduce iterations as context switching will slow things down
doTestManagerBaseCreateSession(100, 100000);
doTestManagerBaseCreateSession(400, 10000);
}
privatevoid doTestManagerBaseCreateSession(int threadCount, int iterCount) throws LifecycleException {
// Create a default session manager
StandardManager mgr = new StandardManager();
mgr.setPathname(null);
Host host = new StandardHost();
host.setName("unittest");
Context context = new StandardContext();
context.setPath("");
context.setParent(host);
mgr.setContext(context);
mgr.start();
mgr.generateSessionId(); while (mgr.sessionCreationTiming.size() <
ManagerBase.TIMING_STATS_CACHE_SIZE) {
mgr.sessionCreationTiming.add(null);
} while (mgr.sessionExpirationTiming.size() <
ManagerBase.TIMING_STATS_CACHE_SIZE) {
mgr.sessionExpirationTiming.add(null);
}
Thread[] threads = newThread[threadCount];
for (int i = 0; i < threadCount; i++) {
threads[i] = newThread( new TestThreadCreateSession(mgr, iterCount));
}
long start = System.currentTimeMillis();
for (int i = 0; i < threadCount; i++) {
threads[i].start();
} for (int i = 0; i < threadCount; i++) { try {
threads[i].join();
} catch (InterruptedException e) {
e.printStackTrace(); Assert.fail(e.getMessage());
}
} long end = System.currentTimeMillis();
StringBuilder result = new StringBuilder();
result.append("Threads: ");
result.append(threadCount);
result.append(", Time(ms): ");
result.append(end-start);
System.out.println(result.toString());
}
privatevoid doTestSecureRandomVsDevURandomInner(int threadCount, int iterCount, boolean useSecureRandom) throws Exception {
Thread[] threads = newThread[threadCount];
for (int i = 0; i < threadCount; i++) { if (useSecureRandom) {
threads[i] = newThread(new TestThreadSecureRandom(iterCount));
} else {
threads[i] = newThread(new TestThreadDevUrandom(iterCount));
}
}
long start = System.currentTimeMillis();
for (int i = 0; i < threadCount; i++) {
threads[i].start();
} for (int i = 0; i < threadCount; i++) { try {
threads[i].join();
} catch (InterruptedException e) {
e.printStackTrace(); Assert.fail(e.getMessage());
}
} long end = System.currentTimeMillis();
StringBuilder result = new StringBuilder(); if (useSecureRandom) {
result.append("SecureRandom ");
} else {
result.append("/dev/urandom ");
}
result.append("Threads: ");
result.append(threadCount);
result.append(", Time(ms): ");
result.append(end-start);
System.out.println(result.toString());
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.