/** * Execute command. * * @param idx Index. * @param cmd Command. */ public void execute(int idx, Runnable cmd) { if (idx == -1) execute(cmd); else { assert idx >= 0 : idx; stripes[idx % stripes.length].execute(cmd); } }
exec.execute(stripe, () -> {
/** * @throws Exception If failed. */ @Test public void testStripesQueueSizes() throws Exception { stripedExecSvc.execute(0, new TestRunnable()); stripedExecSvc.execute(0, new TestRunnable(true)); stripedExecSvc.execute(0, new TestRunnable(true)); stripedExecSvc.execute(1, new TestRunnable(true)); stripedExecSvc.execute(1, new TestRunnable(true)); stripedExecSvc.execute(1, new TestRunnable(true)); sleepASec(); int[] queueSizes = stripedExecSvc.stripesQueueSizes(); assertEquals(1, queueSizes[0]); assertEquals(2, queueSizes[1]); assertEquals(0, queueSizes[2]); }
/** * @param thread Thread. * @param c Closure. */ public void runLocalWithThreadPolicy(IgniteThread thread, Runnable c) { assert thread.stripe() >= 0 || thread.policy() != GridIoPolicy.UNDEFINED : thread; if (thread.stripe() >= 0) ctx.getStripedExecutorService().execute(thread.stripe(), c); else { try { ctx.pools().poolForPolicy(thread.policy()).execute(c); } catch (IgniteCheckedException e) { U.error(log, "Failed to get pool for policy: " + thread.policy(), e); } } }
exec.execute(stripeIdx, () -> {
/** * @throws Exception If failed. */ @Test public void testStripesActiveStatuses() throws Exception { stripedExecSvc.execute(0, new TestRunnable()); stripedExecSvc.execute(1, new TestRunnable(true)); sleepASec(); boolean[] statuses = stripedExecSvc.stripesActiveStatuses(); assertFalse(statuses[0]); assertTrue(statuses[1]); assertFalse(statuses[0]); }
/** * @throws Exception If failed. */ @Test public void testStripesCompletedTasks() throws Exception { stripedExecSvc.execute(0, new TestRunnable()); stripedExecSvc.execute(1, new TestRunnable()); sleepASec(); long[] completedTaks = stripedExecSvc.stripesCompletedTasks(); assertEquals(1, completedTaks[0]); assertEquals(1, completedTaks[1]); assertEquals(0, completedTaks[2]); }
/** * @throws Exception If failed. */ @Test public void testStarvationDetected() throws Exception { final int stripeIdx = 0; stripedExecSvc.execute(stripeIdx, new TestRunnable(true)); sleepASec(); assertFalse(GridTestUtils.waitForCondition(() -> stripedExecSvc.activeStripesCount() == 0, 2000)); stripedExecSvc.execute(stripeIdx, new TestRunnable()); assertTrue(GridTestUtils.waitForCondition(() -> stripedExecSvc.activeStripesCount() == 1, 10000)); assertTrue(stripedExecSvc.detectStarvation()); }
/** * Execute command. * * @param idx Index. * @param cmd Command. */ public void execute(int idx, Runnable cmd) { if (idx == -1) execute(cmd); else { assert idx >= 0 : idx; stripes[idx % stripes.length].execute(cmd); } }
/** * @param thread Thread. * @param c Closure. */ public void runLocalWithThreadPolicy(IgniteThread thread, Runnable c) { assert thread.stripe() >= 0 || thread.policy() != GridIoPolicy.UNDEFINED : thread; if (thread.stripe() >= 0) ctx.getStripedExecutorService().execute(thread.stripe(), c); else { try { ctx.pools().poolForPolicy(thread.policy()).execute(c); } catch (IgniteCheckedException e) { U.error(log, "Failed to get pool for policy: " + thread.policy(), e); } } }