Merge pull request #120 from deskenny/master

[performance] Correcting invalid 0 passed by PeerDiscovery & PeerDiscoveryMonitorThread
This commit is contained in:
romanman 2014-09-13 23:36:24 +02:00
commit 3beb1904b1
2 changed files with 25 additions and 14 deletions

View File

@ -45,7 +45,7 @@ public class PeerDiscovery {
new ArrayBlockingQueue<Runnable>(CONFIG.peerDiscoveryWorkers()), threadFactory, rejectionHandler);
//start the monitoring thread
monitor = new PeerDiscoveryMonitorThread(executorPool, 0);
monitor = new PeerDiscoveryMonitorThread(executorPool, 1);
Thread monitorThread = new Thread(monitor);
monitorThread.start();

View File

@ -1,18 +1,19 @@
package org.ethereum.net.peerdiscovery;
import java.util.concurrent.ThreadPoolExecutor;
import org.ethereum.manager.WorldManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ThreadPoolExecutor;
public class PeerDiscoveryMonitorThread implements Runnable {
private final static Logger logger = LoggerFactory.getLogger("peerdiscovery");
private ThreadPoolExecutor executor;
private int seconds;
private volatile boolean run = true;
private StringBuffer toStringBuff = new StringBuffer();
public PeerDiscoveryMonitorThread(ThreadPoolExecutor executor, int delay) {
this.executor = executor;
this.seconds = delay;
@ -25,16 +26,26 @@ public class PeerDiscoveryMonitorThread implements Runnable {
@Override
public void run() {
while(run) {
logger.trace(
String.format("[monitor] [%d/%d] Active: %d, Completed: %d, Task: %d, isShutdown: %s, isTerminated: %s, peersDiscovered: %d ",
this.executor.getPoolSize(),
this.executor.getCorePoolSize(),
this.executor.getActiveCount(),
this.executor.getCompletedTaskCount(),
this.executor.getTaskCount(),
this.executor.isShutdown(),
this.executor.isTerminated(),
WorldManager.getInstance().getPeers().size()));
if (logger.isDebugEnabled()) {
toStringBuff.setLength(0);
toStringBuff.append("[monitor] [");
toStringBuff.append(this.executor.getPoolSize());
toStringBuff.append("/");
toStringBuff.append(this.executor.getCorePoolSize());
toStringBuff.append("] Active: ");
toStringBuff.append(this.executor.getActiveCount());
toStringBuff.append(", Completed: ");
toStringBuff.append(this.executor.getCompletedTaskCount());
toStringBuff.append(", Task: ");
toStringBuff.append(this.executor.getTaskCount());
toStringBuff.append(", isShutdown: ");
toStringBuff.append(this.executor.isShutdown());
toStringBuff.append(", isTerminated: ");
toStringBuff.append(this.executor.isTerminated());
toStringBuff.append(", peersDiscovered: ");
toStringBuff.append(WorldManager.getInstance().getPeers().size());
logger.trace(toStringBuff.toString());
}
try {
Thread.sleep(seconds*1000);
} catch (InterruptedException e) {