TransactionalCache: Ditch Apache Commons LRUMap in favour of a small LinkedHashMap-derived variant

- LRUMap creates a data array as large as the maximum on initialization
 - Added some profile-related tests for initialization to look for bottlenecks


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@20761 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-06-22 23:07:28 +00:00
parent 343de9efc9
commit 7af010cf14
2 changed files with 66 additions and 7 deletions

View File

@@ -391,6 +391,36 @@ public class CacheTest extends TestCase
}
}
/**
* Time how long it takes to create and complete a whole lot of transactions
*/
public void testInitializationPerformance() throws Exception
{
TransactionService transactionService = serviceRegistry.getTransactionService();
long start = System.nanoTime();
int count = 10000;
for (int i = 0; i < count; i++)
{
UserTransaction txn = transactionService.getUserTransaction();
try
{
txn.begin();
transactionalCache.contains("A");
}
finally
{
try { txn.rollback(); } catch (Throwable ee) {}
}
}
long end = System.nanoTime();
// report
System.out.println(
"Cache initialization performance test: \n" +
" count: " + count + "\n" +
" transaction: " + (end-start)/((long)count) + " ns\\count");
}
/**
* @see #testPerformance()
*/
@@ -400,7 +430,10 @@ public class CacheTest extends TestCase
{
CacheTest test = new CacheTest();
test.setUp();
System.out.println("Press any key to run test ...");
System.out.println("Press any key to run initialization test ...");
System.in.read();
test.testInitializationPerformance();
System.out.println("Press any key to run performance test ...");
System.in.read();
test.testPerformance();
System.out.println("Press any key to shutdown ...");