use of org.spf4j.stackmonitor.Sampler in project spf4j by zolyfarkas.
the class LifoThreadPoolExecutorCoreIdlingTest method testLifoExecSQMutable.
@Test
public void testLifoExecSQMutable() throws InterruptedException, IOException {
MutableLifoThreadPoolExecutorSQP executor = new MutableLifoThreadPoolExecutorSQP("test", 2, 8, 20, 1024, 0);
Sampler s = Sampler.getSampler(20, 10000, new File(org.spf4j.base.Runtime.TMP_FOLDER), "lifeTest1");
s.start();
org.spf4j.base.Runtime.gc(5000);
Thread.sleep(100);
long time = CpuUsageSampler.getProcessCpuTimeNanos();
Thread.sleep(3000);
long cpuTime = CpuUsageSampler.getProcessCpuTimeNanos() - time;
LOG.info("Cpu profile saved to {}", s.dumpToFile());
LOG.debug("CPU time = {} ns", cpuTime);
s.stop();
// 6069497000 with bug 53945000 without bug
Assert.assertTrue("CPU Time = " + cpuTime, cpuTime < 1500000000);
executor.shutdown();
executor.awaitTermination(1, TimeUnit.SECONDS);
}
use of org.spf4j.stackmonitor.Sampler in project spf4j by zolyfarkas.
the class JdbcSemaphoreTest method testPerformance.
@Test
@Ignore
public void testPerformance() throws SQLException, IOException, InterruptedException, ExecutionException, TimeoutException {
int port = PORT.getAndIncrement();
Server server = Server.createTcpServer(new String[] { "-tcpPort", Integer.toString(port), "-ifNotExists" }).start();
try {
File tempDB = File.createTempFile("test", "h2db");
tempDB.deleteOnExit();
String connStr = "jdbc:h2:tcp://localhost:" + port + "/nio:" + tempDB.getAbsolutePath() + ";AUTO_SERVER=TRUE";
JdbcDataSource ds = new JdbcDataSource();
ds.setURL(connStr);
ds.setUser("sa");
ds.setPassword("sa");
createSchemaObjects(ds);
JdbcSemaphore semaphore = new JdbcSemaphore(ds, "test_sem2", 1, true);
Sampler s = new Sampler(5, 5000);
s.registerJmx();
s.start();
LOG.info("started sampling");
long deadline = TimeSource.nanoTime() + TimeUnit.SECONDS.toNanos(10);
do {
semaphore.acquire(1, 1, TimeUnit.SECONDS);
semaphore.release();
} while (deadline > TimeSource.nanoTime());
semaphore.close();
s.stop();
LOG.debug("dumped samples to {}", s.dumpToFile());
} finally {
JdbcHeartBeat.stopHeartBeats();
server.shutdown();
}
}
use of org.spf4j.stackmonitor.Sampler in project spf4j by zolyfarkas.
the class LifoThreadPoolExecutorInterruptingTest method testLifoExecSQ2.
@Test(timeout = 60000)
public void testLifoExecSQ2() throws InterruptedException, IOException, ExecutionException {
LifoThreadPoolExecutorSQP executor = new LifoThreadPoolExecutorSQP("test", 2, 8, 20, 0);
File destFolder = new File(org.spf4j.base.Runtime.TMP_FOLDER);
Sampler s = Sampler.getSampler(20, 10000, destFolder, "lifeTest1");
s.start();
org.spf4j.base.Runtime.gc(5000);
List<Runnable> running = executor.shutdownNow();
Assert.assertTrue(running.isEmpty());
Thread.sleep(100);
long time = CpuUsageSampler.getProcessCpuTimeNanos();
Thread.sleep(3000);
long cpuTime = CpuUsageSampler.getProcessCpuTimeNanos() - time;
File dumpToFile = s.dumpToFile();
Assert.assertEquals(destFolder.getCanonicalFile(), dumpToFile.getParentFile().getCanonicalFile());
LOG.info("Cpu profile saved to {}", dumpToFile);
LOG.debug("CPU time = {} ns", cpuTime);
s.stop();
Assert.assertTrue("CPU Time = " + cpuTime, cpuTime < 1500000000);
// 3260523000 with bug 148672000 without bug with profiler
executor.shutdown();
executor.awaitTermination(1, TimeUnit.SECONDS);
}
use of org.spf4j.stackmonitor.Sampler in project spf4j by zolyfarkas.
the class LifoThreadPoolExecutorInterruptingTest method testLifoExecSQ.
@Test(timeout = 60000)
public void testLifoExecSQ() throws InterruptedException, IOException, ExecutionException {
LifoThreadPoolExecutorSQP executor = new LifoThreadPoolExecutorSQP("test", 2, 8, 20, 0);
File destFolder = new File(org.spf4j.base.Runtime.TMP_FOLDER);
Sampler s = Sampler.getSampler(20, 10000, destFolder, "lifeTest1");
s.start();
org.spf4j.base.Runtime.gc(5000);
ArrayBlockingQueue<Thread> q = new ArrayBlockingQueue<>(1);
Future<Object> f = executor.submit(() -> {
q.put(Thread.currentThread());
return null;
});
q.take().interrupt();
Assert.assertNull(f.get());
Thread.sleep(100);
long time = CpuUsageSampler.getProcessCpuTimeNanos();
Thread.sleep(3000);
long cpuTime = CpuUsageSampler.getProcessCpuTimeNanos() - time;
File dumpToFile = s.dumpToFile();
Assert.assertEquals(destFolder.getCanonicalFile(), dumpToFile.getParentFile().getCanonicalFile());
LOG.info("Cpu profile saved to {}", dumpToFile);
LOG.debug("CPU time = {} ns", cpuTime);
s.stop();
Assert.assertTrue("CPU Time = " + cpuTime, cpuTime < 1500000000);
// 3260523000 with bug 148672000 without bug with profiler
executor.shutdown();
executor.awaitTermination(1, TimeUnit.SECONDS);
}
use of org.spf4j.stackmonitor.Sampler in project spf4j by zolyfarkas.
the class DecentSemaphoreHandler method main.
@SuppressFBWarnings("MDM_THREAD_YIELD")
public static void main(final String[] args) throws InterruptedException, TimeoutException, SQLException, IOException {
String connectionString = args[0];
String semaphoreName = args[1];
JdbcDataSource ds = new JdbcDataSource();
ds.setURL(connectionString);
ds.setUser("sa");
ds.setPassword("sa");
Sampler s = new Sampler(5, 10000);
s.registerJmx();
s.start();
LOG.info("started sampling");
JdbcSemaphore semaphore = new JdbcSemaphore(ds, semaphoreName, 3);
for (int i = 0; i < 50; i++) {
semaphore.acquire(1, 1L, TimeUnit.SECONDS);
Thread.sleep((long) (Math.random() * 10) + 10);
LOG.info("beat");
Thread.sleep((long) (Math.random() * 10) + 10);
semaphore.release();
}
semaphore.close();
File dumpToFile = s.dumpToFile();
LOG.info("stack samples dumped to {}", dumpToFile);
s.stop();
System.exit(0);
}
Aggregations