Repository: ignite Updated Branches: refs/heads/master 7c2ce4c74 -> b4bfd4c7c
SqlQueryFullScanBenchmark Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b4bfd4c7 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b4bfd4c7 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b4bfd4c7 Branch: refs/heads/master Commit: b4bfd4c7cd415fa8bb7132a4a8ee58e207500767 Parents: 7c2ce4c Author: Sergi Vladykin <[email protected]> Authored: Tue Dec 18 14:17:25 2018 +0300 Committer: Sergi Vladykin <[email protected]> Committed: Tue Dec 18 14:17:25 2018 +0300 ---------------------------------------------------------------------- .../cache/IgniteSqlQueryFullScanBenchmark.java | 97 +++++++++ .../yardstick/cache/model/PersonNoIndex.java | 215 +++++++++++++++++++ 2 files changed, 312 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/b4bfd4c7/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryFullScanBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryFullScanBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryFullScanBenchmark.java new file mode 100644 index 0000000..d7cf0a9 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteSqlQueryFullScanBenchmark.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.yardstick.cache; + +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ThreadLocalRandom; +import javax.cache.Cache; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.cache.query.SqlQuery; +import org.apache.ignite.yardstick.cache.model.PersonNoIndex; +import org.yardstickframework.BenchmarkConfiguration; + +import static org.yardstickframework.BenchmarkUtils.println; + +/** + * Ignite benchmark that performs query operations. + */ +public class IgniteSqlQueryFullScanBenchmark extends IgniteCacheAbstractBenchmark<Integer, Object> { + /** {@inheritDoc} */ + @Override public void setUp(BenchmarkConfiguration cfg) throws Exception { + super.setUp(cfg); + + loadCachesData(); + } + + /** {@inheritDoc} */ + @Override protected void loadCacheData(String cacheName) { + try (IgniteDataStreamer<Integer, PersonNoIndex> dataLdr = ignite().dataStreamer(cacheName)) { + for (int i = 0; i < args.range(); i++) { + if (i % 100 == 0 && Thread.currentThread().isInterrupted()) + break; + + dataLdr.addData(i, new PersonNoIndex(i, "firstName" + i, "lastName" + i, i * 1000)); + + if (i % 100000 == 0) + println(cfg, "Populated persons: " + i); + } + } + } + + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + double salary = ThreadLocalRandom.current().nextDouble() * args.range() * 1000; + + double maxSalary = salary + 1000; + + Collection<Cache.Entry<Integer, Object>> entries = executeQuery(salary, maxSalary); + + for (Cache.Entry<Integer, Object> entry : entries) { + PersonNoIndex p = (PersonNoIndex)entry.getValue(); + + if (p.getSalary() < salary || p.getSalary() > maxSalary) + throw new Exception("Invalid person retrieved [min=" + salary + ", max=" + maxSalary + + ", person=" + p + ']'); + } + + return true; + } + + /** + * @param minSalary Min salary. + * @param maxSalary Max salary. + * @return Query result. + * @throws Exception If failed. + */ + private Collection<Cache.Entry<Integer, Object>> executeQuery(double minSalary, double maxSalary) throws Exception { + IgniteCache<Integer, Object> cache = cacheForOperation(true); + + SqlQuery qry = new SqlQuery(PersonNoIndex.class, "salary >= ? and salary <= ?"); + + qry.setArgs(minSalary, maxSalary); + + return cache.query(qry).getAll(); + } + + /** {@inheritDoc} */ + @Override protected IgniteCache<Integer, Object> cache() { + return ignite().cache("query"); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/b4bfd4c7/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/PersonNoIndex.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/PersonNoIndex.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/PersonNoIndex.java new file mode 100644 index 0000000..39ef2f3 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/PersonNoIndex.java @@ -0,0 +1,215 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.yardstick.cache.model; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.apache.ignite.binary.BinaryObjectException; +import org.apache.ignite.binary.BinaryReader; +import org.apache.ignite.binary.BinaryWriter; +import org.apache.ignite.binary.Binarylizable; +import org.apache.ignite.cache.query.annotations.QuerySqlField; + +/** + * Person record used for query test. + */ +public class PersonNoIndex implements Externalizable, Binarylizable { + /** Person ID. */ + @QuerySqlField + private int id; + + /** Organization ID. */ + @QuerySqlField + private int orgId; + + /** First name (not-indexed). */ + @QuerySqlField + private String firstName; + + /** Last name (not indexed). */ + @QuerySqlField + private String lastName; + + /** Salary. */ + @QuerySqlField + private double salary; + + /** + * Constructs empty person. + */ + public PersonNoIndex() { + // 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 PersonNoIndex(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 PersonNoIndex(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 void writeBinary(BinaryWriter writer) throws BinaryObjectException { + writer.writeInt("id", id); + writer.writeInt("orgId", orgId); + writer.writeString("firstName", firstName); + writer.writeString("lastName", lastName); + writer.writeDouble("salary", salary); + } + + /** {@inheritDoc} */ + @Override public void readBinary(BinaryReader reader) throws BinaryObjectException { + 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 PersonNoIndex) && id == ((PersonNoIndex)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 + + ']'; + } +} \ No newline at end of file
