Skip to content

Commit

Permalink
Pauser to warn only if trying to use busy pauser, but using sleepy du…
Browse files Browse the repository at this point in the history
…e to not enough cores. closes OpenHFT#22
  • Loading branch information
peter-lawrey committed Oct 16, 2018
1 parent 20ebbbf commit f6933d6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/main/java/net/openhft/chronicle/threads/Pauser.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ public interface Pauser {

static boolean getSleepy() {
int procs = Runtime.getRuntime().availableProcessors();
if (procs < MIN_PROCESSORS) {
Jvm.warn().on(Pauser.class, "Using Pauser.sleepy() as not enough processors, have " + procs + ", needs " + MIN_PROCESSORS + "+");
return true;
}
return false;
return procs < MIN_PROCESSORS;
}

static Pauser yielding(int minBusy) {
SleepyWarning.warnSleepy();
return SLEEPY ? sleepy() : new YieldingPauser(minBusy);
}

static TimingPauser sleepy() {
Expand Down Expand Up @@ -91,20 +92,32 @@ static Pauser yielding() {
return yielding(2);
}

static Pauser yielding(int minBusy) {
return SLEEPY ? sleepy() : new YieldingPauser(minBusy);
}

/**
* A busy pauser which never waits
*
* @return a busy/non pauser
*/
@NotNull
static Pauser busy() {
SleepyWarning.warnSleepy();
return SLEEPY ? sleepy() : BusyPauser.INSTANCE;
}


enum SleepyWarning {
;

static {
if (SLEEPY) {
int procs = Runtime.getRuntime().availableProcessors();
Jvm.warn().on(Pauser.class, "Using Pauser.sleepy() as not enough processors, have " + procs + ", needs " + MIN_PROCESSORS + "+");
}
}

static void warnSleepy() {
}
}

@NotNull
static TimingPauser timedBusy() {
return SLEEPY ? sleepy() : new BusyTimedPauser();
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/net/openhft/chronicle/threads/PauserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.openhft.chronicle.threads;

import org.junit.Test;

public class PauserTest {

@Test
public void sleepy() {
Pauser.sleepy();
}

@Test
public void yielding() {
Pauser.yielding();
}

@Test
public void busy() {
Pauser.busy();
}
}

0 comments on commit f6933d6

Please sign in to comment.