Skip to content

Commit

Permalink
Downsized the txpool/cachePool test scales
Browse files Browse the repository at this point in the history
  • Loading branch information
AionJayT committed Mar 3, 2020
1 parent bd727f1 commit c966c1d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@

public class PendingTxCacheV1Test {
private static List<ECKey> 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<>();
Expand Down Expand Up @@ -68,7 +69,7 @@ private List<AionTransaction> getMockTransaction(int startNonce, int num, int ke
@Test
public void addCacheTxTest() {

PendingTxCacheV1 cache = new PendingTxCacheV1();
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);

List<AionTransaction> txn = getMockTransaction(0, 10, 0);
for (AionTransaction tx : txn) {
Expand All @@ -81,7 +82,7 @@ public void addCacheTxTest() {
@Test
public void addCacheTxWith2SendersTest() {

PendingTxCacheV1 cache = new PendingTxCacheV1();
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);
List<AionTransaction> txn = getMockTransaction(0, 10, 0);
txn.addAll(getMockTransaction(0, 10, 1));

Expand All @@ -97,7 +98,7 @@ public void addCacheTxWith2SendersTest() {
@Test
public void addCacheTxReachAccountCacheMaxTest() {

PendingTxCacheV1 cache = new PendingTxCacheV1();
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);

List<AionTransaction> txn = new ArrayList<>();
for (int i = 0; i < key.size(); i++) {
Expand All @@ -114,7 +115,7 @@ public void addCacheTxReachAccountCacheMaxTest() {
@Test
public void addTxReachAccountCacheMaxTest() {

PendingTxCacheV1 cache = new PendingTxCacheV1();
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);
List<AionTransaction> txn = getMockTransaction(0, 500, 0);
for (AionTransaction tx : txn) {
cache.addCacheTx(tx);
Expand All @@ -135,7 +136,7 @@ public void addTxReachAccountCacheMaxTest() {
@Test
public void addCacheTxWithDuplicateNonceTransactionsTest() {

PendingTxCacheV1 cache = new PendingTxCacheV1();
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);
List<AionTransaction> txn = getMockTransaction(0, 10, 0);
txn.addAll(getMockTransaction(5, 10, 0));

Expand All @@ -153,7 +154,7 @@ public void addCacheTxWithDuplicateNonceTransactionsTest() {
@Test
public void flush2TxInOneAccountTest() {

PendingTxCacheV1 cache = new PendingTxCacheV1();
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);

List<AionTransaction> txn = getMockTransaction(0, 10, 0);
List<AionTransaction> newCache;
Expand All @@ -177,7 +178,7 @@ public void flush2TxInOneAccountTest() {
@Test
public void flushTxWithOtherAccountTest() {

PendingTxCacheV1 cache = new PendingTxCacheV1();
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);

List<AionTransaction> txn = getMockTransaction(0, 10, 0);

Expand All @@ -200,7 +201,7 @@ public void flushTxWithOtherAccountTest() {
@Test
public void flushTxWith2AccountsTest() {

PendingTxCacheV1 cache = new PendingTxCacheV1();
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);

List<AionTransaction> txn = getMockTransaction(0, 10, 0);
txn.addAll(getMockTransaction(0, 10, 1));
Expand All @@ -227,7 +228,7 @@ public void flushTxWith2AccountsTest() {
@Test
public void fullFlush2SendersUnderFullCachedInstanceTest() {

PendingTxCacheV1 cache = new PendingTxCacheV1();
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);

List<AionTransaction> txn = new ArrayList<>();
for (int i = 0; i < ACCOUNT_CACHE_MAX; i++) {
Expand Down Expand Up @@ -261,7 +262,7 @@ public void fullFlush2SendersUnderFullCachedInstanceTest() {

@Test
public void getRemovedTxHashWithoutPoolBackupTest() {
PendingTxCacheV1 cache = new PendingTxCacheV1();
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);
assertNotNull(cache.pollRemovedTransactionForPoolBackup());
}

Expand Down Expand Up @@ -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<AionTransaction> txn = new ArrayList<>();
Expand Down Expand Up @@ -373,7 +374,7 @@ public void benchmark() {

@Test
public void isInCacheTest() {
PendingTxCacheV1 cache = new PendingTxCacheV1();
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);

List<AionTransaction> txn = getMockTransaction(0, 1, 0);
for (AionTransaction tx : txn) {
Expand All @@ -388,7 +389,7 @@ public void isInCacheTest() {

@Test
public void getNewPendingTransactionTest() {
PendingTxCacheV1 cache = new PendingTxCacheV1();
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);

List<AionTransaction> txn = getMockTransaction(0, 5, 0);
List<AionTransaction> txn2 = getMockTransaction(0, 5, 1);
Expand Down Expand Up @@ -419,7 +420,7 @@ public void getNewPendingTransactionTest() {

@Test
public void removeTransactionTest() {
PendingTxCacheV1 cache = new PendingTxCacheV1();
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);

List<AionTransaction> txn = getMockTransaction(0, 2, 0);
for (AionTransaction tx : txn) {
Expand Down Expand Up @@ -447,7 +448,7 @@ public void removeTransactionTest() {

@Test
public void flushTimeoutTransactionTest() {
PendingTxCacheV1 cache = new PendingTxCacheV1();
PendingTxCacheV1 cache = new PendingTxCacheV1(ACCOUNT_MAX);

List<AionTransaction> txn = getMockTransaction(0, 2, 0);
for (AionTransaction tx : txn) {
Expand Down
18 changes: 6 additions & 12 deletions modTxPool/test/org/aion/txpool/v1/TxPoolV1Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -878,7 +878,7 @@ public void feemapTest() {
TxPoolV1 tp = new TxPoolV1(config);

List<PooledTransaction> 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;
Expand Down Expand Up @@ -907,22 +907,20 @@ public void feemapTest() {
List<Long> 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--));
}
}

@Test
public void testSnapshotAll() {
ECKeyFac.setType(ECKeyFac.ECKeyType.ED25519);
ECKey key = ECKeyFac.inst().create();

List<PooledTransaction> 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"),
Expand Down Expand Up @@ -950,14 +948,12 @@ public void testSnapshotAll() {

@Test
public void testSnapshotAll2() {
ECKeyFac.setType(ECKeyFac.ECKeyType.ED25519);
ECKey key = ECKeyFac.inst().create();

List<PooledTransaction> 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"),
Expand All @@ -981,14 +977,12 @@ public void testSnapshotAll2() {

@Test
public void testRemove2() {
ECKeyFac.setType(ECKeyFac.ECKeyType.ED25519);
ECKey key = ECKeyFac.inst().create();

List<PooledTransaction> 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"),
Expand Down
48 changes: 14 additions & 34 deletions modTxPool/test/org/aion/txpool/v1/TxnPoolV1BenchmarkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
public class TxnPoolV1BenchmarkTest {

private List<ECKey> key;
private List<ECKey> key2;
private Random r = new Random();

@Before
Expand All @@ -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<PooledTransaction> txnl = new ArrayList<>();
int cnt = 10000;
int cnt = 1000;
for (ECKey aKey1 : key) {
for (int i = 0; i < cnt; i++) {
AionTransaction txn =
Expand Down Expand Up @@ -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<PooledTransaction> txnl = new ArrayList<>();
int cnt = 10000;
int cnt = 1000;
for (ECKey aKey2 : key) {
for (int i = 0; i < cnt; i++) {
AionTransaction txn =
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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<PooledTransaction> 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(
Expand All @@ -215,15 +195,15 @@ 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 --");
start = System.currentTimeMillis();
tp.snapshot();
System.out.println("time spent: " + (System.currentTimeMillis() - start) + " ms.");

for (ECKey aKey2 : key2) {
for (ECKey aKey2 : key) {
List<BigInteger> nl = tp.getNonceList(new AionAddress(aKey2.getAddress()));
for (int i = 0; i < cnt; i++) {
Assert.assertEquals(nl.get(i), BigInteger.valueOf(i));
Expand All @@ -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<PooledTransaction> txnl = new ArrayList<>();
List<PooledTransaction> txnlrm = new ArrayList<>();
int cnt = 100000;
int cnt = 1000;
int rmCnt = 10;
System.out.println("gen new transactions...");
long start = System.currentTimeMillis();
Expand Down Expand Up @@ -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<PooledTransaction> txnl = new ArrayList<>();
int cnt = 10000;
int cnt = 1000;
for (ECKey aKey1 : key) {
for (int i = 0; i < cnt; i++) {
AionTransaction txn =
Expand Down

0 comments on commit c966c1d

Please sign in to comment.