You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/11/25 14:29:31 UTC
ignite git commit: ignite-sql-opt-2
Repository: ignite
Updated Branches:
refs/heads/ignite-sql-opt-2 3eeeb8c29 -> 6975e5623
ignite-sql-opt-2
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6975e562
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6975e562
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6975e562
Branch: refs/heads/ignite-sql-opt-2
Commit: 6975e562357b100b176bcf170cf674c5425f978b
Parents: 3eeeb8c
Author: sboikov <sb...@gridgain.com>
Authored: Wed Nov 25 16:26:29 2015 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Nov 25 16:26:29 2015 +0300
----------------------------------------------------------------------
.../yardstick/cache/IgniteTempSqlBenchmark.java | 232 ------------------
.../apache/ignite/yardstick/h2/H2Benchmark.java | 234 -------------------
2 files changed, 466 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/6975e562/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteTempSqlBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteTempSqlBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteTempSqlBenchmark.java
deleted file mode 100644
index e24fe02..0000000
--- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteTempSqlBenchmark.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * 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.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.ConcurrentSkipListMap;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.atomic.AtomicLong;
-import javax.cache.Cache;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteDataStreamer;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.cache.query.SqlFieldsQuery;
-import org.apache.ignite.cache.query.SqlQuery;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.yardstick.cache.model.Person;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
-
-/**
- * -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=delay=60s,duration=120s,filename=sql_benchmark_client1.jfr
- */
-public class IgniteTempSqlBenchmark {
- public static void main(String[] args) throws Exception {
- IgniteConfiguration cfg = new IgniteConfiguration();
-
- //cfg.setClientMode(true);
-
- cfg.setLocalHost("127.0.0.1");
-
- TcpDiscoverySpi spi = new TcpDiscoverySpi();
-
- TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
- ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500","127.0.0.1:47501","127.0.0.1:47502"));
-
- spi.setIpFinder(ipFinder);
-
- cfg.setDiscoverySpi(spi);
-
- CacheConfiguration ccfg = new CacheConfiguration();
-
- ccfg.setName("cache");
- ccfg.setCacheMode(PARTITIONED);
- ccfg.setAtomicityMode(ATOMIC);
- ccfg.setBackups(1);
- ccfg.setWriteSynchronizationMode(FULL_SYNC);
- ccfg.setIndexedTypes(Integer.class, Person.class);
-
- cfg.setCacheConfiguration(ccfg);
-
- final Ignite ignite = Ignition.start(cfg);
-
- final int QRY_THREADS = 10;
- final int PUT_THREADS = 10;
-
- final AtomicLong qryCntr = new AtomicLong();
- final AtomicLong putCntr = new AtomicLong();
-
- List<Thread> threads = new ArrayList<>();
-
- final IgniteCache<Integer, Person> cache = ignite.cache("cache");
-
- final int RANGE = 2 * 500_000;
-
- long start = System.nanoTime();
-
- try (IgniteDataStreamer<Integer, Person> dataLdr = ignite.dataStreamer(cache.getName())) {
- for (int i = 0; i < RANGE; i++) {
- dataLdr.addData(i, new Person(i, "firstName" + i, "lastName" + i, i * 1000));
-
- if (i % 100000 == 0)
- System.out.println("Populated persons: " + i);
- }
- }
-
- System.out.println("Finished populating query data in " + ((System.nanoTime() - start) / 1_000_000) + " ms.");
-
- System.out.println("Plan : \n" + cache.query(
- new SqlFieldsQuery("explain select _val from Person where salary >= ? and salary <= ?")
- .setArgs(Integer.MIN_VALUE, Integer.MAX_VALUE)).getAll());
-
- System.out.println("Size : \n" + cache.query(
- new SqlFieldsQuery("select _val from Person where salary >= ? and salary <= ?")
- .setArgs(1000, 2000)).getAll().size());
-
- for (int i = 0; i < QRY_THREADS; i++) {
- Thread thread = new Thread() {
- public void run() {
- System.out.println("Started thread");
-
- ThreadLocalRandom rnd = ThreadLocalRandom.current();
-
- while (true) {
- double salary = rnd.nextDouble() * RANGE * 1000;
-
- double maxSalary = salary + 1000;
-
- Collection<Cache.Entry<Integer, Object>> entries = executeQuery(salary, maxSalary);
-
- for (Cache.Entry<Integer, Object> entry : entries) {
- Person p = (Person)entry.getValue();
-
- if (p.getSalary() < salary || p.getSalary() > maxSalary) {
- throw new RuntimeException("Invalid person retrieved [min=" + salary + ", max=" + maxSalary +
- ", person=" + p + ']');
- }
- }
-
- qryCntr.incrementAndGet();
- }
- }
-
- /**
- * @param minSalary Min salary.
- * @param maxSalary Max salary.
- * @return Query result.
- */
- private Collection<Cache.Entry<Integer, Object>> executeQuery(double minSalary, double maxSalary) {
- SqlQuery qry = new SqlQuery(Person.class, "salary >= ? and salary <= ?");
-
- qry.setArgs(minSalary, maxSalary);
-
- return cache.query(qry).getAll();
- }
- };
-
- threads.add(thread);
- }
- for (int i = 0; i < PUT_THREADS; i++) {
- Thread thread = new Thread() {
- public void run() {
- System.out.println("Started thread");
-
- ThreadLocalRandom rnd = ThreadLocalRandom.current();
-
- List<ConcurrentSkipListMap<Integer, Person>> maps = new ArrayList<>();
-
-// for (int i = 0; i < 4; i++)
-// maps.add(new ConcurrentSkipListMap<Integer, Person>());
-//
-// while (true) {
-// Integer k = rnd.nextInt(RANGE);
-//
-// Person p = new Person(k, "firstName" + k, "lastName" + k, k * 1000);
-//
-// for (int i = 0; i < maps.size(); i++) {
-// ConcurrentSkipListMap<Integer, Person> cache = maps.get(i);
-//
-// cache.put(k, p);
-// }
-//
-// putCntr.incrementAndGet();
-// }
-
- while (true) {
- Integer k = rnd.nextInt(RANGE);
-
- Person p = new Person(k, "firstName" + k, "lastName" + k, k * 1000);
-
- cache.put(k, p);
-
- putCntr.incrementAndGet();
- }
- }
- };
-
- threads.add(thread);
- }
-
- for (Thread thread : threads)
- thread.start();
-
- Thread.sleep(10_000);
-
- System.out.println("Warmup finished");
-
- long total = 0;
- long total2 = 0;
- long cnt = 0;
-
- long endTime = System.currentTimeMillis() + 90_000;
-
- while (System.currentTimeMillis() < endTime) {
- long c1 = qryCntr.get();
- long p1 = putCntr.get();
-
- Thread.sleep(5000);
-
- long c2 = qryCntr.get();
- long p2 = putCntr.get();
-
- long ops = (long)((c2 - c1) / 5f);
- long ops2 = (long)((p2 - p1) / 5f);
-
- total += ops;
- total2 += ops2;
- cnt++;
-
- System.out.println("Queries: " + ops + " Puts: " + ops2);
- }
-
- System.out.println("Result: " + total / (float)cnt + " " + total2 / (float)cnt);
-
- //ignite.compute().run(new Exit());
-
- System.exit(0);
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/6975e562/modules/yardstick/src/main/java/org/apache/ignite/yardstick/h2/H2Benchmark.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/h2/H2Benchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/h2/H2Benchmark.java
deleted file mode 100644
index 5e11d44..0000000
--- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/h2/H2Benchmark.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * 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.h2;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.yardstick.cache.model.Person;
-import org.yardstickframework.BenchmarkConfiguration;
-import org.yardstickframework.BenchmarkDriverAdapter;
-
-import static org.yardstickframework.BenchmarkUtils.println;
-
-/**
- *
- */
-public class H2Benchmark extends BenchmarkDriverAdapter {
- /** Default DB options. */
- private static final String DB_OPTIONS = ";LOCK_MODE=3;MULTI_THREADED=1;DB_CLOSE_ON_EXIT=FALSE" +
- ";DEFAULT_LOCK_TIMEOUT=10000;FUNCTIONS_IN_SCHEMA=true;OPTIMIZE_REUSE_RESULTS=0;QUERY_CACHE_SIZE=0;" +
- "RECOMPILE_ALWAYS=1;MAX_OPERATION_MEMORY=0";
-
- /** */
- // TODO from arguments?!
- public static final double RANGE = 1_000_000;
-
- /** */
- private static final String CONNECTION_KEY = "CONNECTION_KEY";
-
- /** */
- private Connection[] conns;
-
- /** */
- private final AtomicInteger threadNum = new AtomicInteger();
-
- /** {@inheritDoc} */
- @Override public void setUp(BenchmarkConfiguration cfg) throws Exception {
- super.setUp(cfg);
-
- conns = new Connection[cfg.threads()];
-
- for (int i = 0; i < conns.length; i++)
- conns[i] = openH2Connection(false);
-
- Connection conn = conns[0];
-
- initializeH2Schema(conn);
-
- println(cfg, "Populating query data...");
-
- long start = System.nanoTime();
-
- for (int i = 0; i < RANGE && !Thread.currentThread().isInterrupted(); i++) {
- insertInDb(conn, new Person(i, "firstName" + i, "lastName" + i, i * 1000));
-
- if (i % 100000 == 0)
- println(cfg, "Populated persons: " + i);
- }
-
- conn.commit();
-
- println(cfg, "Finished populating query data in " + ((System.nanoTime() - start) / 1_000_000) + " ms.");
- }
-
- /** {@inheritDoc} */
- @Override public void tearDown() throws Exception {
- super.tearDown();
-
- for (Connection conn : conns)
- conn.close();
- }
-
- /**
- * Gets connection from a pool.
- *
- * @param autocommit {@code true} If connection should use autocommit mode.
- * @return Pooled connection.
- * @throws SQLException In case of error.
- */
- private static Connection openH2Connection(boolean autocommit) throws SQLException {
- System.setProperty("h2.serializeJavaObject", "false");
- System.setProperty("h2.objectCacheMaxPerElementSize", "0"); // Avoid ValueJavaObject caching.
-
- String dbName = "test";
-
- Connection conn = DriverManager.getConnection("jdbc:h2:mem:" + dbName + DB_OPTIONS);
-
- conn.setAutoCommit(autocommit);
-
- return conn;
- }
-
- /**
- * Initialize h2 database schema.
- *
- * @param conn Connection.
- * @throws SQLException If exception.
- */
- protected static void initializeH2Schema(Connection conn) throws SQLException {
- Statement st = conn.createStatement();
-
- st.execute("CREATE SCHEMA \"test\"");
-
- st.execute("create table \"test\".PERSON" +
- " (_key other not null ," +
- " _val other not null ," +
- " id int unique, " +
- " firstName varchar(255), " +
- " lastName varchar(255)," +
- " orgId int not null," +
- " salary double)");
-
- st.execute("create INDEX person_salary_idx on \"test\".PERSON(salary)");
-
- conn.commit();
- }
-
- /**
- * @param p Person.
- * @throws SQLException If exception.
- */
- private static void insertInDb(Connection conn, Person p) throws SQLException {
- try(PreparedStatement st = conn.prepareStatement("insert into \"test\".PERSON " +
- "(_key, _val, id, orgId, firstName, lastName, salary) values(?, ?, ?, ?, ?, ?, ?)")) {
- st.setObject(1, p.getId(), Types.JAVA_OBJECT);
- st.setObject(2, p);
- st.setObject(3, p.getId());
- st.setObject(4, p.getOrganizationId());
- st.setObject(5, p.getFirstName());
- st.setObject(6, p.getLastName());
- st.setObject(7, p.getSalary());
-
- st.executeUpdate();
- }
- }
-
- /** {@inheritDoc} */
- @Override public boolean test(Map<Object, Object> ctx) throws Exception {
- Connection conn = (Connection)ctx.get(CONNECTION_KEY);
-
- if (conn == null) {
- int num = threadNum.getAndIncrement();
-
- conn = conns[num];
-
- ctx.put(CONNECTION_KEY, conn);
- }
-
- double salary = ThreadLocalRandom.current().nextDouble() * RANGE * 1000;
-
- double maxSalary = salary + 1000;
-
- String qry = "select _key, _val from \"test\".PERSON where salary >= ? and salary <= ?";
-
- List<List<?>> lists = executeH2Query(conn, qry, salary, maxSalary);
-
- for (List<?> list : lists) {
- if (list.size() != 2)
- throw new Exception("List: " + list);
-
- Person p = (Person)list.get(1);
-
- if (p.getSalary() < salary || p.getSalary() > maxSalary)
- throw new Exception("Invalid person retrieved [min=" + salary + ", max=" + maxSalary +
- ", person=" + p + ']');
- }
-
- return true;
- }
-
- /**
- * Execute SQL query on h2 database.
- *
- * @param sql SQL query.
- * @param args SQL arguments.
- * @return Result of SQL query on h2 database.
- * @throws SQLException If exception.
- */
- private static List<List<?>> executeH2Query(Connection conn, String sql, Object... args) throws SQLException {
- List<List<?>> res = new ArrayList<>();
- ResultSet rs = null;
-
- try(PreparedStatement st = conn.prepareStatement(sql)) {
- for (int idx = 0; idx < args.length; idx++)
- st.setObject(idx + 1, args[idx]);
-
- rs = st.executeQuery();
-
- ResultSetMetaData meta = rs.getMetaData();
-
- int colCnt = meta.getColumnCount();
-
- while (rs.next()) {
- List<Object> row = new ArrayList<>(colCnt);
-
- for (int i = 1; i <= colCnt; i++)
- row.add(rs.getObject(i));
-
- res.add(row);
- }
- }
- finally {
- U.closeQuiet(rs);
- }
-
- return res;
- }
-}
\ No newline at end of file