From c966c1d730278d37536b8b10445f8c2525bd5b14 Mon Sep 17 00:00:00 2001 From: AionJayT Date: Tue, 3 Mar 2020 15:57:03 -0500 Subject: [PATCH] Downsized the txpool/cachePool test scales --- .../pendingState/v1/PendingTxCacheV1.java | 13 ++++- .../pendingState/v1/PendingTxCacheV1Test.java | 33 ++++++------- .../test/org/aion/txpool/v1/TxPoolV1Test.java | 18 +++---- .../txpool/v1/TxnPoolV1BenchmarkTest.java | 48 ++++++------------- 4 files changed, 49 insertions(+), 63 deletions(-) diff --git a/modAionImpl/src/org/aion/zero/impl/pendingState/v1/PendingTxCacheV1.java b/modAionImpl/src/org/aion/zero/impl/pendingState/v1/PendingTxCacheV1.java index 528da618c2..3f42114d0a 100644 --- a/modAionImpl/src/org/aion/zero/impl/pendingState/v1/PendingTxCacheV1.java +++ b/modAionImpl/src/org/aion/zero/impl/pendingState/v1/PendingTxCacheV1.java @@ -31,7 +31,7 @@ */ public final class PendingTxCacheV1 { - public static final int ACCOUNT_CACHE_MAX = 2_000; + static int ACCOUNT_CACHE_MAX = 2_000; public static final int TX_PER_ACCOUNT_MAX = 500; public static final int CACHE_TIMEOUT = 3_600; private static final Logger LOG = AionLoggerFactory.getLogger(LogEnum.TX.name()); @@ -58,6 +58,17 @@ public PendingTxCacheV1(boolean backupTransactions) { removedTransactionForPoolBackup = backupTransactions ? new ArrayList<>() : null; } + @VisibleForTesting + /** + * the constructor for the unit test + */ + public PendingTxCacheV1(int accountMax) { + ACCOUNT_CACHE_MAX = accountMax; + cacheTxMap = new LinkedHashMap<>(ACCOUNT_CACHE_MAX); + timeOutMap = new TreeMap<>(); + removedTransactionForPoolBackup = null; + } + private static long getExpiredTime(long longValue) { return TimeUnit.MICROSECONDS.toSeconds(longValue) + CACHE_TIMEOUT; } diff --git a/modAionImpl/test/org/aion/zero/impl/pendingState/v1/PendingTxCacheV1Test.java b/modAionImpl/test/org/aion/zero/impl/pendingState/v1/PendingTxCacheV1Test.java index 02b71cd64c..1a738e86fa 100644 --- a/modAionImpl/test/org/aion/zero/impl/pendingState/v1/PendingTxCacheV1Test.java +++ b/modAionImpl/test/org/aion/zero/impl/pendingState/v1/PendingTxCacheV1Test.java @@ -24,12 +24,13 @@ public class PendingTxCacheV1Test { private static List key; + private static int ACCOUNT_MAX = 10; @Before public void Setup() { ECKeyFac.setType(ECKeyFac.ECKeyType.ED25519); - int keyCnt = 2_001; + int keyCnt = ACCOUNT_MAX + 1; System.out.println("gen key list----------------"); if (key == null) { key = new ArrayList<>(); @@ -68,7 +69,7 @@ private List getMockTransaction(int startNonce, int num, int ke @Test public void addCacheTxTest() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); List txn = getMockTransaction(0, 10, 0); for (AionTransaction tx : txn) { @@ -81,7 +82,7 @@ public void addCacheTxTest() { @Test public void addCacheTxWith2SendersTest() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); List txn = getMockTransaction(0, 10, 0); txn.addAll(getMockTransaction(0, 10, 1)); @@ -97,7 +98,7 @@ public void addCacheTxWith2SendersTest() { @Test public void addCacheTxReachAccountCacheMaxTest() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); List txn = new ArrayList<>(); for (int i = 0; i < key.size(); i++) { @@ -114,7 +115,7 @@ public void addCacheTxReachAccountCacheMaxTest() { @Test public void addTxReachAccountCacheMaxTest() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); List txn = getMockTransaction(0, 500, 0); for (AionTransaction tx : txn) { cache.addCacheTx(tx); @@ -135,7 +136,7 @@ public void addTxReachAccountCacheMaxTest() { @Test public void addCacheTxWithDuplicateNonceTransactionsTest() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); List txn = getMockTransaction(0, 10, 0); txn.addAll(getMockTransaction(5, 10, 0)); @@ -153,7 +154,7 @@ public void addCacheTxWithDuplicateNonceTransactionsTest() { @Test public void flush2TxInOneAccountTest() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); List txn = getMockTransaction(0, 10, 0); List newCache; @@ -177,7 +178,7 @@ public void flush2TxInOneAccountTest() { @Test public void flushTxWithOtherAccountTest() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); List txn = getMockTransaction(0, 10, 0); @@ -200,7 +201,7 @@ public void flushTxWithOtherAccountTest() { @Test public void flushTxWith2AccountsTest() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); List txn = getMockTransaction(0, 10, 0); txn.addAll(getMockTransaction(0, 10, 1)); @@ -227,7 +228,7 @@ public void flushTxWith2AccountsTest() { @Test public void fullFlush2SendersUnderFullCachedInstanceTest() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); List txn = new ArrayList<>(); for (int i = 0; i < ACCOUNT_CACHE_MAX; i++) { @@ -261,7 +262,7 @@ public void fullFlush2SendersUnderFullCachedInstanceTest() { @Test public void getRemovedTxHashWithoutPoolBackupTest() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); assertNotNull(cache.pollRemovedTransactionForPoolBackup()); } @@ -329,7 +330,7 @@ public void clearRemovedTxHashForPoolBackupTest() { @Test public void benchmark() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); System.out.println("Gen 1M txs"); List txn = new ArrayList<>(); @@ -373,7 +374,7 @@ public void benchmark() { @Test public void isInCacheTest() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); List txn = getMockTransaction(0, 1, 0); for (AionTransaction tx : txn) { @@ -388,7 +389,7 @@ public void isInCacheTest() { @Test public void getNewPendingTransactionTest() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); List txn = getMockTransaction(0, 5, 0); List txn2 = getMockTransaction(0, 5, 1); @@ -419,7 +420,7 @@ public void getNewPendingTransactionTest() { @Test public void removeTransactionTest() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); List txn = getMockTransaction(0, 2, 0); for (AionTransaction tx : txn) { @@ -447,7 +448,7 @@ public void removeTransactionTest() { @Test public void flushTimeoutTransactionTest() { - PendingTxCacheV1 cache = new PendingTxCacheV1(); + PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX); List txn = getMockTransaction(0, 2, 0); for (AionTransaction tx : txn) { diff --git a/modTxPool/test/org/aion/txpool/v1/TxPoolV1Test.java b/modTxPool/test/org/aion/txpool/v1/TxPoolV1Test.java index 670a74211b..3b63c505e0 100644 --- a/modTxPool/test/org/aion/txpool/v1/TxPoolV1Test.java +++ b/modTxPool/test/org/aion/txpool/v1/TxPoolV1Test.java @@ -54,7 +54,7 @@ public void Setup() { } if (key2 == null) { - keyCnt = 10000; + keyCnt = 10; key2 = new ArrayList<>(); System.out.println("gen key list 2--------------"); for (int i = 0; i < keyCnt; i++) { @@ -878,7 +878,7 @@ public void feemapTest() { TxPoolV1 tp = new TxPoolV1(config); List txnl = new ArrayList<>(); - int cnt = 100; + int cnt = 10; byte[] nonce = new byte[Long.BYTES]; for (int i = 0; i < cnt; i++) { nonce[Long.BYTES - 1] = (byte) i; @@ -907,7 +907,7 @@ public void feemapTest() { List nl = tp.getFeeList(); assertEquals(cnt, nl.size()); - long val = 100; + long val = 10; for (int i = 0; i < cnt; i++) { Assert.assertEquals(0, nl.get(i).compareTo(val--)); } @@ -915,14 +915,12 @@ public void feemapTest() { @Test public void testSnapshotAll() { - ECKeyFac.setType(ECKeyFac.ECKeyType.ED25519); - ECKey key = ECKeyFac.inst().create(); List txs = new ArrayList<>(); for (int i = 0; i < 1000; i++) { AionTransaction tx = AionTransaction.create( - key, + key.get(0), BigInteger.valueOf(i).toByteArray(), AddressUtils.wrapAddress( "0000000000000000000000000000000000000000000000000000000000000001"), @@ -950,14 +948,12 @@ public void testSnapshotAll() { @Test public void testSnapshotAll2() { - ECKeyFac.setType(ECKeyFac.ECKeyType.ED25519); - ECKey key = ECKeyFac.inst().create(); List txs = new ArrayList<>(); for (int i = 0; i < 17; i++) { AionTransaction tx = AionTransaction.create( - key, + key.get(0), BigInteger.valueOf(i).toByteArray(), AddressUtils.wrapAddress( "0000000000000000000000000000000000000000000000000000000000000001"), @@ -981,14 +977,12 @@ public void testSnapshotAll2() { @Test public void testRemove2() { - ECKeyFac.setType(ECKeyFac.ECKeyType.ED25519); - ECKey key = ECKeyFac.inst().create(); List txs = new ArrayList<>(); for (int i = 0; i < 95; i++) { AionTransaction tx = AionTransaction.create( - key, + key.get(0), BigInteger.valueOf(i).toByteArray(), AddressUtils.wrapAddress( "0000000000000000000000000000000000000000000000000000000000000001"), diff --git a/modTxPool/test/org/aion/txpool/v1/TxnPoolV1BenchmarkTest.java b/modTxPool/test/org/aion/txpool/v1/TxnPoolV1BenchmarkTest.java index f948f2ba11..897ba9af68 100644 --- a/modTxPool/test/org/aion/txpool/v1/TxnPoolV1BenchmarkTest.java +++ b/modTxPool/test/org/aion/txpool/v1/TxnPoolV1BenchmarkTest.java @@ -22,7 +22,6 @@ public class TxnPoolV1BenchmarkTest { private List key; - private List key2; private Random r = new Random(); @Before @@ -38,29 +37,18 @@ public void Setup() { } System.out.println("gen key list finished-------"); } - - if (key2 == null) { - keyCnt = 10000; - key2 = new ArrayList<>(); - System.out.println("gen key list 2--------------"); - for (int i = 0; i < keyCnt; i++) { - key2.add(ECKeyFac.inst().create()); - } - System.out.println("gen key list 2 finished-----"); - } } - /* 100K new transactions in pool around 1200ms (cold-call)*/ @Test public void benchmarkSnapshot() { Properties config = new Properties(); config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100"); - config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "100000"); + config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "10000"); TxPoolV1 tp = new TxPoolV1(config); List txnl = new ArrayList<>(); - int cnt = 10000; + int cnt = 1000; for (ECKey aKey1 : key) { for (int i = 0; i < cnt; i++) { AionTransaction txn = @@ -97,18 +85,15 @@ public void benchmarkSnapshot() { } @Test - /* 100K new transactions in pool around 650ms (cold-call) - 1K new transactions insert to the pool later around 150ms to snap (including sort) - */ public void benchmarkSnapshot2() { Properties config = new Properties(); config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100"); - config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "101000"); + config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "10100"); TxPoolV1 tp = new TxPoolV1(config); List txnl = new ArrayList<>(); - int cnt = 10000; + int cnt = 1000; for (ECKey aKey2 : key) { for (int i = 0; i < cnt; i++) { AionTransaction txn = @@ -136,7 +121,7 @@ public void benchmarkSnapshot2() { tp.snapshot(); System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms."); - int cnt2 = 100; + int cnt2 = 10; txnl.clear(); for (ECKey aKey1 : key) { for (int i = 0; i < cnt2; i++) { @@ -173,24 +158,19 @@ public void benchmarkSnapshot2() { } @Test - /* 1M new transactions with 10000 accounts (100 txs per account)in pool snapshot around 10s (cold-call) - gen new txns 55s (spent a lot of time to sign tx) - put txns into pool 2.5s - snapshot txn 5s - */ public void benchmarkSnapshot3() { Properties config = new Properties(); config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100"); - config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "1000000"); + config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "10000"); TxPoolV1 tp = new TxPoolV1(config); List txnl = new ArrayList<>(); - int cnt = 100; + int cnt = 1000; System.out.println("Gen new transactions --"); long start = System.currentTimeMillis(); - for (ECKey aKey21 : key2) { + for (ECKey aKey21 : key) { for (int i = 0; i < cnt; i++) { AionTransaction txn = AionTransaction.create( @@ -215,7 +195,7 @@ public void benchmarkSnapshot3() { tp.add(txnl); System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms."); - Assert.assertEquals(tp.size(), cnt * key2.size()); + Assert.assertEquals(tp.size(), cnt * key.size()); // sort the inserted txs System.out.println("Snapshoting --"); @@ -223,7 +203,7 @@ public void benchmarkSnapshot3() { tp.snapshot(); System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms."); - for (ECKey aKey2 : key2) { + for (ECKey aKey2 : key) { List nl = tp.getNonceList(new AionAddress(aKey2.getAddress())); for (int i = 0; i < cnt; i++) { Assert.assertEquals(nl.get(i), BigInteger.valueOf(i)); @@ -237,13 +217,13 @@ public void benchmarkSnapshot3() { public void benchmarkSnapshot4() { Properties config = new Properties(); config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100"); - config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "100000"); + config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "10000"); TxPoolV1 tp = new TxPoolV1(config); List txnl = new ArrayList<>(); List txnlrm = new ArrayList<>(); - int cnt = 100000; + int cnt = 1000; int rmCnt = 10; System.out.println("gen new transactions..."); long start = System.currentTimeMillis(); @@ -307,12 +287,12 @@ public void benchmarkSnapshot4() { public void benchmarkSnapshot5() { Properties config = new Properties(); config.put(TXPOOL_PROPERTY.PROP_TX_TIMEOUT, "100"); - config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "100000"); + config.put(TXPOOL_PROPERTY.PROP_POOL_SIZE_MAX, "10000"); TxPoolV1 tp = new TxPoolV1(config); List txnl = new ArrayList<>(); - int cnt = 10000; + int cnt = 1000; for (ECKey aKey1 : key) { for (int i = 0; i < cnt; i++) { AionTransaction txn =