ignite-950: added benchmarks temporaly
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/cc19b086 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/cc19b086 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/cc19b086 Branch: refs/heads/ignite-950 Commit: cc19b0862df3461024f43786ea61b6321d678966 Parents: 76309bb Author: Denis Magda <dma...@gridgain.com> Authored: Wed Jul 1 08:24:31 2015 +0300 Committer: Denis Magda <dma...@gridgain.com> Committed: Wed Jul 1 08:24:31 2015 +0300 ---------------------------------------------------------------------- .../ignite/jmh/CliendServerNodeBenchmark.java | 204 +++++++++ .../ignite/jmh/MarshallerContextJMHImpl.java | 57 +++ .../ignite/jmh/MarshallerMethodsBenchmark.java | 95 ++++ .../ignite/jmh/QueryMarshallerBenchmark.java | 412 ++++++++++++++++++ .../apache/ignite/jmh/ReadFieldBenchmark.java | 91 ++++ .../SeveralNodesQueryMarshallerBenchmark.java | 432 +++++++++++++++++++ .../ignite/jmh/SimpleMarshallerBenchmark.java | 208 +++++++++ .../java/org/apache/ignite/jmh/model/City.java | 72 ++++ .../org/apache/ignite/jmh/model/Department.java | 75 ++++ .../apache/ignite/jmh/model/Organization.java | 39 ++ .../org/apache/ignite/jmh/model/Person.java | 97 +++++ .../ignite/jmh/model/PersonExternalizable.java | 190 ++++++++ .../ignite/jmh/model/PersonMarshalAware.java | 199 +++++++++ .../apache/ignite/jmh/model/PersonSimple.java | 172 ++++++++ 14 files changed, 2343 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc19b086/modules/yardstick/src/main/java/org/apache/ignite/jmh/CliendServerNodeBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/jmh/CliendServerNodeBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/jmh/CliendServerNodeBenchmark.java new file mode 100644 index 0000000..6018ae9 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/jmh/CliendServerNodeBenchmark.java @@ -0,0 +1,204 @@ +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.jmh; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.query.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.jmh.model.*; +import org.apache.ignite.marshaller.*; +import org.apache.ignite.marshaller.optimized.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.output.*; +import org.openjdk.jmh.runner.*; +import org.openjdk.jmh.runner.options.*; + +import javax.cache.*; +import java.util.*; +import java.util.concurrent.*; + +/** + * Created by GridAdmin1234 on 6/29/2015. + */ +@State (value = Scope.Benchmark) +public class CliendServerNodeBenchmark { + private TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + private Ignite node; + + private IgniteCache<Integer, PersonSimple> cache; + + private static final int ROWS_COUNT = 50000; + + private int putCounter = ROWS_COUNT + 1; + + private IgniteConfiguration createConfiguration(String gridName, boolean newMarshaller) { + IgniteConfiguration cfg = new IgniteConfiguration(); + + cfg.setGridName(gridName); + + TcpDiscoverySpi spi = new TcpDiscoverySpi(); + spi.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(spi); + + OptimizedMarshaller marsh = new OptimizedMarshaller(false); + marsh.setProtocolVersion(newMarshaller ? OptimizedMarshallerProtocolVersion.VER_1_1 : + OptimizedMarshallerProtocolVersion.VER_1); + cfg.setMarshaller(marsh); + + CacheConfiguration cCfg = new CacheConfiguration(); + cCfg.setName("query"); + cCfg.setCacheMode(CacheMode.PARTITIONED); + cCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + cCfg.setSwapEnabled(false); +// cCfg.setCopyOnRead(false); + + CacheTypeMetadata meta = new CacheTypeMetadata(); + + meta.setKeyType(Integer.class); + meta.setValueType(PersonSimple.class); + + HashMap<String, Class<?>> indexes = new HashMap<>(); + indexes.put("id", Integer.class); + indexes.put("orgId", Integer.class); + indexes.put("salary", Double.class); + + meta.setAscendingFields(indexes); + + HashMap<String, Class<?>> queryFields = new HashMap<>(); + queryFields.put("firstName", String.class); + queryFields.put("lastName", String.class); + + meta.setQueryFields(queryFields); + + cCfg.setTypeMetadata(Arrays.asList(meta)); + + cfg.setCacheConfiguration(cCfg); + + return cfg; + } + + @TearDown + public void stopNodes() { + Ignition.stopAll(true); + } + + //@Setup + public void startOldNodes() { + System.out.println(); + System.out.println("STARTED OLD NODE"); + + Ignition.start(createConfiguration("node", false)); + + IgniteConfiguration clientCfg = createConfiguration("client", false); + clientCfg.setClientMode(true); + + node = Ignition.start(clientCfg); + + cache = node.cache("query"); + + for (int i = 0; i < ROWS_COUNT; i++) { + PersonSimple person = new PersonSimple(i, "Name ", "Surname ", (i + 1) * 100); + cache.put(i, person); + } + } + + @Setup + public void startNewNodes() { + System.out.println(); + System.out.println("STARTED NEW NODE"); + + Ignite server = Ignition.start(createConfiguration("node", true)); + + IgniteConfiguration clientCfg = createConfiguration("client", true); + clientCfg.setClientMode(true); + + node = Ignition.start(clientCfg); + + cache = node.cache("query"); + + for (int i = 0; i < ROWS_COUNT; i++) { + PersonSimple person = new PersonSimple(i, "Name ", "Surname ", (i + 1) * 100); + cache.put(i, person); + } + } + + + @GenerateMicroBenchmark + public void testGet() throws Exception { + int key = ThreadLocalRandom.current().nextInt(0, ROWS_COUNT); + + PersonSimple personSimple = cache.get(key); + + if (personSimple == null) + throw new IgniteException("Person is null"); + } + + //@GenerateMicroBenchmark + public void testPut() throws Exception { + cache.put(putCounter, new PersonSimple(putCounter, "Name ", "Surname ", (putCounter + 1) * 100)); + putCounter++; + } + + //@GenerateMicroBenchmark + public void testFieldsQuery() throws Exception { + double salary = ThreadLocalRandom.current().nextInt(0, ROWS_COUNT); + + double maxSalary = salary + 100; + + SqlFieldsQuery qry = new SqlFieldsQuery("SELECT PersonSimple.firstName, PersonSimple.lastName FROM " + + "PersonSimple WHERE salary >= ? and salary <= ?"); + + qry.setArgs(salary, maxSalary); + + List<List<?>> result = cache.query(qry).getAll(); + + for (List<?> row : result) { + if (row.get(0) == null || row.get(1) == null) + throw new Exception("Invalid person retrieved [min=" + salary + ", max=" + maxSalary + + ", person=" + row + ']'); + } + } + +// public static void main(String args[]) throws Exception { +// CliendServerNodeBenchmark benchmark = new CliendServerNodeBenchmark(); +// +// benchmark.startNewNodes(); +// +// for (int i = ROWS_COUNT + 1; i < 1000000; i++) { +// benchmark.cache.put(i, new PersonSimple(i, "Name DSda hdasjhdkas ajksdhasjkd " + i, "Surname dasdsad " + i, +// (i + 1) * 100)); +// +// if (i % 10000 == 0) +// System.out.println("Put :" + i); +// } +// +// System.out.println("Put all the data!"); +// } + + + public static void main(String... args) throws Exception { + Options opts = new OptionsBuilder() + .include(".*" + CliendServerNodeBenchmark.class.getSimpleName() + ".*") + .warmupIterations(15) + .measurementIterations(65) + .jvmArgs("-server") + .forks(1) + .outputFormat(OutputFormatType.TextReport) + //.shouldDoGC(true) + .build(); + + new Runner(opts).run(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc19b086/modules/yardstick/src/main/java/org/apache/ignite/jmh/MarshallerContextJMHImpl.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/jmh/MarshallerContextJMHImpl.java b/modules/yardstick/src/main/java/org/apache/ignite/jmh/MarshallerContextJMHImpl.java new file mode 100644 index 0000000..5504851 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/jmh/MarshallerContextJMHImpl.java @@ -0,0 +1,57 @@ +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.jmh; + +import org.apache.ignite.*; +import org.apache.ignite.internal.*; +import org.apache.ignite.plugin.*; +import org.jsr166.*; + +import java.util.*; +import java.util.concurrent.*; + +/** + * Test marshaller context. + */ +public class MarshallerContextJMHImpl extends MarshallerContextAdapter { + /** */ + private final static ConcurrentMap<Integer, String> map = new ConcurrentHashMap8<>(); + + /** + * Initializes context. + * + * @param plugins Plugins. + */ + public MarshallerContextJMHImpl(List<PluginProvider> plugins) { + super(plugins); + } + + /** + * Initializes context. + */ + public MarshallerContextJMHImpl() { + super(null); + } + + /** {@inheritDoc} */ + @Override protected boolean registerClassName(int id, String clsName) throws IgniteCheckedException { + String oldClsName = map.putIfAbsent(id, clsName); + + if (oldClsName != null && !oldClsName.equals(clsName)) + throw new IgniteCheckedException("Duplicate ID [id=" + id + ", oldClsName=" + oldClsName + ", clsName=" + + clsName + ']'); + + return true; + } + + /** {@inheritDoc} */ + @Override protected String className(int id) { + return map.get(id); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc19b086/modules/yardstick/src/main/java/org/apache/ignite/jmh/MarshallerMethodsBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/jmh/MarshallerMethodsBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/jmh/MarshallerMethodsBenchmark.java new file mode 100644 index 0000000..728637c --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/jmh/MarshallerMethodsBenchmark.java @@ -0,0 +1,95 @@ +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.jmh; + +import org.apache.ignite.jmh.model.*; +import org.apache.ignite.marshaller.*; +import org.apache.ignite.marshaller.optimized.*; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.output.*; +import org.openjdk.jmh.runner.*; +import org.openjdk.jmh.runner.options.*; + +import java.util.concurrent.*; + +/** + * Created by GridAdmin1234 on 6/30/2015. + */ +@State(value = Scope.Benchmark) +public class MarshallerMethodsBenchmark { + private OptimizedMarshaller marsh; + + private PersonSimple personSimple; + + @Setup + public void initNewMarshaller() { + marsh = new OptimizedMarshaller(false); + marsh.setProtocolVersion(OptimizedMarshallerProtocolVersion.VER_1_1); + + marsh.setContext(new MarshallerContextJMHImpl()); + + OptimizedMarshallerIndexingHandler idxHandler = new OptimizedMarshallerIndexingHandler(); + + idxHandler.setMetaHandler(new OptimizedMarshallerMetaHandler() { + + private ConcurrentHashMap<Integer, OptimizedObjectMetadata> map = new ConcurrentHashMap<Integer, + OptimizedObjectMetadata>(); + + @Override public void addMeta(int typeId, OptimizedObjectMetadata meta) { + map.put(typeId, meta); + } + + @Override public OptimizedObjectMetadata metadata(int typeId) { + return map.get(typeId); + } + }); + + marsh.setIndexingHandler(idxHandler); + + personSimple = new PersonSimple(100, 200, "asdjkas aksjdhkajsd ajd", "asjdlaskd askdjsalkd", 900); + } + + //@Setup + public void initOldMarshaller() { + marsh = new OptimizedMarshaller(false); + + marsh.setProtocolVersion(OptimizedMarshallerProtocolVersion.VER_1); + marsh.setContext(new MarshallerContextJMHImpl()); + + personSimple = new PersonSimple(100, 200, "asdjkas aksjdhkajsd ajd", "asjdlaskd askdjsalkd", 900); + } + + @GenerateMicroBenchmark + public void testMarshal() throws Exception { + marsh.marshal(personSimple); + } + + public static void main(String... args) throws Exception { + Options opts = new OptionsBuilder() + .include(".*" + MarshallerMethodsBenchmark.class.getSimpleName() + ".*") + .warmupIterations(15) + .measurementIterations(65) + .jvmArgs("-server") + .forks(1) + .outputFormat(OutputFormatType.TextReport) + //.shouldDoGC(true) + .build(); + + new Runner(opts).run(); + } + +// public static void main(String[] args) throws Exception { +// MarshallerMethodsBenchmark benchmark = new MarshallerMethodsBenchmark(); +// +// benchmark.initNewMarshaller(); +// +// for (int i = 0; i < 40; i++) +// benchmark.testMarshal(); +// } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc19b086/modules/yardstick/src/main/java/org/apache/ignite/jmh/QueryMarshallerBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/jmh/QueryMarshallerBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/jmh/QueryMarshallerBenchmark.java new file mode 100644 index 0000000..76aee7f --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/jmh/QueryMarshallerBenchmark.java @@ -0,0 +1,412 @@ +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.jmh; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.affinity.*; +import org.apache.ignite.cache.query.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.jmh.model.*; +import org.apache.ignite.marshaller.optimized.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.output.*; +import org.openjdk.jmh.runner.*; +import org.openjdk.jmh.runner.options.*; + +import javax.cache.*; +import java.util.*; + +/** + * Created by GridAdmin1234 on 6/25/2015. + */ +@State (value = Scope.Benchmark) +public class QueryMarshallerBenchmark { + + private final static String PERSON_CACHE = "person"; + + private final static String CITY_CACHE = "city"; + + private final static String DEPARTMENT_CACHE = "dep"; + + private final static String ORGANIZATION_CACHE = "org"; + + private static final int PERSON_ROWS_COUNT = 400000; + + private static final int CITY_ROWS_COUNT = 500; + + private static final int DEPARTMENT_ROWS_COUNT = CITY_ROWS_COUNT * 10; + + private static final int ORGANIZATION_ROWS_COUNT = 30; + + private static final int SALARY_LIMIT = 100000; + + + private TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + private Ignite node1; + + private Ignite node2; + + private IgniteCache<AffinityKey<UUID>, Person> personCache; + + private IgniteConfiguration createOldConfiguration(String gridName) { + IgniteConfiguration cfg = new IgniteConfiguration(); + + cfg.setGridName(gridName); + + TcpDiscoverySpi spi = new TcpDiscoverySpi(); + spi.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(spi); + + OptimizedMarshaller marshaller = new OptimizedMarshaller(); + marshaller.setProtocolVersion(OptimizedMarshallerProtocolVersion.VER_1); + + cfg.setMarshaller(marshaller); + + CacheConfiguration cityCacheCfg = createCacheCfg(CITY_CACHE); + cityCacheCfg.setTypeMetadata(Arrays.asList(createCityMetadata())); + + CacheConfiguration orgCacheCfg = createCacheCfg(ORGANIZATION_CACHE); + orgCacheCfg.setTypeMetadata(Arrays.asList(createOrgMetadata())); + + CacheConfiguration depCacheCfg = createCacheCfg(DEPARTMENT_CACHE); + depCacheCfg.setTypeMetadata(Arrays.asList(createDepartmentMeta())); + + CacheConfiguration personCacheCfg = createCacheCfg(PERSON_CACHE); + personCacheCfg.setTypeMetadata(Arrays.asList(createPersonMeta())); + + cfg.setCacheConfiguration(cityCacheCfg, orgCacheCfg, depCacheCfg, personCacheCfg); + +// CacheConfiguration cityCacheCfg = createCacheCfg(CITY_CACHE); +// cityCacheCfg.setIndexedTypes(UUID.class, City.class); +// +// CacheConfiguration orgCacheCfg = createCacheCfg(ORGANIZATION_CACHE); +// orgCacheCfg.setIndexedTypes(UUID.class, Organization.class); +// +// CacheConfiguration depCacheCfg = createCacheCfg(DEPARTMENT_CACHE); +// depCacheCfg.setIndexedTypes(AffinityKey.class, Department.class); +// +// CacheConfiguration personCacheCfg = createCacheCfg(PERSON_CACHE); +// personCacheCfg.setIndexedTypes(AffinityKey.class, Person.class); +// +// cfg.setCacheConfiguration(cityCacheCfg, orgCacheCfg, depCacheCfg, personCacheCfg); + + return cfg; + } + + private IgniteConfiguration createNewConfiguration(String gridName) { + IgniteConfiguration cfg = new IgniteConfiguration(); + + cfg.setGridName(gridName); + + TcpDiscoverySpi spi = new TcpDiscoverySpi(); + spi.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(spi); + + OptimizedMarshaller marshaller = new OptimizedMarshaller(); + marshaller.setProtocolVersion(OptimizedMarshallerProtocolVersion.VER_1_1); + cfg.setMarshaller(marshaller); + + CacheConfiguration cityCacheCfg = createCacheCfg(CITY_CACHE); + cityCacheCfg.setTypeMetadata(Arrays.asList(createCityMetadata())); + + CacheConfiguration orgCacheCfg = createCacheCfg(ORGANIZATION_CACHE); + orgCacheCfg.setTypeMetadata(Arrays.asList(createOrgMetadata())); + + CacheConfiguration depCacheCfg = createCacheCfg(DEPARTMENT_CACHE); + depCacheCfg.setTypeMetadata(Arrays.asList(createDepartmentMeta())); + + CacheConfiguration personCacheCfg = createCacheCfg(PERSON_CACHE); + personCacheCfg.setTypeMetadata(Arrays.asList(createPersonMeta())); + + cfg.setCacheConfiguration(cityCacheCfg, orgCacheCfg, depCacheCfg, personCacheCfg); + + return cfg; + } + + private CacheConfiguration createCacheCfg(String name) { + CacheConfiguration cCfg = new CacheConfiguration(); + cCfg.setName(name); + cCfg.setCacheMode(CacheMode.PARTITIONED); + cCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + cCfg.setSwapEnabled(false); + +// cCfg.setMemoryMode(CacheMemoryMode.OFFHEAP_TIERED); +// cCfg.setOffHeapMaxMemory(0); +// cCfg.setSqlOnheapRowCacheSize(1); + + return cCfg; + } + + private CacheTypeMetadata createCityMetadata() { + CacheTypeMetadata meta = new CacheTypeMetadata(); + + meta.setKeyType(UUID.class); + meta.setValueType(City.class); + + HashMap<String, Class<?>> indexes = new HashMap<>(); + indexes.put("id", UUID.class); + + HashMap<String, Class<?>> queryFields = new HashMap<>(); + queryFields.put("name", String.class); + queryFields.put("population", Integer.class); + queryFields.put("age", Integer.class); + + meta.setAscendingFields(indexes); + meta.setQueryFields(queryFields); + + return meta; + } + + private CacheTypeMetadata createOrgMetadata() { + CacheTypeMetadata meta = new CacheTypeMetadata(); + + meta.setKeyType(UUID.class); + meta.setValueType(Organization.class); + + HashMap<String, Class<?>> indexes = new HashMap<>(); + indexes.put("id", UUID.class); + + HashMap<String, Class<?>> queryFields = new HashMap<>(); + queryFields.put("name", String.class); + + meta.setAscendingFields(indexes); + meta.setQueryFields(queryFields); + + return meta; + } + + private CacheTypeMetadata createDepartmentMeta() { + CacheTypeMetadata meta = new CacheTypeMetadata(); + + meta.setKeyType(AffinityKey.class); + meta.setValueType(Department.class); + + HashMap<String, Class<?>> indexes = new HashMap<>(); + indexes.put("id", UUID.class); + indexes.put("cityId", UUID.class); + indexes.put("orgId", UUID.class); + + HashMap<String, Class<?>> queryFields = new HashMap<>(); + queryFields.put("name", String.class); + + meta.setAscendingFields(indexes); + meta.setQueryFields(queryFields); + + return meta; + } + + private CacheTypeMetadata createPersonMeta() { + CacheTypeMetadata meta = new CacheTypeMetadata(); + + meta.setKeyType(AffinityKey.class); + meta.setValueType(Person.class); + + HashMap<String, Class<?>> indexes = new HashMap<>(); + indexes.put("id", UUID.class); + indexes.put("depId", UUID.class); + + HashMap<String, Class<?>> queryFields = new HashMap<>(); + queryFields.put("firstName", String.class); + queryFields.put("lastName", String.class); + queryFields.put("rank", Integer.class); + queryFields.put("title", String.class); + queryFields.put("age", Integer.class); + queryFields.put("salary", Integer.class); + + meta.setAscendingFields(indexes); + meta.setQueryFields(queryFields); + + return meta; + } + + private void populateCaches() { + Random rand = new Random(); + + System.out.println(); + + IgniteCache<UUID, City> cityCache = node1.cache(CITY_CACHE); + + City[] cities = new City[CITY_ROWS_COUNT]; + + for (int i = 0; i < CITY_ROWS_COUNT; i++) { + City city = new City("City Name " + i, rand.nextInt(10000000), rand.nextInt(2000), "Country" + i); + + cities[i] = city; + + cityCache.put(city.getId(), city); + } + + System.out.println("Populated cities: " + CITY_ROWS_COUNT); + + IgniteCache<UUID, Organization> orgCache = node1.cache(ORGANIZATION_CACHE); + + Organization[] organizations = new Organization[ORGANIZATION_ROWS_COUNT]; + + for (int i = 0; i < ORGANIZATION_ROWS_COUNT; i++) { + Organization org = new Organization("Org Name " + i); + + organizations[i] = org; + + orgCache.put(org.getId(), org); + } + + System.out.println("Populated organizations: " + ORGANIZATION_ROWS_COUNT); + + IgniteCache<AffinityKey<UUID>, Department> depCache = node1.cache(DEPARTMENT_CACHE); + + Department[] departments = new Department[DEPARTMENT_ROWS_COUNT]; + + for (int i = 0; i < DEPARTMENT_ROWS_COUNT; i++) { + Department dep = new Department("Dep Name " + i, cities[rand.nextInt(CITY_ROWS_COUNT)], + organizations[rand.nextInt(ORGANIZATION_ROWS_COUNT)]); + + departments[i] = dep; + + try { + depCache.put(dep.getKey(), dep); + } + catch (Exception e) { + System.out.println("ROW: " + i); + e.printStackTrace(); + } + } + + System.out.println("Populated departments: " + DEPARTMENT_ROWS_COUNT); + + cities = null; + organizations = null; + + personCache = node1.cache(PERSON_CACHE); + + for (int i = 0; i < PERSON_ROWS_COUNT; i++) { + Person person = new Person(departments[rand.nextInt(DEPARTMENT_ROWS_COUNT)], "First Name " + i, + "Last Name " + i, rand.nextInt(21), "Title " + i, rand.nextInt(90), rand.nextInt(SALARY_LIMIT)); + + personCache.put(person.getKey(), person); + } + + System.out.println("Populated persons: " + PERSON_ROWS_COUNT); + + System.out.printf(""); + } + + @Setup (Level.Trial) + public void startOldNodes() { + System.out.println(); + + System.out.println("Using OLD marshaller"); + + node1 = Ignition.start(createOldConfiguration("node1")); + //node2 = Ignition.start(createOldConfiguration("node2")); + + populateCaches(); + } + + //@Setup (Level.Trial) + public void startNewNodes() { + System.out.println(); + + System.out.println("Using New marshaller"); + + node1 = Ignition.start(createNewConfiguration("node1")); + //node2 = Ignition.start(createNewConfiguration("node2")); + + populateCaches(); + } + + @TearDown (Level.Trial) + public void stopNodes() { + Ignition.stopAll(true); + } + + //@GenerateMicroBenchmark + public void sqlQuerySimple() { + String sql = "salary > ? and salary <= ?"; + + List<Cache.Entry<AffinityKey<UUID>, Person>> result = + personCache.query(new SqlQuery<AffinityKey<UUID>, Person>(Person.class, sql). + setArgs(0, 200000)).getAll(); + + if (result.size() == 0) + throw new RuntimeException("Invalid result size"); + } + + //@GenerateMicroBenchmark + public void sqlQueryWithJoin() { + // SQL clause query which joins on 2 types to select people for a specific organization. + String joinSql = + "from Person, \"" + DEPARTMENT_CACHE + "\".Department as dep " + + "where Person.depId = dep.id " + + "and lower(dep.name) = lower(?)"; + + // Execute queries for find employees for different organizations. + List<Cache.Entry<AffinityKey<UUID>, Person>> result = + personCache.query(new SqlQuery<AffinityKey<UUID>, Person>(Person.class, joinSql). + setArgs("Dep Name 1")).getAll(); + + if (result.size() == 0) + throw new RuntimeException("Invalid result size"); + } + + @GenerateMicroBenchmark + public void sqlQueryWithAggregation() { + // Calculate average of salary of all persons in ApacheIgnite. + // Note that we also join on Organization cache as well. + Random rand = new Random(); + + String sql = +// "select Person.firstName, Person.lastName, Person.salary " + + "select Person.firstName, city.name " + + "from Person, \"" + DEPARTMENT_CACHE + "\".Department as dep, " + + "\"" + CITY_CACHE + "\".City as city " + + "where Person.depId = dep.id and dep.cityId = city.id " + + "and city.population > ? and city.population <= ?"; + + QueryCursor<List<?>> cursor = personCache.query(new SqlFieldsQuery(sql).setArgs(rand.nextInt(1000), + rand.nextInt(10000000))); + + if (cursor.getAll().size() == 0) + System.err.println("Invalid result size"); + } + + + /*public static void main(String... args) throws Exception { + Options opts = new OptionsBuilder() + .include(".*" + QueryMarshallerBenchmark.class.getSimpleName() + ".*") + .warmupIterations(15) + .measurementIterations(35) + .jvmArgs("-server") + .forks(1) + .outputFormat(OutputFormatType.TextReport) + .build(); + + new Runner(opts).run(); + }*/ + + public static void main(String... args) throws Exception { + QueryMarshallerBenchmark benchmark = new QueryMarshallerBenchmark(); + + benchmark.startOldNodes(); + + for (int i = 0; i < 20000; i++) { + benchmark.sqlQuerySimple(); + + if (i % 1000 == 0) + System.out.println("Iteration: " + i); + } + + benchmark.stopNodes(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc19b086/modules/yardstick/src/main/java/org/apache/ignite/jmh/ReadFieldBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/jmh/ReadFieldBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/jmh/ReadFieldBenchmark.java new file mode 100644 index 0000000..a118ca5 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/jmh/ReadFieldBenchmark.java @@ -0,0 +1,91 @@ +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.jmh; + +import org.apache.ignite.jmh.model.*; +import org.apache.ignite.marshaller.optimized.*; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.logic.results.*; +import org.openjdk.jmh.output.*; +import org.openjdk.jmh.runner.*; +import org.openjdk.jmh.runner.options.*; + +import java.util.*; +import java.util.concurrent.*; + +/** + * + */ +@State +public class ReadFieldBenchmark { + + private OptimizedMarshaller marshaller; + + private byte[] arr; + + @Setup + public void init() throws Exception { + marshaller = new OptimizedMarshaller(); + + marshaller.setContext(new MarshallerContextJMHImpl()); + + /*marshaller.setMetadataHandler(new OptimizedMarshallerMetaHandler() { + + private ConcurrentHashMap<Integer, OptimizedObjectMetadata> map = new ConcurrentHashMap<Integer, + OptimizedObjectMetadata>(); + + @Override public void addMeta(int typeId, OptimizedObjectMetadata meta) { + map.put(typeId, meta); + } + + @Override public OptimizedObjectMetadata metadata(int typeId) { + return map.get(typeId); + } + }); + + marshaller.enableFieldsIndexing(PersonSimple.class); +*/ + PersonSimple person = new PersonSimple(100, "Denis A", "Magda", 200); + + arr = marshaller.marshal(person); + } + + @GenerateMicroBenchmark + public void testReadField() throws Exception { + //boolean res = marshaller.hasField("firstName", arr, 0, arr.length); + + //if (!res) + // throw new RuntimeException("Fuck"); + + Object name = marshaller.readField("id", arr, 0, arr.length, null); + + if (name == null) + throw new RuntimeException("Fuck"); + } + + public static void main(String... args) throws Exception { + Options opts = new OptionsBuilder() + .include(".*") + .warmupIterations(15) + .measurementIterations(15) + .jvmArgs("-server") + .forks(1) + .outputFormat(OutputFormatType.TextReport) + .build(); + + Map<BenchmarkRecord,RunResult> records = new Runner(opts).run(); + /*for (Map.Entry<BenchmarkRecord, RunResult> result : records.entrySet()) { + Result r = result.getValue().getPrimaryResult(); + System.out.println("API replied benchmark score: " + + r.getScore() + " " + + r.getScoreUnit() + " over " + + r.getStatistics().getN() + " iterations"); + }*/ + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc19b086/modules/yardstick/src/main/java/org/apache/ignite/jmh/SeveralNodesQueryMarshallerBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/jmh/SeveralNodesQueryMarshallerBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/jmh/SeveralNodesQueryMarshallerBenchmark.java new file mode 100644 index 0000000..54b00aa --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/jmh/SeveralNodesQueryMarshallerBenchmark.java @@ -0,0 +1,432 @@ +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.jmh; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.affinity.*; +import org.apache.ignite.cache.query.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.jmh.model.*; +import org.apache.ignite.marshaller.optimized.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.output.*; +import org.openjdk.jmh.runner.*; +import org.openjdk.jmh.runner.options.*; + +import javax.cache.*; +import java.util.*; + +/** + * Created by GridAdmin1234 on 6/25/2015. + */ +@State (value = Scope.Benchmark) +public class SeveralNodesQueryMarshallerBenchmark { + + private final static String PERSON_CACHE = "person"; + + private final static String CITY_CACHE = "city"; + + private final static String DEPARTMENT_CACHE = "dep"; + + private final static String ORGANIZATION_CACHE = "org"; + + private static final int PERSON_ROWS_COUNT = 50000; + + private static final int CITY_ROWS_COUNT = 500; + + private static final int DEPARTMENT_ROWS_COUNT = CITY_ROWS_COUNT * 10; + + private static final int ORGANIZATION_ROWS_COUNT = 30; + + private static final int SALARY_LIMIT = 100000; + + + private TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + private Ignite clientNode; + + private IgniteCache<AffinityKey<UUID>, Person> personCache; + + private IgniteConfiguration createOldConfiguration(String gridName) { + IgniteConfiguration cfg = new IgniteConfiguration(); + + cfg.setGridName(gridName); + + TcpDiscoverySpi spi = new TcpDiscoverySpi(); + spi.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(spi); + + OptimizedMarshaller marshaller = new OptimizedMarshaller(); + marshaller.setProtocolVersion(OptimizedMarshallerProtocolVersion.VER_1); + + cfg.setMarshaller(marshaller); + + CacheConfiguration cityCacheCfg = createCacheCfg(CITY_CACHE); + cityCacheCfg.setTypeMetadata(Arrays.asList(createCityMetadata())); + + CacheConfiguration orgCacheCfg = createCacheCfg(ORGANIZATION_CACHE); + orgCacheCfg.setTypeMetadata(Arrays.asList(createOrgMetadata())); + + CacheConfiguration depCacheCfg = createCacheCfg(DEPARTMENT_CACHE); + depCacheCfg.setTypeMetadata(Arrays.asList(createDepartmentMeta())); + + CacheConfiguration personCacheCfg = createCacheCfg(PERSON_CACHE); + personCacheCfg.setTypeMetadata(Arrays.asList(createPersonMeta())); + + cfg.setCacheConfiguration(cityCacheCfg, orgCacheCfg, depCacheCfg, personCacheCfg); + +// CacheConfiguration cityCacheCfg = createCacheCfg(CITY_CACHE); +// cityCacheCfg.setIndexedTypes(UUID.class, City.class); +// +// CacheConfiguration orgCacheCfg = createCacheCfg(ORGANIZATION_CACHE); +// orgCacheCfg.setIndexedTypes(UUID.class, Organization.class); +// +// CacheConfiguration depCacheCfg = createCacheCfg(DEPARTMENT_CACHE); +// depCacheCfg.setIndexedTypes(AffinityKey.class, Department.class); +// +// CacheConfiguration personCacheCfg = createCacheCfg(PERSON_CACHE); +// personCacheCfg.setIndexedTypes(AffinityKey.class, Person.class); +// +// cfg.setCacheConfiguration(cityCacheCfg, orgCacheCfg, depCacheCfg, personCacheCfg); + + return cfg; + } + + private IgniteConfiguration createNewConfiguration(String gridName) { + IgniteConfiguration cfg = new IgniteConfiguration(); + + cfg.setGridName(gridName); + + TcpDiscoverySpi spi = new TcpDiscoverySpi(); + spi.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(spi); + + OptimizedMarshaller marshaller = new OptimizedMarshaller(); + marshaller.setProtocolVersion(OptimizedMarshallerProtocolVersion.VER_1_1); + cfg.setMarshaller(marshaller); + + CacheConfiguration cityCacheCfg = createCacheCfg(CITY_CACHE); + cityCacheCfg.setTypeMetadata(Arrays.asList(createCityMetadata())); + + CacheConfiguration orgCacheCfg = createCacheCfg(ORGANIZATION_CACHE); + orgCacheCfg.setTypeMetadata(Arrays.asList(createOrgMetadata())); + + CacheConfiguration depCacheCfg = createCacheCfg(DEPARTMENT_CACHE); + depCacheCfg.setTypeMetadata(Arrays.asList(createDepartmentMeta())); + + CacheConfiguration personCacheCfg = createCacheCfg(PERSON_CACHE); + personCacheCfg.setTypeMetadata(Arrays.asList(createPersonMeta())); + + cfg.setCacheConfiguration(cityCacheCfg, orgCacheCfg, depCacheCfg, personCacheCfg); + + return cfg; + } + + private CacheConfiguration createCacheCfg(String name) { + CacheConfiguration cCfg = new CacheConfiguration(); + cCfg.setName(name); + cCfg.setCacheMode(CacheMode.PARTITIONED); + cCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + cCfg.setSwapEnabled(false); + +// cCfg.setMemoryMode(CacheMemoryMode.OFFHEAP_TIERED); +// cCfg.setOffHeapMaxMemory(0); +// cCfg.setSqlOnheapRowCacheSize(1); + + return cCfg; + } + + private CacheTypeMetadata createCityMetadata() { + CacheTypeMetadata meta = new CacheTypeMetadata(); + + meta.setKeyType(UUID.class); + meta.setValueType(City.class); + + HashMap<String, Class<?>> indexes = new HashMap<>(); + indexes.put("id", UUID.class); + + HashMap<String, Class<?>> queryFields = new HashMap<>(); + queryFields.put("name", String.class); + queryFields.put("population", Integer.class); + queryFields.put("age", Integer.class); + + meta.setAscendingFields(indexes); + meta.setQueryFields(queryFields); + + return meta; + } + + private CacheTypeMetadata createOrgMetadata() { + CacheTypeMetadata meta = new CacheTypeMetadata(); + + meta.setKeyType(UUID.class); + meta.setValueType(Organization.class); + + HashMap<String, Class<?>> indexes = new HashMap<>(); + indexes.put("id", UUID.class); + + HashMap<String, Class<?>> queryFields = new HashMap<>(); + queryFields.put("name", String.class); + + meta.setAscendingFields(indexes); + meta.setQueryFields(queryFields); + + return meta; + } + + private CacheTypeMetadata createDepartmentMeta() { + CacheTypeMetadata meta = new CacheTypeMetadata(); + + meta.setKeyType(AffinityKey.class); + meta.setValueType(Department.class); + + HashMap<String, Class<?>> indexes = new HashMap<>(); + indexes.put("id", UUID.class); + indexes.put("cityId", UUID.class); + indexes.put("orgId", UUID.class); + + HashMap<String, Class<?>> queryFields = new HashMap<>(); + queryFields.put("name", String.class); + + meta.setAscendingFields(indexes); + meta.setQueryFields(queryFields); + + return meta; + } + + private CacheTypeMetadata createPersonMeta() { + CacheTypeMetadata meta = new CacheTypeMetadata(); + + meta.setKeyType(AffinityKey.class); + meta.setValueType(Person.class); + + HashMap<String, Class<?>> indexes = new HashMap<>(); + indexes.put("id", UUID.class); + indexes.put("depId", UUID.class); + + HashMap<String, Class<?>> queryFields = new HashMap<>(); + queryFields.put("firstName", String.class); + queryFields.put("lastName", String.class); + queryFields.put("rank", Integer.class); + queryFields.put("title", String.class); + queryFields.put("age", Integer.class); + queryFields.put("salary", Integer.class); + + meta.setAscendingFields(indexes); + meta.setQueryFields(queryFields); + + return meta; + } + + private void populateCaches() { + Random rand = new Random(); + + System.out.println(); + + IgniteCache<UUID, City> cityCache = clientNode.cache(CITY_CACHE); + + City[] cities = new City[CITY_ROWS_COUNT]; + + for (int i = 0; i < CITY_ROWS_COUNT; i++) { + City city = new City("City Name " + i, rand.nextInt(10000000), rand.nextInt(2000), "Country" + i); + + cities[i] = city; + + cityCache.put(city.getId(), city); + } + + System.out.println("Populated cities: " + CITY_ROWS_COUNT); + + IgniteCache<UUID, Organization> orgCache = clientNode.cache(ORGANIZATION_CACHE); + + Organization[] organizations = new Organization[ORGANIZATION_ROWS_COUNT]; + + for (int i = 0; i < ORGANIZATION_ROWS_COUNT; i++) { + Organization org = new Organization("Org Name " + i); + + organizations[i] = org; + + orgCache.put(org.getId(), org); + } + + System.out.println("Populated organizations: " + ORGANIZATION_ROWS_COUNT); + + IgniteCache<AffinityKey<UUID>, Department> depCache = clientNode.cache(DEPARTMENT_CACHE); + + Department[] departments = new Department[DEPARTMENT_ROWS_COUNT]; + + for (int i = 0; i < DEPARTMENT_ROWS_COUNT; i++) { + Department dep = new Department("Dep Name " + i, cities[rand.nextInt(CITY_ROWS_COUNT)], + organizations[rand.nextInt(ORGANIZATION_ROWS_COUNT)]); + + departments[i] = dep; + + try { + depCache.put(dep.getKey(), dep); + } + catch (Exception e) { + System.out.println("ROW: " + i); + e.printStackTrace(); + } + } + + System.out.println("Populated departments: " + DEPARTMENT_ROWS_COUNT); + + cities = null; + organizations = null; + + personCache = clientNode.cache(PERSON_CACHE); + + for (int i = 0; i < PERSON_ROWS_COUNT; i++) { + Person person = new Person(departments[rand.nextInt(DEPARTMENT_ROWS_COUNT)], "First Name " + i, + "Last Name " + i, rand.nextInt(21), "Title " + i, rand.nextInt(90), rand.nextInt(SALARY_LIMIT)); + + personCache.put(person.getKey(), person); + } + + System.out.println("Populated persons: " + PERSON_ROWS_COUNT); + + System.out.printf(""); + } + + //@Setup (Level.Trial) + public void startOldNodes() { + System.out.println(); + + System.out.println("Using OLD marshaller"); + + Ignition.start(createOldConfiguration("server1")); + Ignition.start(createOldConfiguration("server2")); + Ignition.start(createOldConfiguration("server3")); + + IgniteConfiguration clientCfg = createOldConfiguration("client"); + clientCfg.setClientMode(true); + + clientNode = Ignition.start(clientCfg); + + populateCaches(); + } + + @Setup (Level.Trial) + public void startNewNodes() { + System.out.println(); + + System.out.println("Using NEW marshaller"); + + Ignition.start(createNewConfiguration("server1")); + Ignition.start(createNewConfiguration("server2")); + Ignition.start(createNewConfiguration("server3")); + + IgniteConfiguration clientCfg = createNewConfiguration("client"); + clientCfg.setClientMode(true); + + clientNode = Ignition.start(clientCfg); + + populateCaches(); + } + + @TearDown (Level.Trial) + public void stopNodes() { + Ignition.stopAll(true); + } + + //@GenerateMicroBenchmark + public void sqlQuerySimple() { + String sql = "salary > ? and salary <= ?"; + + List<Cache.Entry<AffinityKey<UUID>, Person>> result = + personCache.query(new SqlQuery<AffinityKey<UUID>, Person>(Person.class, sql). + setArgs(0, 200000)).getAll(); + + if (result.size() == 0) + throw new RuntimeException("Invalid result size"); + } + + //@GenerateMicroBenchmark + public void sqlQueryWithJoin() { + // SQL clause query which joins on 2 types to select people for a specific organization. + String joinSql = + "from Person, \"" + DEPARTMENT_CACHE + "\".Department as dep " + + "where Person.depId = dep.id " + + "and lower(dep.name) = lower(?)"; + + // Execute queries for find employees for different organizations. + List<Cache.Entry<AffinityKey<UUID>, Person>> result = + personCache.query(new SqlQuery<AffinityKey<UUID>, Person>(Person.class, joinSql). + setArgs("Dep Name 1")).getAll(); + + if (result.size() == 0) + throw new RuntimeException("Invalid result size"); + } + + @GenerateMicroBenchmark + public void sqlQueryWithAggregation() { + // Calculate average of salary of all persons in ApacheIgnite. + // Note that we also join on Organization cache as well. + Random rand = new Random(); + + String sql = +// "select Person.firstName, Person.lastName, Person.salary " + + "select Person.firstName, city.name " + + "from Person, \"" + DEPARTMENT_CACHE + "\".Department as dep, " + + "\"" + CITY_CACHE + "\".City as city " + + "where Person.depId = dep.id and dep.cityId = city.id " + + "and city.population > ? and city.population <= ?"; + + QueryCursor<List<?>> cursor = personCache.query(new SqlFieldsQuery(sql).setArgs(rand.nextInt(1000), + rand.nextInt(10000000))); + + if (cursor.getAll().size() == 0) + System.err.println("Invalid result size"); + } + + + public static void main(String... args) throws Exception { + Options opts = new OptionsBuilder() + .include(".*" + SeveralNodesQueryMarshallerBenchmark.class.getSimpleName() + ".*") + .warmupIterations(15) + .measurementIterations(35) + .jvmArgs("-server") + .forks(1) + .outputFormat(OutputFormatType.TextReport) + .build(); + + new Runner(opts).run(); + } + +// public static void main(String... args) throws Exception { +// SeveralNodesQueryMarshallerBenchmark benchmark = new SeveralNodesQueryMarshallerBenchmark(); +// +// benchmark.startNewNodes(); +// +// for (int i = 0; i < 20000; i++) { +// benchmark.sqlQueryWithAggregation(); +// +// if (i != 0 && i % 2000 == 0) { +// System.out.println("Iteration: " + i); +// break; +// } +// } +// +// //benchmark.stopNodes(); +// } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc19b086/modules/yardstick/src/main/java/org/apache/ignite/jmh/SimpleMarshallerBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/jmh/SimpleMarshallerBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/jmh/SimpleMarshallerBenchmark.java new file mode 100644 index 0000000..2fb6f8f --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/jmh/SimpleMarshallerBenchmark.java @@ -0,0 +1,208 @@ +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.jmh; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.cache.query.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.jmh.model.*; +import org.apache.ignite.marshaller.*; +import org.apache.ignite.marshaller.optimized.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.logic.results.*; +import org.openjdk.jmh.output.*; +import org.openjdk.jmh.runner.*; +import org.openjdk.jmh.runner.options.*; + +import javax.cache.*; +import java.util.*; +import java.util.concurrent.*; + +/** + * + */ +@State +public class SimpleMarshallerBenchmark { + + private TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + private Ignite node; + + private IgniteCache<Integer, PersonSimple> cache; + + private static final int ROWS_COUNT = 50000; + + private IgniteConfiguration createConfiguration(String gridName, Marshaller marshaller) { + IgniteConfiguration cfg = new IgniteConfiguration(); + + cfg.setGridName(gridName); + + TcpDiscoverySpi spi = new TcpDiscoverySpi(); + spi.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(spi); + + cfg.setMarshaller(marshaller); + + CacheConfiguration cCfg = new CacheConfiguration(); + cCfg.setName("query"); + cCfg.setCacheMode(CacheMode.PARTITIONED); + cCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC); + cCfg.setSwapEnabled(false); + + /*cCfg.setMemoryMode(CacheMemoryMode.OFFHEAP_TIERED); + cCfg.setOffHeapMaxMemory(0); + cCfg.setSqlOnheapRowCacheSize(1);*/ + + CacheTypeMetadata meta = new CacheTypeMetadata(); + + meta.setKeyType(Integer.class); + meta.setValueType(PersonSimple.class); + + HashMap<String, Class<?>> indexes = new HashMap<>(); + indexes.put("id", Integer.class); + indexes.put("orgId", Integer.class); + indexes.put("salary", Double.class); + + meta.setAscendingFields(indexes); + + HashMap<String, Class<?>> queryFields = new HashMap<>(); + queryFields.put("firstName", String.class); + queryFields.put("lastName", String.class); + + meta.setQueryFields(queryFields); + + cCfg.setTypeMetadata(Arrays.asList(meta)); + + cfg.setCacheConfiguration(cCfg); + + return cfg; + } + + @TearDown + public void stopNodes() { + Ignition.stopAll(true); + } + + //@Setup + public void startOldNodes() { + System.out.println(); + System.out.println("STARTED OLD NODE"); + + OptimizedMarshaller marsh = new OptimizedMarshaller(); + marsh.setProtocolVersion(OptimizedMarshallerProtocolVersion.VER_1); + + node = Ignition.start(createConfiguration("node", marsh)); + + cache = node.cache("query"); + + for (int i = 0; i < ROWS_COUNT; i++) { + PersonSimple person = new PersonSimple(i, "Name ", "Surname ", (i + 1) * 100); + cache.put(i, person); + } + } + + @Setup + public void startNewNodes() { + System.out.println(); + System.out.println("STARTED NEW NODE"); + + OptimizedMarshaller marsh = new OptimizedMarshaller(); + marsh.setProtocolVersion(OptimizedMarshallerProtocolVersion.VER_1_1); + + node = Ignition.start(createConfiguration("node", marsh)); + + cache = node.cache("query"); + + for (int i = 0; i < ROWS_COUNT; i++) { + PersonSimple person = new PersonSimple(i, "Name ", "Surname ", (i + 1) * 100); + cache.put(i, person); + } + } + + + //@GenerateMicroBenchmark + public void testQuery() throws Exception { + double salary = ThreadLocalRandom.current().nextInt(0, ROWS_COUNT); + + double maxSalary = salary + 100; + + SqlQuery qry = new SqlQuery(PersonSimple.class, "salary >= ? and salary <= ?"); + + qry.setArgs(salary, maxSalary); + + Collection<Cache.Entry<Integer, Object>> entries = cache.query(qry).getAll(); + + entries.size(); + +// Collection<Cache.Entry<Integer, PersonSimple>> entries = cache.query(qry).getAll(); +// +// for (Cache.Entry<Integer, PersonSimple> entry : entries) { +// PersonSimple p = entry.getValue(); +// +// if (p.getSalary() < salary || p.getSalary() > maxSalary) +// throw new Exception("Invalid person retrieved [min=" + salary + ", max=" + maxSalary + +// ", person=" + p + ']'); +// } + } + + @GenerateMicroBenchmark + public void testFieldsQuery() throws Exception { + double salary = ThreadLocalRandom.current().nextInt(0, ROWS_COUNT); + + double maxSalary = salary + 100; + + SqlFieldsQuery qry = new SqlFieldsQuery("SELECT PersonSimple.firstName, PersonSimple.lastName FROM " + + "PersonSimple WHERE salary >= ? and salary <= ?"); + + qry.setArgs(salary, maxSalary); + + List<List<?>> result = cache.query(qry).getAll(); + + for (List<?> row : result) { + if (row.get(0) == null || row.get(1) == null) + throw new Exception("Invalid person retrieved [min=" + salary + ", max=" + maxSalary + + ", person=" + row + ']'); + } + } + +// public static void main(String args[]) throws Exception { +// SimpleMarshallerBenchmark benchmark = new SimpleMarshallerBenchmark(); +// +// benchmark.startOldNodes(); +// +// for (int i = 0; i < 500000000; i++) { +// benchmark.testFieldsQuery(); +// +// if (i % 10000 == 0) +// System.out.println("Iteration: " + i); +// } +// +// benchmark.stopNodes(); +// } + + + public static void main(String... args) throws Exception { + Options opts = new OptionsBuilder() + .include(".*" + SimpleMarshallerBenchmark.class.getSimpleName() + ".*") + .warmupIterations(15) + .measurementIterations(35) + .jvmArgs("-server") + .forks(1) + .outputFormat(OutputFormatType.TextReport) + //.shouldDoGC(true) + .build(); + + new Runner(opts).run(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc19b086/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/City.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/City.java b/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/City.java new file mode 100644 index 0000000..f2ca065 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/City.java @@ -0,0 +1,72 @@ +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.jmh.model; + +import org.apache.ignite.cache.query.annotations.*; + +import java.io.*; +import java.util.*; + +/** + * Created by GridAdmin1234 on 6/25/2015. + */ +public class City implements Serializable { + @QuerySqlField(index = true) + private UUID id; + + @QuerySqlField + private String name; + + @QuerySqlField + private int population; + + @QuerySqlField + private int age; + + private String country; + + public City(String name, int population, int age, String country) { + id = UUID.randomUUID(); + + this.name = name; + this.population = population; + this.age = age; + this.country = country; + } + + public UUID getId() { + return id; + } + + public String getName() { + return name; + } + + public int getPopulation() { + return population; + } + + public int getAge() { + return age; + } + + public String getCountry() { + return country; + } + + @Override public String toString() { + return "City{" + + "id=" + id + + ", name='" + name + '\'' + + ", population=" + population + + ", age=" + age + + ", country='" + country + '\'' + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc19b086/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/Department.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/Department.java b/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/Department.java new file mode 100644 index 0000000..a1a6633 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/Department.java @@ -0,0 +1,75 @@ +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.jmh.model; + +import org.apache.ignite.cache.affinity.*; +import org.apache.ignite.cache.query.annotations.*; + +import java.io.*; +import java.util.*; + +/** + * Created by GridAdmin1234 on 6/25/2015. + */ +public class Department implements Serializable { + @QuerySqlField(index = true) + private UUID id; + + @QuerySqlField (index = true) + private UUID cityId; + + @QuerySqlField (index = true) + private UUID orgId; + + @QuerySqlField + private String name; + + private transient AffinityKey<UUID> key; + + public Department(String name, City city, Organization org) { + id = UUID.randomUUID(); + + cityId = city.getId(); + orgId = org.getId(); + + this.name = name; + } + + public UUID getId() { + return id; + } + + public UUID getCityId() { + return cityId; + } + + public UUID getOrgId() { + return orgId; + } + + public String getName() { + return name; + } + + public AffinityKey<UUID> getKey() { + if (key == null) + key = new AffinityKey<>(id, cityId); + + return key; + } + + @Override public String toString() { + return "Department{" + + "id=" + id + + ", cityId=" + cityId + + ", orgId=" + orgId + + ", name='" + name + '\'' + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc19b086/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/Organization.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/Organization.java b/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/Organization.java new file mode 100644 index 0000000..a0882ef --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/Organization.java @@ -0,0 +1,39 @@ +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.jmh.model; + +import org.apache.ignite.cache.query.annotations.*; + +import java.io.*; +import java.util.*; + +/** + * Created by GridAdmin1234 on 6/25/2015. + */ +public class Organization implements Serializable { + @QuerySqlField (index = true) + private UUID id; + + @QuerySqlField + private String name; + + public Organization(String name) { + id = UUID.randomUUID(); + + this.name = name; + } + + public UUID getId() { + return id; + } + + public String getName() { + return name; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc19b086/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/Person.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/Person.java b/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/Person.java new file mode 100644 index 0000000..e9d7331 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/Person.java @@ -0,0 +1,97 @@ +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.jmh.model; + +import org.apache.ignite.cache.affinity.*; +import org.apache.ignite.cache.query.annotations.*; + +import java.io.*; +import java.util.*; + +/** + * Created by GridAdmin1234 on 6/25/2015. + */ +public class Person implements Serializable { + @QuerySqlField (index = true) + private UUID id; + + @QuerySqlField (index = true) + private UUID depId; + + @QuerySqlField + private String firstName; + + @QuerySqlField + private String lastName; + + @QuerySqlField + private int rank; + + @QuerySqlField + private String title; + + @QuerySqlField + private int age; + + @QuerySqlField + private int salary; + + private transient AffinityKey<UUID> key; + + public Person(Department dep, String firstName, String lastName, int rank, String title, int age, int salary) { + id = UUID.randomUUID(); + depId = dep.getId(); + + this.firstName = firstName; + this.lastName = lastName; + this.rank = rank; + this.title = title; + this.age = age; + this.salary = salary; + } + + public UUID getId() { + return id; + } + + public UUID getDepId() { + return depId; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public int getRank() { + return rank; + } + + public String getTitle() { + return title; + } + + public int getAge() { + return age; + } + + public int getSalary() { + return salary; + } + + public AffinityKey<UUID> getKey() { + if (key == null) + key = new AffinityKey<>(id, depId); + + return key; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc19b086/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/PersonExternalizable.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/PersonExternalizable.java b/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/PersonExternalizable.java new file mode 100644 index 0000000..854f95e --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/PersonExternalizable.java @@ -0,0 +1,190 @@ +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.jmh.model; + +import org.apache.ignite.cache.query.annotations.*; + +import java.io.*; + +/** + * Person record used for query test. + */ +public class PersonExternalizable implements Externalizable { + /** Person ID. */ + @QuerySqlField(index = true) + private int id; + + /** Organization ID. */ + @QuerySqlField(index = true) + private int orgId; + + /** First name (not-indexed). */ + @QuerySqlField + private String firstName; + + /** Last name (not indexed). */ + @QuerySqlField + private String lastName; + + /** Salary. */ + @QuerySqlField(index = true) + private double salary; + + /** + * Constructs empty person. + */ + public PersonExternalizable() { + // No-op. + } + + /** + * Constructs person record that is not linked to any organization. + * + * @param id Person ID. + * @param firstName First name. + * @param lastName Last name. + * @param salary Salary. + */ + public PersonExternalizable(int id, String firstName, String lastName, double salary) { + this(id, 0, firstName, lastName, salary); + } + + /** + * Constructs person record. + * + * @param id Person ID. + * @param orgId Organization ID. + * @param firstName First name. + * @param lastName Last name. + * @param salary Salary. + */ + public PersonExternalizable(int id, int orgId, String firstName, String lastName, double salary) { + this.id = id; + this.orgId = orgId; + this.firstName = firstName; + this.lastName = lastName; + this.salary = salary; + } + + /** + * @return Person id. + */ + public int getId() { + return id; + } + + /** + * @param id Person id. + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return Organization id. + */ + public int getOrganizationId() { + return orgId; + } + + /** + * @param orgId Organization id. + */ + public void setOrganizationId(int orgId) { + this.orgId = orgId; + } + + /** + * @return Person first name. + */ + public String getFirstName() { + return firstName; + } + + /** + * @param firstName Person first name. + */ + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + /** + * @return Person last name. + */ + public String getLastName() { + return lastName; + } + + /** + * @param lastName Person last name. + */ + public void setLastName(String lastName) { + this.lastName = lastName; + } + + /** + * @return Salary. + */ + public double getSalary() { + return salary; + } + + /** + * @param salary Salary. + */ + public void setSalary(double salary) { + this.salary = salary; + } + + /** {@inheritDoc} */ + @Override public void writeExternal(ObjectOutput out) throws IOException { + out.writeInt(id); + out.writeInt(orgId); + out.writeUTF(firstName); + out.writeUTF(lastName); + out.writeDouble(salary); + } + + /** {@inheritDoc} */ + @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + id = in.readInt(); + orgId = in.readInt(); + firstName = in.readUTF(); + lastName = in.readUTF(); + salary = in.readDouble(); + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + return this == o || (o instanceof PersonExternalizable) && id == ((PersonExternalizable)o).id; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return id; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return "Person [firstName=" + firstName + + ", id=" + id + + ", orgId=" + orgId + + ", lastName=" + lastName + + ", salary=" + salary + + ']'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc19b086/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/PersonMarshalAware.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/PersonMarshalAware.java b/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/PersonMarshalAware.java new file mode 100644 index 0000000..8e80db6 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/PersonMarshalAware.java @@ -0,0 +1,199 @@ +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.jmh.model; + +import org.apache.ignite.cache.query.annotations.*; +import org.apache.ignite.marshaller.optimized.*; + +import java.io.*; + +/** + * Person record used for query test. + */ +public class PersonMarshalAware implements OptimizedMarshalAware { + /** Person ID. */ + @QuerySqlField(index = true) + private int id; + + /** Organization ID. */ + @QuerySqlField(index = true) + private int orgId; + + /** First name (not-indexed). */ + @QuerySqlField + private String firstName; + + /** Last name (not indexed). */ + @QuerySqlField + private String lastName; + + /** Salary. */ + @QuerySqlField(index = true) + private double salary; + + /** + * Constructs empty person. + */ + public PersonMarshalAware() { + // No-op. + } + + /** + * Constructs person record that is not linked to any organization. + * + * @param id Person ID. + * @param firstName First name. + * @param lastName Last name. + * @param salary Salary. + */ + public PersonMarshalAware(int id, String firstName, String lastName, double salary) { + this(id, 0, firstName, lastName, salary); + } + + /** + * Constructs person record. + * + * @param id Person ID. + * @param orgId Organization ID. + * @param firstName First name. + * @param lastName Last name. + * @param salary Salary. + */ + public PersonMarshalAware(int id, int orgId, String firstName, String lastName, double salary) { + this.id = id; + this.orgId = orgId; + this.firstName = firstName; + this.lastName = lastName; + this.salary = salary; + } + + /** + * @return Person id. + */ + public int getId() { + return id; + } + + /** + * @param id Person id. + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return Organization id. + */ + public int getOrganizationId() { + return orgId; + } + + /** + * @param orgId Organization id. + */ + public void setOrganizationId(int orgId) { + this.orgId = orgId; + } + + /** + * @return Person first name. + */ + public String getFirstName() { + return firstName; + } + + /** + * @param firstName Person first name. + */ + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + /** + * @return Person last name. + */ + public String getLastName() { + return lastName; + } + + /** + * @param lastName Person last name. + */ + public void setLastName(String lastName) { + this.lastName = lastName; + } + + /** + * @return Salary. + */ + public double getSalary() { + return salary; + } + + /** + * @param salary Salary. + */ + public void setSalary(double salary) { + this.salary = salary; + } + + /** {@inheritDoc} */ + @Override public void writeFields(OptimizedFieldsWriter writer) throws IOException { + writer.writeInt("id", id); + writer.writeInt("orgId", orgId); + writer.writeString("firstName", firstName); + writer.writeString("lastName", lastName); + writer.writeDouble("salary", salary); + } + + /** {@inheritDoc} */ + @Override public void readFields(OptimizedFieldsReader reader) throws IOException { + id = reader.readInt("id"); + orgId = reader.readInt("orgId"); + firstName = reader.readString("firstName"); + lastName = reader.readString("lastName"); + salary = reader.readDouble("salary"); + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + return this == o || (o instanceof PersonMarshalAware) && id == ((PersonMarshalAware)o).id; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return id; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return "Person [firstName=" + firstName + + ", id=" + id + + ", orgId=" + orgId + + ", lastName=" + lastName + + ", salary=" + salary + + ']'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cc19b086/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/PersonSimple.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/PersonSimple.java b/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/PersonSimple.java new file mode 100644 index 0000000..b749de1 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/jmh/model/PersonSimple.java @@ -0,0 +1,172 @@ +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +/* + * _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.apache.ignite.jmh.model; + +import org.apache.ignite.cache.query.annotations.*; + +import java.io.*; + +/** + * Person record used for query test. + */ +public class PersonSimple implements Serializable { + /** Person ID. */ + @QuerySqlField(index = true) + private int id; + + /** Organization ID. */ + @QuerySqlField(index = true) + private int orgId; + + /** First name (not-indexed). */ + @QuerySqlField + private String firstName; + + /** Last name (not indexed). */ + @QuerySqlField + private String lastName; + + /** Salary. */ + @QuerySqlField(index = true) + private double salary; + + /** + * Constructs empty person. + */ + public PersonSimple() { + // No-op. + } + + /** + * Constructs person record that is not linked to any organization. + * + * @param id Person ID. + * @param firstName First name. + * @param lastName Last name. + * @param salary Salary. + */ + public PersonSimple(int id, String firstName, String lastName, double salary) { + this(id, 0, firstName, lastName, salary); + } + + /** + * Constructs person record. + * + * @param id Person ID. + * @param orgId Organization ID. + * @param firstName First name. + * @param lastName Last name. + * @param salary Salary. + */ + public PersonSimple(int id, int orgId, String firstName, String lastName, double salary) { + this.id = id; + this.orgId = orgId; + this.firstName = firstName; + this.lastName = lastName; + this.salary = salary; + } + + /** + * @return Person id. + */ + public int getId() { + return id; + } + + /** + * @param id Person id. + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return Organization id. + */ + public int getOrganizationId() { + return orgId; + } + + /** + * @param orgId Organization id. + */ + public void setOrganizationId(int orgId) { + this.orgId = orgId; + } + + /** + * @return Person first name. + */ + public String getFirstName() { + return firstName; + } + + /** + * @param firstName Person first name. + */ + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + /** + * @return Person last name. + */ + public String getLastName() { + return lastName; + } + + /** + * @param lastName Person last name. + */ + public void setLastName(String lastName) { + this.lastName = lastName; + } + + /** + * @return Salary. + */ + public double getSalary() { + return salary; + } + + /** + * @param salary Salary. + */ + public void setSalary(double salary) { + this.salary = salary; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + return this == o || (o instanceof PersonSimple) && id == ((PersonSimple)o).id; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return id; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return "Person [firstName=" + firstName + + ", id=" + id + + ", orgId=" + orgId + + ", lastName=" + lastName + + ", salary=" + salary + + ']'; + } +}