You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2017/08/21 13:19:01 UTC
[1/2] ignite git commit: ignite-6009 Review.
Repository: ignite
Updated Branches:
refs/heads/master 60c056098 -> f4e4f77d1
ignite-6009 Review.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f4e4f77d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f4e4f77d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f4e4f77d
Branch: refs/heads/master
Commit: f4e4f77d17002bd8c7eb3ab89587f5b0bd838d92
Parents: dadc42f
Author: Andrey Gura <ag...@apache.org>
Authored: Mon Aug 21 16:06:30 2017 +0300
Committer: Andrey Gura <ag...@apache.org>
Committed: Mon Aug 21 16:14:06 2017 +0300
----------------------------------------------------------------------
.../datastructures/IgniteSemaphoreExample.java | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/f4e4f77d/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java
index 1280464..99403dc 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java
@@ -47,11 +47,12 @@ public class IgniteSemaphoreExample {
*/
public static void main(String[] args) {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
- // Number of producers; should be equal to number of consumers.
- // This value should not exceed overall number of compute threads in a cluster,
- // otherwise blocking consumer jobs can occupy all the threads leading to deadlock.
- int producerConsumerCount =
- ignite.configuration().getPublicThreadPoolSize() * ignite.cluster().forServers().nodes().size() / 2;
+ int nodeCount = ignite.cluster().forServers().nodes().size();
+
+ // Number of producers should be equal to number of consumers.
+ // This value should not exceed overall number of public thread pools in a cluster,
+ // otherwise blocking consumer jobs can occupy all the threads leading to starvation.
+ int jobCount = ignite.configuration().getPublicThreadPoolSize() * nodeCount / 2;
System.out.println();
System.out.println(">>> Cache atomic semaphore example started.");
@@ -66,17 +67,17 @@ public class IgniteSemaphoreExample {
IgniteSemaphore semaphore = ignite.semaphore(semaphoreName, 0, false, true);
// Start consumers on all cluster nodes.
- for (int i = 0; i < producerConsumerCount; i++)
+ for (int i = 0; i < jobCount; i++)
ignite.compute().runAsync(new Consumer(semaphoreName));
// Start producers on all cluster nodes.
- for (int i = 0; i < producerConsumerCount; i++)
+ for (int i = 0; i < jobCount; i++)
ignite.compute().runAsync(new Producer(semaphoreName));
System.out.println("Master node is waiting for all other nodes to finish...");
// Wait for everyone to finish.
- syncSemaphore.acquire(2 * producerConsumerCount);
+ syncSemaphore.acquire(2 * jobCount);
}
System.out.flush();
[2/2] ignite git commit: IGNITE-6009: Fixed IgniteSemaphore test.
Posted by ag...@apache.org.
IGNITE-6009: Fixed IgniteSemaphore test.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/dadc42f3
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/dadc42f3
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/dadc42f3
Branch: refs/heads/master
Commit: dadc42f32127a6eab752e62f6e0aa0e1b1369603
Parents: 60c0560
Author: Andrey Kuznetsov <st...@gmail.com>
Authored: Fri Aug 11 15:51:31 2017 +0300
Committer: Andrey Gura <ag...@apache.org>
Committed: Mon Aug 21 16:14:06 2017 +0300
----------------------------------------------------------------------
.../datastructures/IgniteSemaphoreExample.java | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/dadc42f3/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java
index 12d1eab..1280464 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSemaphoreExample.java
@@ -37,12 +37,6 @@ public class IgniteSemaphoreExample {
/** Number of items for each producer/consumer to produce/consume. */
private static final int OPS_COUNT = 100;
- /** Number of producers. */
- private static final int NUM_PRODUCERS = 10;
-
- /** Number of consumers. */
- private static final int NUM_CONSUMERS = 10;
-
/** Synchronization semaphore name. */
private static final String SEM_NAME = IgniteSemaphoreExample.class.getSimpleName();
@@ -53,6 +47,12 @@ public class IgniteSemaphoreExample {
*/
public static void main(String[] args) {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
+ // Number of producers; should be equal to number of consumers.
+ // This value should not exceed overall number of compute threads in a cluster,
+ // otherwise blocking consumer jobs can occupy all the threads leading to deadlock.
+ int producerConsumerCount =
+ ignite.configuration().getPublicThreadPoolSize() * ignite.cluster().forServers().nodes().size() / 2;
+
System.out.println();
System.out.println(">>> Cache atomic semaphore example started.");
@@ -66,17 +66,17 @@ public class IgniteSemaphoreExample {
IgniteSemaphore semaphore = ignite.semaphore(semaphoreName, 0, false, true);
// Start consumers on all cluster nodes.
- for (int i = 0; i < NUM_CONSUMERS; i++)
+ for (int i = 0; i < producerConsumerCount; i++)
ignite.compute().runAsync(new Consumer(semaphoreName));
// Start producers on all cluster nodes.
- for (int i = 0; i < NUM_PRODUCERS; i++)
+ for (int i = 0; i < producerConsumerCount; i++)
ignite.compute().runAsync(new Producer(semaphoreName));
System.out.println("Master node is waiting for all other nodes to finish...");
// Wait for everyone to finish.
- syncSemaphore.acquire(NUM_CONSUMERS + NUM_PRODUCERS);
+ syncSemaphore.acquire(2 * producerConsumerCount);
}
System.out.flush();
@@ -159,7 +159,7 @@ public class IgniteSemaphoreExample {
System.out.println("Consumer finished [nodeId=" + Ignition.ignite().cluster().localNode().id() + ']');
// Gets the syncing semaphore
- IgniteSemaphore sync = Ignition.ignite().semaphore(SEM_NAME, 3, true, true);
+ IgniteSemaphore sync = Ignition.ignite().semaphore(SEM_NAME, 0, true, true);
// Signals the master thread.
sync.release();