http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiClient.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiClient.java b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiClient.java deleted file mode 100644 index 1a33937..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiClient.java +++ /dev/null @@ -1,419 +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.gridgain.loadtests.dsi; - -import org.apache.ignite.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.internal.util.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.internal.util.typedef.*; -import org.gridgain.testframework.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -/** - * - */ -public class GridDsiClient implements Callable { - /** Stats update interval in seconds. */ - private static final int UPDATE_INTERVAL_SEC = 10; - - /** Grid. */ - private static Ignite g; - - /** Transaction count. */ - private static AtomicLong txCnt = new AtomicLong(); - - /** Latency. */ - private static AtomicLong latency = new AtomicLong(); - - /** Submit time. */ - private static GridAtomicLong submitTime = new GridAtomicLong(); - - /** Server stats. */ - private static volatile T3<Long, Integer, Integer> srvStats; - - /** Finish flag. */ - private static AtomicBoolean finish = new AtomicBoolean(); - - /** Terminal ID. */ - private String terminalId; - - /** Node ID. */ - private UUID nodeId; - - /** - * Client constructor. - * - * @param terminalId Terminal ID. - * @param nodeId Node ID. - */ - GridDsiClient(String terminalId, UUID nodeId) { - this.terminalId = terminalId; - this.nodeId = nodeId; - } - - /** - * Predicate to look for server node. - * - * @return {@code true} if node segment is 'server'. - */ - public static IgnitePredicate<ClusterNode> serverNode() { - return new IgnitePredicate<ClusterNode>() { - @Override public boolean apply(ClusterNode node) { - return "server".equals(node.attribute("segment")); - } - }; - } - - /** - * Predicate to look for client node. - * - * @return {@code true} if node segment is 'client'. - */ - public static IgnitePredicate<ClusterNode> clientNode() { - return new IgnitePredicate<ClusterNode>() { - @Override public boolean apply(ClusterNode node) { - return "client".equals(node.attribute("segment")); - } - }; - } - - /** {@inheritDoc} */ - @SuppressWarnings({"unchecked", "InfiniteLoopStatement"}) - @Nullable @Override public Object call() throws Exception { - IgniteCompute comp = g.compute(g.cluster().forPredicate(serverNode())).enableAsync(); - - while (!finish.get()) { - try { - long t0 = System.currentTimeMillis(); - - long submitTime1 = t0; - - comp.execute(GridDsiRequestTask.class, new GridDsiMessage(terminalId, nodeId)); - - ComputeTaskFuture<T3<Long, Integer, Integer>> f1 = comp.future(); - - submitTime.setIfGreater(System.currentTimeMillis() - submitTime1); - - T3<Long, Integer, Integer> res1 = f1.get(); - - submitTime1 = System.currentTimeMillis(); - - comp.execute(GridDsiResponseTask.class, new GridDsiMessage(terminalId, nodeId)); - - ComputeTaskFuture<T3<Long, Integer, Integer>> f2 = comp.future(); - - submitTime.setIfGreater(System.currentTimeMillis() - submitTime1); - - T3<Long, Integer, Integer> res2 = f2.get(); - - long t1 = System.currentTimeMillis(); - - txCnt.incrementAndGet(); - - latency.addAndGet(t1 - t0); - - if (res1 != null) - srvStats = res1; - - if (res2 != null) - srvStats = res2; - } - catch (IgniteCheckedException e) { - e.printStackTrace(); - } - } - - return null; - } - - /** - * Method to print request statistics. - */ - private static void displayReqCount() { - new Thread(new Runnable() { - @SuppressWarnings({"BusyWait", "InfiniteLoopStatement"}) - @Override public void run() { - int interval = 30; - - while (true) { - long cnt0 = txCnt.get(); - long lt0 = latency.get(); - - try { - Thread.sleep(interval * 1000); - } - catch (InterruptedException e) { - e.printStackTrace(); - } - - long cnt1 = txCnt.get(); - long lt1 = latency.get(); - - X.println(">>>"); - X.println(">>> Transaction/s: " + (cnt1 - cnt0) / interval); - X.println( - ">>> Avg Latency: " + ((cnt1 - cnt0) > 0 ? (lt1 - lt0) / (cnt1 - cnt0) + "ms" : "invalid")); - X.println(">>> Max Submit Time: " + submitTime.getAndSet(0)); - } - } - }).start(); - } - - /** - * Execute DSI load client. - * - * @param args Command line arguments, two required - first one is the number of threads, - * second one should point to the Spring XML configuration file. - * @throws Exception If client fails. - */ - @SuppressWarnings("unchecked") - public static void main(String[] args) throws Exception { - GridFileLock fileLock = GridLoadTestUtils.fileLock(); - - fileLock.lock(true); // Get shared lock, allowing multiple instances. - - try { - Ignition.start(args.length < 4 ? "modules/core/src/test/config/load/dsi-load-client.xml" : args[3]); - - Thread collector = null; - - Thread timer = null; - - try { - g = Ignition.ignite("dsi"); - - int noThreads = Integer.parseInt(args[0]); - - final int duration = args.length < 2 ? 0 : Integer.parseInt(args[1]); - - final String outputFileName = args.length < 3 ? null : args[2]; - - X.println("Thread count: " + noThreads); - - Collection<ClusterNode> srvNodes = g.cluster().forPredicate(serverNode()).nodes(); - - if (srvNodes.isEmpty()) { - X.println("No server nodes available"); - - System.exit(-1); - } - - X.println("No of servers: " + srvNodes.size()); - - int srvMaxNoTerminals = noThreads / srvNodes.size(); - - if (srvMaxNoTerminals * srvNodes.size() != noThreads) { - noThreads = srvMaxNoTerminals * srvNodes.size(); - - X.println("Using " + noThreads + " threads instead to ensure equal distribution of terminals"); - } - - Collection<Callable<Object>> clients = new ArrayList<>(noThreads); - - // No 2 client should use the same simulator. - HashMap<UUID, Collection<String>> terminals = (HashMap<UUID, Collection<String>>) - g.cache("CLIENT_PARTITIONED_CACHE").get("terminals"); - - if (terminals == null) { - X.println(">>> Terminals map has not been initialized."); - - terminals = new HashMap<>(srvNodes.size()); - - // Distribute terminals evenly across all servers. - for (ClusterNode node : srvNodes) { - UUID srvrId = node.id(); - - X.println(">>> Node ID: " + srvrId); - - Collection<String> list = terminals.get(srvrId); - - if (list == null) - list = new ArrayList<>(0); - - int terminalsPerSrv = 0; - - int tid = 0; // Terminal ID. - - while (true) { - String terminalId = String.valueOf(++tid); - - // Server partition cache. - if (!srvrId.equals(g.cluster().mapKeyToNode("PARTITIONED_CACHE", terminalId).id())) - continue; - - if (terminalsPerSrv < srvMaxNoTerminals) { - list.add(terminalId); - - clients.add(new GridDsiClient(terminalId, srvrId)); - - terminalsPerSrv++; - - X.println("Terminal ID: " + terminalId); - } - else - break; - } - - terminals.put(srvrId, list); - } - - g.cache("CLIENT_PARTITIONED_CACHE").putx("terminals", terminals); - } - else { - X.println(">>> Terminals map has been initialized."); - - for (Map.Entry<UUID, Collection<String>> e : terminals.entrySet()) { - X.println(">>> Node ID: " + e.getKey()); - - for (String s : e.getValue()) { - clients.add(new GridDsiClient(s, e.getKey())); - - X.println("Terminal ID: " + s); - } - } - } - - if (duration > 0) { - timer = new Thread(new Runnable() { - @Override public void run() { - try { - Thread.sleep(duration * 1000); - - finish.set(true); - } - catch (InterruptedException ignored) { - // No-op. - } - } - }); - timer.start(); - } - - collector = new Thread(new Runnable() { - @SuppressWarnings({"BusyWait", "InfiniteLoopStatement"}) - @Override public void run() { - long txPerSecond = -1; - long avgLatency = -1; - long maxSubmitTime = -1; - T3<Long, Integer, Integer> sst = null; - - try { - while (!finish.get()) { - long cnt0 = txCnt.get(); - long lt0 = latency.get(); - - Thread.sleep(UPDATE_INTERVAL_SEC * 1000); - - long cnt1 = txCnt.get(); - long lt1 = latency.get(); - - X.println(">>>"); - - txPerSecond = (cnt1 - cnt0) / UPDATE_INTERVAL_SEC; - X.println(">>> Transaction/s: " + txPerSecond); - - avgLatency = (cnt1 - cnt0) > 0 ? (lt1 - lt0) / (cnt1 - cnt0) : -1; - X.println( - ">>> Avg Latency: " + (avgLatency >= 0 ? avgLatency + "ms" : "invalid")); - - maxSubmitTime = submitTime.getAndSet(0); - X.println(">>> Max Submit Time: " + maxSubmitTime); - - sst = srvStats; - - if (sst != null) - X.println(String.format(">>> Server stats: [tx/sec=%d, nearSize=%d, dhtSize=%d]", - sst.get1(), sst.get2(), sst.get3())); - } - } - catch (InterruptedException ignored) { - X.println(">>> Interrupted."); - - Thread.currentThread().interrupt(); - } - - // Output data to a file, if specified. - if (outputFileName != null) { - X.println("Writing client results to a file: " + outputFileName); - - try { - GridLoadTestUtils.appendLineToFile( - outputFileName, - "%s,%d,%d,%d", - GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), - txPerSecond, - avgLatency, - maxSubmitTime); - } - catch (IOException e) { - X.println("Failed to write client results: ", e); - } - - if (sst != null) { - String srvOutputFileName = outputFileName + "-server"; - - X.println("Writing server results to a file: " + srvOutputFileName); - - try { - GridLoadTestUtils.appendLineToFile( - srvOutputFileName, - "%s,%d,%d,%d", - GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), - sst.get1(), - sst.get2(), - sst.get3()); - } - catch (IOException e) { - X.println("Failed to write server results: ", e); - } - } - } - } - }); - collector.start(); - - ExecutorService pool = Executors.newFixedThreadPool(noThreads); - - pool.invokeAll(clients); - - collector.interrupt(); - - pool.shutdown(); - } - finally { - if (collector != null && !collector.isInterrupted()) - collector.interrupt(); - - if (timer != null) - timer.interrupt(); - - Ignition.stopAll(true); - } - } - finally { - fileLock.close(); - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiLifecycleBean.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiLifecycleBean.java b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiLifecycleBean.java deleted file mode 100644 index 2dea769..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiLifecycleBean.java +++ /dev/null @@ -1,59 +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.gridgain.loadtests.dsi; - -import org.apache.ignite.*; -import org.apache.ignite.lifecycle.*; -import org.apache.ignite.resources.*; -import org.springframework.context.*; - -/** - * - */ -public class GridDsiLifecycleBean implements LifecycleBean { - /** - * Ignite instance will be automatically injected. For additional resources - * that can be injected into lifecycle beans see - * {@link org.apache.ignite.lifecycle.LifecycleBean} documentation. - */ - @IgniteInstanceResource - private Ignite ignite; - - /** */ - @SuppressWarnings("UnusedDeclaration") - @IgniteSpringApplicationContextResource - private ApplicationContext springCtx; - - /** {@inheritDoc} */ - @Override public void onLifecycleEvent(LifecycleEventType evt) throws IgniteCheckedException { - switch (evt) { - case BEFORE_GRID_START: - break; - - case AFTER_GRID_START: - ignite.cache("PARTITIONED_CACHE").dataStructures().atomicSequence("ID", 0, true); - break; - - case BEFORE_GRID_STOP: - break; - - case AFTER_GRID_STOP: - break; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiMessage.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiMessage.java b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiMessage.java deleted file mode 100644 index ad79b57..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiMessage.java +++ /dev/null @@ -1,74 +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.gridgain.loadtests.dsi; - -import java.io.*; -import java.util.*; - -/** - * - */ -public class GridDsiMessage implements Serializable { - /** Terminal ID. */ - private String terminalId; - - /** Node ID. */ - private UUID nodeId; - - /** - * Message constructor. - * - * @param terminalId Terminal ID. - * @param nodeId Node ID. - */ - public GridDsiMessage(String terminalId, UUID nodeId) { - this.terminalId = terminalId; - this.nodeId = nodeId; - } - - /** - * @return Terminal ID. - */ - public String getTerminalId() { - return terminalId; - } - - /** - * Sets terminal ID. - * @param terminalId Terminal ID. - */ - public void setTerminalId(String terminalId) { - this.terminalId = terminalId; - } - - /** - * @return Node ID. - */ - public UUID getNodeId() { - return nodeId; - } - - /** - * Sets node ID. - * - * @param nodeId Node ID. - */ - public void setNodeId(UUID nodeId) { - this.nodeId = nodeId; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiPerfJob.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiPerfJob.java b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiPerfJob.java deleted file mode 100644 index d2c0cb2..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiPerfJob.java +++ /dev/null @@ -1,341 +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.gridgain.loadtests.dsi; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.affinity.*; -import org.apache.ignite.cache.datastructures.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.*; -import org.apache.ignite.resources.*; -import org.apache.ignite.transactions.*; -import org.apache.ignite.internal.processors.cache.distributed.dht.*; -import org.apache.ignite.internal.processors.cache.distributed.near.*; -import org.apache.ignite.internal.util.typedef.*; -import org.jdk8.backport.*; -import org.jetbrains.annotations.*; - -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -/** - * - */ -public class GridDsiPerfJob extends ComputeJobAdapter { - /** */ - private static final ConcurrentMap<Thread, ConcurrentMap<String, T3<Long, Long, Long>>> timers = - new ConcurrentHashMap8<>(); - - /** */ - private static final long PRINT_FREQ = 10000; - - /** */ - private static final GridAtomicLong lastPrint = new GridAtomicLong(); - - /** */ - private static final long MAX = 5000; - - /** */ - @IgniteInstanceResource - private Ignite ignite; - - /** */ - @GridCacheName - private String cacheName = "PARTITIONED_CACHE"; - - /** - * @param msg Message. - */ - public GridDsiPerfJob(@Nullable GridDsiMessage msg) { - super(msg); - } - - /** - * @return Message. - */ - @Nullable private GridDsiMessage message() { - return argument(0); - } - - /** - * @return Terminal ID. - */ - @GridCacheAffinityKeyMapped - @Nullable public String terminalId() { - GridDsiMessage msg = message(); - - return msg != null ? msg.getTerminalId() : null; - } - - /** - * @return Result. - */ - @SuppressWarnings("ConstantConditions") - @Override public Object execute() { - ClusterNodeLocalMap<String, T2<AtomicLong, AtomicLong>> nodeLoc = ignite.cluster().nodeLocalMap(); - - T2<AtomicLong, AtomicLong> cntrs = nodeLoc.get("cntrs"); - - if (cntrs == null) { - T2<AtomicLong, AtomicLong> other = nodeLoc.putIfAbsent("cntrs", - cntrs = new T2<>(new AtomicLong(), new AtomicLong(System.currentTimeMillis()))); - - if (other != null) - cntrs = other; - } - - long cnt = cntrs.get1().incrementAndGet(); - - GridNearCacheAdapter near = (GridNearCacheAdapter)((GridKernal) ignite).internalCache(cacheName); - GridDhtCacheAdapter dht = near.dht(); - - doWork(); - - long start = cntrs.get2().get(); - - long now = System.currentTimeMillis(); - - long dur = now - start; - - if (dur > 20000 && cntrs.get2().compareAndSet(start, System.currentTimeMillis())) { - cntrs.get1().set(0); - - long txPerSec = cnt / (dur / 1000); - - X.println("Stats [tx/sec=" + txPerSec + ", nearSize=" + near.size() + ", dhtSize=" + dht.size() + ']'); - - return new T3<>(txPerSec, near.size(), dht.size()); - } - - return null; - } - - /** - * @param name Timer name to start. - */ - private void startTimer(String name) { - ConcurrentMap<String, T3<Long, Long, Long>> m = timers.get(Thread.currentThread()); - - if (m == null) { - ConcurrentMap<String, T3<Long, Long, Long>> old = timers.putIfAbsent(Thread.currentThread(), - m = new ConcurrentHashMap8<>()); - - if (old != null) - m = old; - } - - T3<Long, Long, Long> t = m.get(name); - - if (t == null) { - T3<Long, Long, Long> old = m.putIfAbsent(name, t = new T3<>()); - - if (old != null) - t = old; - } - - t.set1(System.currentTimeMillis()); - t.set2(0L); - } - - /** - * @param name Timer name to stop. - */ - @SuppressWarnings("ConstantConditions") - private void stopTimer(String name) { - ConcurrentMap<String, T3<Long, Long, Long>> m = timers.get(Thread.currentThread()); - - T3<Long, Long, Long> t = m.get(name); - - assert t != null; - - long now = System.currentTimeMillis(); - - t.set2(now); - - t.set3(Math.max(t.get3() == null ? 0 : t.get3(), now - t.get1())); - } - - /** - * - */ - private void printTimers() { - long now = System.currentTimeMillis(); - - if (lastPrint.get() + PRINT_FREQ < now && lastPrint.setIfGreater(now)) { - Map<String, Long> maxes = new HashMap<>(); - - for (Map.Entry<Thread, ConcurrentMap<String, T3<Long, Long, Long>>> e1 : timers.entrySet()) { - for (Map.Entry<String, T3<Long, Long, Long>> e2 : e1.getValue().entrySet()) { - T3<Long, Long, Long> t = e2.getValue(); - - Long start = t.get1(); - Long end = t.get2(); - - assert start != null; - assert end != null; - - long duration = end == 0 ? now - start : end - start; - - long max = t.get3() == null ? duration : t.get3(); - - if (duration < 0) - duration = now - start; - - if (duration > MAX) - X.println("Maxed out timer [name=" + e2.getKey() + ", duration=" + duration + - ", ongoing=" + (end == 0) + ", thread=" + e1.getKey().getName() + ']'); - - Long cmax = maxes.get(e2.getKey()); - - if (cmax == null || max > cmax) - maxes.put(e2.getKey(), max); - - t.set3(null); - } - } - - for (Map.Entry<String, Long> e : maxes.entrySet()) - X.println("Timer [name=" + e.getKey() + ", maxTime=" + e.getValue() + ']'); - - X.println(">>>>"); - } - } - - /** - * - */ - private void doWork() { - GridCache cache = ignite.cache(cacheName); - - assert cache != null; - - // This is instead of former code to find request - // with some ID. - try { - getId(); - } - catch (IgniteCheckedException e) { - e.printStackTrace(); - } - - startTimer("getSession"); - - String terminalId = terminalId(); - - assert terminalId != null; - - GridDsiSession ses = null; - - try { - ses = (GridDsiSession)get(GridDsiSession.getCacheKey(terminalId)); - } - catch (IgniteCheckedException e) { - e.printStackTrace(); - } - - stopTimer("getSession"); - - if (ses == null) - ses = new GridDsiSession(terminalId); - - try { - try (IgniteTx tx = cache.txStart()) { - GridDsiRequest req = new GridDsiRequest(getId()); - - req.setMessageId(getId()); - - startTimer("putRequest"); - - put(req, req.getCacheKey(terminalId)); - - stopTimer("putRequest"); - - for (int i = 0; i < 5; i++) { - GridDsiResponse rsp = new GridDsiResponse(getId()); - - startTimer("putResponse-" + i); - - put(rsp, rsp.getCacheKey(terminalId)); - - stopTimer("putResponse-" + i); - } - - startTimer("putSession"); - - put(ses, ses.getCacheKey()); - - stopTimer("putSession"); - - startTimer("commit"); - - tx.commit(); - - stopTimer("commit"); - } - } - catch (Exception e) { - e.printStackTrace(); - } - - printTimers(); - } - - /** - * @return ID. - * @throws IgniteCheckedException If failed. - */ - private long getId() throws IgniteCheckedException { - GridCache<Object, Object> cache = ignite.cache(cacheName); - - assert cache != null; - - GridCacheAtomicSequence seq = cache.dataStructures().atomicSequence("ID", 0, true); - - return seq.incrementAndGet(); - } - - /** - * @param o Object. - * @param cacheKey Key. - * @throws IgniteCheckedException If failed. - */ - private void put(Object o, Object cacheKey) throws IgniteCheckedException { - GridCache<Object, Object> cache = ignite.cache(cacheName); - - assert cache != null; - - GridCacheEntry<Object, Object> entry = cache.entry(cacheKey); - - if (entry != null) - entry.setx(o); - } - - /** - * @param key Key. - * @return Object. - * @throws IgniteCheckedException If failed. - */ - @SuppressWarnings("ConstantConditions") - private <T> Object get(Object key) throws IgniteCheckedException { - return ignite.cache(cacheName).get(key); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiRequest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiRequest.java b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiRequest.java deleted file mode 100644 index d3d191a..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiRequest.java +++ /dev/null @@ -1,93 +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.gridgain.loadtests.dsi; - -import org.apache.ignite.cache.affinity.*; - -import java.io.*; - -/** - * - */ -public class GridDsiRequest implements Serializable { - /** */ - private Long id; - - /** */ - @SuppressWarnings({"UnusedDeclaration", "FieldCanBeLocal"}) - private long msgId; - - /** */ - @SuppressWarnings("UnusedDeclaration") - private long txId; - - /** - * @param id ID. - */ - public GridDsiRequest(long id) { - this.id = id; - } - - /** - * @param msgId Message ID. - */ - public void setMessageId(long msgId) { - this.msgId = msgId; - } - - /** - * @param terminalId Terminal ID. - * @return Cache key. - */ - public Object getCacheKey(String terminalId){ - return new RequestKey(id, terminalId); - } - - /** - * - */ - @SuppressWarnings("PackageVisibleInnerClass") - static class RequestKey implements Serializable { - /** */ - private Long key; - - /** */ - @SuppressWarnings("UnusedDeclaration") - @GridCacheAffinityKeyMapped - private String terminalId; - - /** - * @param key Key. - * @param terminalId Terminal ID. - */ - RequestKey(long key, String terminalId) { - this.key = key; - this.terminalId = terminalId; - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - return key.hashCode(); - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object obj) { - return obj instanceof RequestKey && key.equals(((RequestKey)obj).key); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiRequestTask.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiRequestTask.java b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiRequestTask.java deleted file mode 100644 index 1b288e9..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiRequestTask.java +++ /dev/null @@ -1,41 +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.gridgain.loadtests.dsi; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.internal.util.typedef.*; - -import java.util.*; - -/** - * - */ -public class GridDsiRequestTask extends ComputeTaskSplitAdapter<GridDsiMessage, T3<Long, Integer, Integer>> { - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int arg0, GridDsiMessage msg) throws IgniteCheckedException { - return Collections.singletonList(new GridDsiPerfJob(msg)); - } - - /** {@inheritDoc} */ - @Override public T3<Long, Integer, Integer> reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - assert results.size() == 1; - - return results.get(0).getData(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiResponse.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiResponse.java b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiResponse.java deleted file mode 100644 index af22af2..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiResponse.java +++ /dev/null @@ -1,87 +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.gridgain.loadtests.dsi; - -import org.apache.ignite.cache.affinity.*; - -import java.io.*; - -/** - * - */ -public class GridDsiResponse implements Serializable { - /** */ - private long id; - - /** */ - @SuppressWarnings("UnusedDeclaration") - private long msgId; - - /** */ - @SuppressWarnings("UnusedDeclaration") - private long transactionId; - - /** - * @param id ID. - */ - public GridDsiResponse(long id) { - this.id = id; - } - - /** - * @param terminalId Terminal ID. - * @return Cache key. - */ - public Object getCacheKey(String terminalId){ - //return new GridCacheAffinityKey<String>("RESPONSE:" + id.toString(), terminalId); - return new ResponseKey(id, terminalId); - } - - /** - * - */ - @SuppressWarnings("PackageVisibleInnerClass") - static class ResponseKey implements Serializable { - /** */ - private Long key; - - /** */ - @SuppressWarnings("UnusedDeclaration") - @GridCacheAffinityKeyMapped - private String terminalId; - - /** - * @param key Key. - * @param terminalId Terminal ID. - */ - ResponseKey(Long key, String terminalId) { - this.key = key; - this.terminalId = terminalId; - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - return key.hashCode(); - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object obj) { - return obj instanceof ResponseKey && key.equals(((ResponseKey)obj).key); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiResponseTask.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiResponseTask.java b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiResponseTask.java deleted file mode 100644 index a06f885..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiResponseTask.java +++ /dev/null @@ -1,41 +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.gridgain.loadtests.dsi; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.internal.util.typedef.*; - -import java.util.*; - -/** - * Adapter to be used by client. - */ -public class GridDsiResponseTask extends ComputeTaskSplitAdapter<GridDsiMessage, T3<Long, Integer, Integer>> { - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int arg0, GridDsiMessage msg) throws IgniteCheckedException { - return Collections.singletonList(new GridDsiPerfJob(msg)); - } - - /** {@inheritDoc} */ - @Override public T3<Long, Integer, Integer> reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - assert results.size() == 1; - - return results.get(0).getData(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiSession.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiSession.java b/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiSession.java deleted file mode 100644 index 796999a..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/dsi/GridDsiSession.java +++ /dev/null @@ -1,84 +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.gridgain.loadtests.dsi; - -import org.apache.ignite.cache.affinity.*; - -import java.io.*; - -/** - * - */ -public class GridDsiSession implements Serializable{ - /** */ - private String terminalId; - - /** - * @param terminalId Terminal ID. - */ - GridDsiSession(String terminalId) { - this.terminalId = terminalId; - } - - /** - * @return Cache key. - */ - public Object getCacheKey() { - return getCacheKey(terminalId); - } - - /** - * @param terminalId Terminal ID. - * @return Object. - */ - public static Object getCacheKey(String terminalId) { - return new SessionKey(terminalId + "SESSION", terminalId); - } - - /** - * - */ - private static class SessionKey implements Serializable { - /** */ - private String key; - - /** */ - @SuppressWarnings("UnusedDeclaration") - @GridCacheAffinityKeyMapped - private String terminalId; - - /** - * @param key Key. - * @param terminalId Terminal ID. - */ - SessionKey(String key, String terminalId) { - this.key = key; - this.terminalId = terminalId; - } - - /** {@inheritDoc} */ - @Override public int hashCode() { - return key.hashCode(); - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object obj) { - return obj instanceof SessionKey && key.equals(((SessionKey)obj).key); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/dsi/cacheget/GridBenchmarkCacheGetLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/dsi/cacheget/GridBenchmarkCacheGetLoadTest.java b/modules/core/src/test/java/org/gridgain/loadtests/dsi/cacheget/GridBenchmarkCacheGetLoadTest.java deleted file mode 100644 index ade5498..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/dsi/cacheget/GridBenchmarkCacheGetLoadTest.java +++ /dev/null @@ -1,119 +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.gridgain.loadtests.dsi.cacheget; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; - -import java.util.concurrent.atomic.*; - -/** - * This is an adapted test case from DSI-49 (http://www.gridgainsystems.com/jira/browse/DSI-49). - */ -public class GridBenchmarkCacheGetLoadTest { - /** */ - private static AtomicLong cnt = new AtomicLong(); - - /** */ - private static AtomicLong latency = new AtomicLong(); - - /** */ - private static AtomicLong id = new AtomicLong(); - - private static Thread t; - - /** - * - */ - private GridBenchmarkCacheGetLoadTest() { - // No-op. - } - - /** - * @param args Args. - * @throws Exception If failed. - */ - public static void main(String[] args) throws Exception { - Ignition.start("modules/core/src/test/config/load/dsi-49-server-production.xml"); - - GridCache<Long, Long> cache = Ignition.ignite("dsi").cache("PARTITIONED_CACHE"); - - stats(); - - boolean usePrj = true; - - GridCacheProjection<Long, Long> cachePrj = cache.projection(Long.class, Long.class); - - for (int i = 0; i < 5000000; i++) { - long t0 = System.currentTimeMillis(); - - cnt.incrementAndGet(); - - if (usePrj) - // This is slow - cachePrj.get(id.incrementAndGet()); - else - // This is fast - cache.get(id.incrementAndGet()); - - latency.addAndGet(System.currentTimeMillis() - t0); - } - - System.out.println("Finished test."); - - if (t != null) { - t.interrupt(); - t.join(); - } - } - - /** - * - */ - public static void stats() { - t = new Thread(new Runnable() { - @SuppressWarnings({"InfiniteLoopStatement", "BusyWait"}) - @Override public void run() { - int interval = 5; - - while (!Thread.currentThread().isInterrupted()) { - long cnt0 = cnt.get(); - long lt0 = latency.get(); - - try { - Thread.sleep(interval * 1000); - } - catch (InterruptedException e) { - System.out.println("Stat thread got interrupted: " + e); - - return; - } - - long cnt1 = cnt.get(); - long lt1 = latency.get(); - - System.out.println("Get/s: " + (cnt1 - cnt0) / interval); - System.out.println("Avg Latency: " + ((cnt1 - cnt0) > 0 ? (lt1 - lt0) / (cnt1 - cnt0) + - "ms" : "invalid")); - } - } - }); - - t.start(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/dsi/package.html ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/dsi/package.html b/modules/core/src/test/java/org/gridgain/loadtests/dsi/package.html deleted file mode 100644 index e291932..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/dsi/package.html +++ /dev/null @@ -1,23 +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. - --> -<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -<html> -<body> -<!-- Package description. --> -Contains internal tests or test related classes and interfaces. -</body> -</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/hashmap/GridBoundedConcurrentLinkedHashSetLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/hashmap/GridBoundedConcurrentLinkedHashSetLoadTest.java b/modules/core/src/test/java/org/gridgain/loadtests/hashmap/GridBoundedConcurrentLinkedHashSetLoadTest.java deleted file mode 100644 index 0143c72..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/hashmap/GridBoundedConcurrentLinkedHashSetLoadTest.java +++ /dev/null @@ -1,118 +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.gridgain.loadtests.hashmap; - -import org.apache.ignite.internal.util.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.internal.util.typedef.*; -import org.gridgain.loadtests.util.*; -import org.jdk8.backport.*; - -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -import static org.jdk8.backport.ConcurrentLinkedHashMap.QueuePolicy; -import static org.jdk8.backport.ConcurrentLinkedHashMap.QueuePolicy.*; - -/** - * - */ -public class GridBoundedConcurrentLinkedHashSetLoadTest { - /** */ - public static final int UPDATE_INTERVAL_SEC = 5; - - /** - * @param args Arguments. - */ - public static void main(String[] args) throws Exception { - QueuePolicy qPlc = args.length > 0 ? QueuePolicy.valueOf(args[0]) : SINGLE_Q; - int threadCnt = args.length > 1 ? Integer.valueOf(args[1]) : Runtime.getRuntime().availableProcessors(); - - X.println("Queue policy: " + qPlc); - X.println("Threads: " + threadCnt); - - ExecutorService pool = Executors.newFixedThreadPool(threadCnt); - - final Collection<IgniteUuid> set = - new GridBoundedConcurrentLinkedHashSet<>(10240, 32, 0.75f, 128, qPlc); - - X.println("Set: " + set); - - final LongAdder execCnt = new LongAdder(); - - final AtomicBoolean finish = new AtomicBoolean(); - - // Thread that measures and outputs performance statistics. - Thread collector = new Thread(new Runnable() { - @SuppressWarnings({"BusyWait", "InfiniteLoopStatement"}) - @Override public void run() { - GridCumulativeAverage avgTasksPerSec = new GridCumulativeAverage(); - - try { - while (!finish.get()) { - Thread.sleep(UPDATE_INTERVAL_SEC * 1000); - - long curTasksPerSec = execCnt.sumThenReset() / UPDATE_INTERVAL_SEC; - - X.println(">>> Tasks/s: " + curTasksPerSec); - - avgTasksPerSec.update(curTasksPerSec); - } - } - catch (InterruptedException ignored) { - X.println(">>> Interrupted."); - - Thread.currentThread().interrupt(); - } - } - }); - - collector.start(); - - Collection<Callable<Object>> producers = new ArrayList<>(threadCnt); - - for (int i = 0; i < threadCnt; i++) - producers.add(new Callable<Object>() { - @SuppressWarnings({"unchecked", "InfiniteLoopStatement"}) - @Override public Object call() throws Exception { - UUID id = UUID.randomUUID(); - - try { - while (!finish.get()) { - set.add(IgniteUuid.fromUuid(id)); - - execCnt.increment(); - } - - return null; - } - catch (Throwable t) { - t.printStackTrace(); - - throw new Exception(t); - } - finally { - X.println("Thread finished."); - } - } - }); - - pool.invokeAll(producers); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/hashmap/GridCacheTestContext.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/hashmap/GridCacheTestContext.java b/modules/core/src/test/java/org/gridgain/loadtests/hashmap/GridCacheTestContext.java deleted file mode 100644 index 8c8f95f..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/hashmap/GridCacheTestContext.java +++ /dev/null @@ -1,72 +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.gridgain.loadtests.hashmap; - -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.store.*; -import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.processors.cache.datastructures.*; -import org.apache.ignite.internal.processors.cache.dr.os.*; -import org.apache.ignite.internal.processors.cache.jta.*; -import org.apache.ignite.internal.processors.cache.query.*; -import org.apache.ignite.internal.processors.cache.query.continuous.*; -import org.apache.ignite.internal.processors.cache.transactions.*; -import org.gridgain.testframework.junits.*; - -import java.util.*; - -import static org.gridgain.testframework.junits.GridAbstractTest.*; - -/** - * Cache test context. - */ -public class GridCacheTestContext<K, V> extends GridCacheContext<K, V> { - /** - * @param ctx Context. - * @throws Exception If failed. - */ - @SuppressWarnings("NullableProblems") - public GridCacheTestContext(GridTestKernalContext ctx) throws Exception { - super( - ctx, - new GridCacheSharedContext<>( - ctx, - new IgniteTxManager<K, V>(), - new GridCacheVersionManager<K, V>(), - new GridCacheMvccManager<K, V>(), - new GridCacheDeploymentManager<K, V>(), - new GridCachePartitionExchangeManager<K, V>(), - new GridCacheIoManager<K, V>() - ), - defaultCacheConfiguration(), - new GridCacheEventManager<K, V>(), - new GridCacheSwapManager<K, V>(false), - new GridCacheStoreManager<K, V>(null, - new IdentityHashMap<CacheStore, ThreadLocal>(), - null, - new CacheConfiguration()), - new GridCacheEvictionManager<K, V>(), - new GridCacheLocalQueryManager<K, V>(), - new GridCacheContinuousQueryManager<K, V>(), - new GridCacheAffinityManager<K, V>(), - new GridCacheDataStructuresManager<K, V>(), - new GridCacheTtlManager<K, V>(), - new GridOsCacheDrManager<K, V>(), - new GridCacheNoopJtaManager<K, V>()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/hashmap/GridHashMapLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/hashmap/GridHashMapLoadTest.java b/modules/core/src/test/java/org/gridgain/loadtests/hashmap/GridHashMapLoadTest.java deleted file mode 100644 index 925c20f..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/hashmap/GridHashMapLoadTest.java +++ /dev/null @@ -1,100 +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.gridgain.loadtests.hashmap; - -import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.processors.cache.transactions.*; -import org.gridgain.testframework.junits.*; -import org.gridgain.testframework.junits.common.*; -import org.gridgain.testframework.junits.logger.*; - -import java.util.*; -import java.util.concurrent.*; - -/** - * Tests hashmap load. - */ -@SuppressWarnings("InfiniteLoopStatement") -public class GridHashMapLoadTest extends GridCommonAbstractTest { - /** - * - */ - public void testHashMapLoad() { - Map<Integer, Integer> map = new HashMap<>(5 * 1024 * 1024); - - int i = 0; - - while (true) { - map.put(i++, i++); - - if (i % 400000 == 0) - info("Inserted objects: " + i / 2); - } - } - - /** - * - */ - public void testConcurrentHashMapLoad() { - Map<Integer, Integer> map = new ConcurrentHashMap<>(5 * 1024 * 1024); - - int i = 0; - - while (true) { - map.put(i++, i++); - - if (i % 400000 == 0) - info("Inserted objects: " + i / 2); - } - } - - /** - * @throws Exception If failed. - */ - public void testMapEntry() throws Exception { - Map<Integer, GridCacheMapEntry<Integer, Integer>> map = new HashMap<>(5 * 1024 * 1024); - - int i = 0; - - GridCacheTestContext<Integer, Integer> ctx = new GridCacheTestContext<>( - new GridTestKernalContext(new GridTestLog4jLogger())); - - while (true) { - Integer key = i++; - Integer val = i++; - - map.put(key, new GridCacheMapEntry<Integer, Integer>(ctx, key, - key.hashCode(), val, null, 0, 1) { - @Override public boolean tmLock(IgniteTxEx<Integer, Integer> tx, long timeout) { - return false; - } - - @Override public void txUnlock(IgniteTxEx<Integer, Integer> tx) { - // No-op. - } - - @Override public boolean removeLock(GridCacheVersion ver) { - return false; - } - }); - - if (i % 100000 == 0) - info("Inserted objects: " + i / 2); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestClient.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestClient.java b/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestClient.java deleted file mode 100644 index f04b9cd..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestClient.java +++ /dev/null @@ -1,219 +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.gridgain.loadtests.job; - -import org.apache.ignite.*; -import org.apache.ignite.internal.util.lang.*; -import org.apache.ignite.internal.util.typedef.*; -import org.gridgain.loadtests.util.*; -import org.gridgain.testframework.*; -import org.jdk8.backport.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.*; - -/** - * - */ -public class GridJobExecutionLoadTestClient implements Callable<Object> { - /** Performance stats update interval in seconds. */ - private static final int UPDATE_INTERVAL_SEC = 10; - - /** Warm-up duration. */ - public static final int WARM_UP_DURATION = 60 * 1000; - - /** Grid. */ - private static Ignite g; - - /** Transaction count. */ - private static LongAdder txCnt = new LongAdder(); - - /** Finish flag. */ - private static volatile boolean finish; - - /** {@inheritDoc} */ - @SuppressWarnings("InfiniteLoopStatement") - @Nullable @Override public Object call() throws Exception { - IgniteCompute rmts = g.compute(g.cluster().forRemotes()); - - while (!finish) { - try { - rmts.execute(GridJobExecutionLoadTestTask.class, null); - - txCnt.increment(); - } - catch (IgniteCheckedException e) { - e.printStackTrace(); - } - } - - return null; - } - - /** - * @param args Args. - * @throws Exception If failed. - */ - public static void main(String[] args) throws Exception { - GridFileLock fileLock = GridLoadTestUtils.fileLock(); - - fileLock.lock(); - - try { - final int noThreads = args.length > 0 ? Integer.parseInt(args[0]) : 64; - final int duration = args.length > 1 ? Integer.parseInt(args[1]) : 0; - final String outputFileName = args.length > 2 ? args[2] : null; - - X.println("Thread count: " + noThreads); - - g = G.start("modules/tests/config/jobs-load-client.xml"); - - warmUp(noThreads); - - final Thread collector = new Thread(new Runnable() { - @SuppressWarnings("BusyWait") - @Override public void run() { - GridCumulativeAverage avgTxPerSec = new GridCumulativeAverage(); - - try { - while (!finish) { - Thread.sleep(UPDATE_INTERVAL_SEC * 1000); - - long txPerSec = txCnt.sumThenReset() / UPDATE_INTERVAL_SEC; - - X.println(">>>"); - X.println(">>> Transactions/s: " + txPerSec); - - avgTxPerSec.update(txPerSec); - } - } - catch (InterruptedException ignored) { - X.println(">>> Interrupted."); - - Thread.currentThread().interrupt(); - } - - X.println(">>> Average Transactions/s: " + avgTxPerSec); - - if (outputFileName != null) { - try { - X.println("Writing results to file: " + outputFileName); - - GridLoadTestUtils.appendLineToFile( - outputFileName, - "%s,%d", - GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), - avgTxPerSec.get() - ); - } - catch (IOException e) { - X.error("Failed to output results to file.", e); - } - } - } - }); - - X.println("Running main test..."); - - Thread timer = null; - - try { - ExecutorService pool = Executors.newFixedThreadPool(noThreads); - - Collection<Callable<Object>> clients = new ArrayList<>(noThreads); - - for (int i = 0; i < noThreads; i++) - clients.add(new GridJobExecutionLoadTestClient()); - - collector.start(); - - if (duration > 0) { - timer = new Thread(new Runnable() { - @Override public void run() { - try { - Thread.sleep(duration * 1000); - - finish = true; - } - catch (InterruptedException ignored) { - X.println(">>> Interrupted."); - } - } - }); - timer.start(); - } - - pool.invokeAll(clients); - - collector.interrupt(); - - pool.shutdown(); - } - finally { - if (collector != null && !collector.isInterrupted()) - collector.interrupt(); - - if (timer != null) - timer.interrupt(); - - G.stopAll(true); - } - } - finally { - fileLock.close(); - } - } - - /** - * Warms the JVM up. - * - * @param noThreads Number of threads to use. - */ - private static void warmUp(int noThreads) { - X.println("Warming up..."); - - final IgniteCompute rmts = g.compute(g.cluster().forRemotes()); - - GridLoadTestUtils.runMultithreadedInLoop(new Callable<Object>() { - @Nullable @Override public Object call() { - try { - rmts.execute(GridJobExecutionLoadTestTask.class, null); - } - catch (IgniteCheckedException e) { - e.printStackTrace(); - } - - return null; - } - }, noThreads, WARM_UP_DURATION); - - // Run GC on all nodes. - try { - g.compute().run(new GridAbsClosure() { - @Override public void apply() { - System.gc(); - } - }); - } - catch (IgniteCheckedException e) { - throw new IllegalStateException(e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestClientSemaphore.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestClientSemaphore.java b/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestClientSemaphore.java deleted file mode 100644 index ad465b7..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestClientSemaphore.java +++ /dev/null @@ -1,239 +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.gridgain.loadtests.job; - -import org.apache.ignite.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.internal.util.lang.*; -import org.apache.ignite.internal.util.typedef.*; -import org.gridgain.loadtests.util.*; -import org.gridgain.testframework.*; -import org.jdk8.backport.*; -import org.jetbrains.annotations.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.*; - -/** - * - */ -public class GridJobExecutionLoadTestClientSemaphore implements Callable<Object> { - /** Performance stats update interval in seconds. */ - private static final int UPDATE_INTERVAL_SEC = 10; - - /** Warm-up duration. */ - public static final int WARM_UP_DURATION = 60 * 1000; - - /** Grid. */ - private static Ignite g; - - /** Transaction count. */ - private static LongAdder txCnt = new LongAdder(); - - /** Finish flag. */ - private static volatile boolean finish; - - /** */ - private static Semaphore tasksSem; - - /** {@inheritDoc} */ - @SuppressWarnings("InfiniteLoopStatement") - @Nullable @Override public Object call() throws Exception { - final IgniteInClosure<IgniteFuture<?>> lsnr = new CI1<IgniteFuture<?>>() { - @Override public void apply(IgniteFuture<?> t) { - tasksSem.release(); - } - }; - - ClusterGroup rmts = g.cluster().forRemotes(); - - IgniteCompute comp = g.compute(rmts).enableAsync(); - - while (!finish) { - tasksSem.acquire(); - - comp.execute(GridJobExecutionLoadTestTask.class, null); - - ComputeTaskFuture<Object> f = comp.future(); - - f.listenAsync(lsnr); - - txCnt.increment(); - } - - return null; - } - - /** - * @param args Args. - * @throws Exception If failed. - */ - public static void main(String[] args) throws Exception { - GridFileLock fileLock = GridLoadTestUtils.fileLock(); - - fileLock.lock(); - - try { - final int noThreads = args.length > 0 ? Integer.parseInt(args[0]) : - Runtime.getRuntime().availableProcessors(); - final int duration = args.length > 1 ? Integer.parseInt(args[1]) : 0; - int tasksCnt = args.length > 2 ? Integer.parseInt(args[2]) : 4069; - final String outputFileName = args.length > 3 ? args[3] : null; - - X.println("Thread count: " + noThreads); - X.println("Tasks count: " + tasksCnt); - - tasksSem = new Semaphore(tasksCnt); - - g = G.start("modules/tests/config/jobs-load-client.xml"); - - warmUp(noThreads); - - final Thread collector = new Thread(new Runnable() { - @SuppressWarnings("BusyWait") - @Override public void run() { - GridCumulativeAverage avgTxPerSec = new GridCumulativeAverage(); - - try { - while (!finish) { - Thread.sleep(UPDATE_INTERVAL_SEC * 1000); - - long txPerSec = txCnt.sumThenReset() / UPDATE_INTERVAL_SEC; - - X.println(">>>"); - X.println(">>> Transactions/s: " + txPerSec); - - avgTxPerSec.update(txPerSec); - } - } - catch (InterruptedException ignored) { - X.println(">>> Interrupted."); - - Thread.currentThread().interrupt(); - } - - X.println(">>> Average Transactions/s: " + avgTxPerSec); - - if (outputFileName != null) { - try { - X.println("Writing results to file: " + outputFileName); - - GridLoadTestUtils.appendLineToFile( - outputFileName, - "%s,%d", - GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), - avgTxPerSec.get() - ); - } - catch (IOException e) { - X.error("Failed to output results to file.", e); - } - } - } - }); - - X.println("Running main test..."); - - Thread timer = null; - - try { - ExecutorService pool = Executors.newFixedThreadPool(noThreads); - - Collection<Callable<Object>> clients = new ArrayList<>(noThreads); - - for (int i = 0; i < noThreads; i++) - clients.add(new GridJobExecutionLoadTestClientSemaphore()); - - collector.start(); - - if (duration > 0) { - timer = new Thread(new Runnable() { - @Override public void run() { - try { - Thread.sleep(duration * 1000); - - finish = true; - } - catch (InterruptedException ignored) { - X.println(">>> Interrupted."); - } - } - }); - timer.start(); - } - - pool.invokeAll(clients); - - collector.interrupt(); - - pool.shutdown(); - } - finally { - if (collector != null && !collector.isInterrupted()) - collector.interrupt(); - - if (timer != null) - timer.interrupt(); - - G.stopAll(true); - } - } - finally { - fileLock.close(); - } - } - - /** - * Warms the JVM up. - * - * @param noThreads Number of threads to use. - */ - private static void warmUp(int noThreads) { - X.println("Warming up..."); - - final IgniteCompute rmts = g.compute(g.cluster().forRemotes()); - - GridLoadTestUtils.runMultithreadedInLoop(new Callable<Object>() { - @Nullable @Override public Object call() { - try { - rmts.execute(GridJobExecutionLoadTestTask.class, null); - } - catch (IgniteCheckedException e) { - e.printStackTrace(); - } - - return null; - } - }, noThreads, WARM_UP_DURATION); - - // Run GC on all nodes. - try { - g.compute().run(new GridAbsClosure() { - @Override public void apply() { - System.gc(); - } - }); - } - catch (IgniteCheckedException e) { - throw new IllegalStateException(e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestJob.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestJob.java b/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestJob.java deleted file mode 100644 index 69b0d81..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestJob.java +++ /dev/null @@ -1,48 +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.gridgain.loadtests.job; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; - -import java.io.*; - -/** - * - */ -public class GridJobExecutionLoadTestJob implements ComputeJob, Externalizable { - /** {@inheritDoc} */ - @Override public Object execute() throws IgniteCheckedException { - return null; - } - - /** {@inheritDoc} */ - @Override public void cancel() { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void writeExternal(ObjectOutput out) throws IOException { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - // No-op. - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestServer.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestServer.java b/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestServer.java deleted file mode 100644 index db233f4..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestServer.java +++ /dev/null @@ -1,40 +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.gridgain.loadtests.job; - -import org.apache.ignite.internal.util.typedef.*; - -/** - * - */ -public class GridJobExecutionLoadTestServer { - /** - * - */ - private GridJobExecutionLoadTestServer() { - // No-op. - } - - /** - * @param args Args. - * @throws Exception If failed. - */ - public static void main(String[] args) throws Exception { - G.start("modules/core/src/test/config/jobs-load-server.xml"); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestTask.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestTask.java b/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestTask.java deleted file mode 100644 index 010dbb6..0000000 --- a/modules/core/src/test/java/org/gridgain/loadtests/job/GridJobExecutionLoadTestTask.java +++ /dev/null @@ -1,50 +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.gridgain.loadtests.job; - -import org.apache.ignite.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.internal.util.typedef.*; -import org.jetbrains.annotations.*; - -import java.util.*; - -import static org.apache.ignite.compute.ComputeJobResultPolicy.*; - -/** - * - */ -public class GridJobExecutionLoadTestTask implements ComputeTask<Object, Object> { - /** {@inheritDoc} */ - @Nullable @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable Object arg) - throws IgniteCheckedException { - return F.asMap(new GridJobExecutionLoadTestJob(), subgrid.get(0)); - } - - /** {@inheritDoc} */ - @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteCheckedException { - return REDUCE; - } - - /** {@inheritDoc} */ - @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return null; - } -} -