Search in sources :

Example 1 with Account

use of org.apache.ignite.yardstick.cache.model.Account in project ignite by apache.

the class IgniteAccountSerializableTxBenchmark method test.

/**
 * {@inheritDoc}
 */
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
    Set<Integer> accountIds = new HashSet<>();
    int accNum = args.batch();
    while (accountIds.size() < accNum) accountIds.add(nextRandom(args.range()));
    while (true) {
        try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
            Map<Integer, Account> accounts = (Map) cache.getAll(accountIds);
            if (accounts.size() != accNum)
                throw new Exception("Failed to find accounts: " + accountIds);
            Integer fromId = accountIds.iterator().next();
            int fromBalance = accounts.get(fromId).balance();
            for (Integer id : accountIds) {
                if (id.equals(fromId))
                    continue;
                Account account = accounts.get(id);
                if (fromBalance > 0) {
                    fromBalance--;
                    cache.put(id, new Account(account.balance() + 1));
                }
            }
            cache.put(fromId, new Account(fromBalance));
            tx.commit();
        } catch (TransactionOptimisticException e) {
            continue;
        }
        break;
    }
    return true;
}
Also used : TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) Account(org.apache.ignite.yardstick.cache.model.Account) Transaction(org.apache.ignite.transactions.Transaction) Map(java.util.Map) TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) HashSet(java.util.HashSet)

Example 2 with Account

use of org.apache.ignite.yardstick.cache.model.Account in project ignite by apache.

the class IgniteAccountTxAbstractBenchmark method setUp.

/**
 * {@inheritDoc}
 */
@Override
public void setUp(BenchmarkConfiguration cfg) throws Exception {
    super.setUp(cfg);
    txs = ignite().transactions();
    println(cfg, "Populating data...");
    long start = System.nanoTime();
    try (IgniteDataStreamer<Integer, Account> dataLdr = ignite().dataStreamer(cache.getName())) {
        for (int i = 0; i < args.range() && !Thread.currentThread().isInterrupted(); i++) {
            dataLdr.addData(i, new Account(100_000));
            if (i % 100000 == 0)
                println(cfg, "Populated accounts: " + i);
        }
    }
    println(cfg, "Finished populating data in " + ((System.nanoTime() - start) / 1_000_000) + " ms.");
}
Also used : Account(org.apache.ignite.yardstick.cache.model.Account)

Example 3 with Account

use of org.apache.ignite.yardstick.cache.model.Account in project ignite by apache.

the class IgniteAccountTxBenchmark method test.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
    Set<Integer> accountIds = new TreeSet<>();
    int accNum = args.batch();
    while (accountIds.size() < accNum) accountIds.add(nextRandom(args.range()));
    try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) {
        Map<Integer, Account> accounts = (Map) cache.getAll(accountIds);
        if (accounts.size() != accNum)
            throw new Exception("Failed to find accounts: " + accountIds);
        Integer fromId = accountIds.iterator().next();
        int fromBalance = accounts.get(fromId).balance();
        for (Integer id : accountIds) {
            if (id.equals(fromId))
                continue;
            Account account = accounts.get(id);
            if (fromBalance > 0) {
                fromBalance--;
                cache.put(id, new Account(account.balance() + 1));
            }
        }
        cache.put(fromId, new Account(fromBalance));
        tx.commit();
    }
    return true;
}
Also used : Account(org.apache.ignite.yardstick.cache.model.Account) Transaction(org.apache.ignite.transactions.Transaction) TreeSet(java.util.TreeSet) Map(java.util.Map)

Example 4 with Account

use of org.apache.ignite.yardstick.cache.model.Account in project ignite by apache.

the class ModelUtil method create.

/**
 * @param c model class
 * @param id object id
 * @return object from model
 */
public static Object create(Class c, int id) {
    Object res;
    switch(c.getSimpleName()) {
        case "Double":
            res = id;
            break;
        case "Identifier":
            res = new Identifier(id, "id " + id);
            break;
        case "Mark":
            res = new Mark(id, UUID.nameUUIDFromBytes(Integer.toString(id).getBytes()));
            break;
        case "Integer":
            res = id;
            break;
        case "UUID":
            res = UUID.nameUUIDFromBytes(Integer.toString(id).getBytes());
            break;
        case "Car":
            int colorCnt = Color.values().length;
            res = new Car(id, "Mark " + id, id / 2.123 * 100, Color.values()[id % colorCnt]);
            break;
        case "Truck":
            int colors = Color.values().length;
            res = new Truck(id, "Mark " + id, id / 2.123 * 100, Color.values()[id % colors], id / 4.123 * 100);
            break;
        case "Person":
            res = new Person(id, id + 1, "First Name " + id, "Last Name " + id, id / 2.123 * 100);
            break;
        case "Organization":
            res = new Organization(id, "Organization " + id);
            break;
        case "Account":
            res = new Account(id);
            break;
        case "Person1":
            res = new Person1(id);
            break;
        case "Person2":
            res = new Person2(id);
            break;
        case "Person8":
            res = new Person8(id);
            break;
        case "String":
            res = String.valueOf(id);
            break;
        default:
            throw new IllegalArgumentException("Unsupported class: " + c.getSimpleName());
    }
    return res;
}
Also used : Account(org.apache.ignite.yardstick.cache.model.Account) Organization(org.apache.ignite.yardstick.cache.model.Organization) Mark(org.apache.ignite.yardstick.cache.load.model.key.Mark) Truck(org.apache.ignite.yardstick.cache.load.model.value.Truck) Person8(org.apache.ignite.yardstick.cache.model.Person8) Identifier(org.apache.ignite.yardstick.cache.load.model.key.Identifier) Person1(org.apache.ignite.yardstick.cache.model.Person1) Car(org.apache.ignite.yardstick.cache.load.model.value.Car) Person2(org.apache.ignite.yardstick.cache.model.Person2) Person(org.apache.ignite.yardstick.cache.model.Person)

Aggregations

Account (org.apache.ignite.yardstick.cache.model.Account)4 Map (java.util.Map)2 Transaction (org.apache.ignite.transactions.Transaction)2 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 TransactionOptimisticException (org.apache.ignite.transactions.TransactionOptimisticException)1 Identifier (org.apache.ignite.yardstick.cache.load.model.key.Identifier)1 Mark (org.apache.ignite.yardstick.cache.load.model.key.Mark)1 Car (org.apache.ignite.yardstick.cache.load.model.value.Car)1 Truck (org.apache.ignite.yardstick.cache.load.model.value.Truck)1 Organization (org.apache.ignite.yardstick.cache.model.Organization)1 Person (org.apache.ignite.yardstick.cache.model.Person)1 Person1 (org.apache.ignite.yardstick.cache.model.Person1)1 Person2 (org.apache.ignite.yardstick.cache.model.Person2)1 Person8 (org.apache.ignite.yardstick.cache.model.Person8)1