Fix timing
This commit is contained in:
parent
3f6730f9f5
commit
ad59dd7c4d
@ -86,15 +86,13 @@ public abstract class NetManager {
|
||||
ex.prestartAllCoreThreads();
|
||||
|
||||
i_tex.scheduleAtFixedRate(()-> {
|
||||
System.out.println("NetManager DeliverIf/BroadcastIf");
|
||||
nm_listeners.values().forEach(nmh-> {
|
||||
nmh.deliverIf();
|
||||
nmh.broadcastIf();
|
||||
});
|
||||
System.err.println("NetManager DeliverIf/BroadcastIf");
|
||||
nm_listeners.values().forEach(NetEventHandlerInterface::deliverIf);
|
||||
nm_listeners.values().forEach(NetEventHandlerInterface::broadcastIf);
|
||||
}, 0, INTERNAL_WAIT, TimeUnit.MILLISECONDS);
|
||||
|
||||
fd_tex.scheduleAtFixedRate(()-> {
|
||||
System.out.println("NetManager HeartBeat");
|
||||
System.err.println("NetManager HeartBeat");
|
||||
nm_listeners.values().forEach(NetEventHandlerInterface::beat);
|
||||
}, 0, FD_WAIT, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
@ -104,7 +102,7 @@ public abstract class NetManager {
|
||||
* Stops the NetManager
|
||||
*/
|
||||
public static void stop() {
|
||||
System.out.println("NetManager is stopping...");
|
||||
System.err.println("NetManager is stopping...");
|
||||
isStopped = true;
|
||||
nm_listeners.values().forEach(NetEventHandlerAbstract::stop);
|
||||
ex.shutdown();
|
||||
@ -120,7 +118,7 @@ public abstract class NetManager {
|
||||
public static boolean isDone() {
|
||||
return isStopped || nm_listeners.values().stream().map(nmh ->{
|
||||
if(!nmh.isDone()){
|
||||
System.out.println("NetManager Waiting for: "+nmh.getClass().getSimpleName());
|
||||
System.err.println("NetManager Waiting for: "+nmh.getClass().getSimpleName());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -5,9 +5,6 @@ import cs451.net.event.NetEvent;
|
||||
import cs451.parser.Host;
|
||||
import cs451.parser.Parser;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* NetEventHandler abstraction class
|
||||
*
|
||||
@ -22,8 +19,6 @@ public abstract class NetEventHandlerAbstract implements NetEventHandlerInterfac
|
||||
private final Class<? extends NetEventHandlerAbstract> deliverLayer;
|
||||
private final Class<? extends NetEventHandlerAbstract> broadcastLayer;
|
||||
|
||||
public final AtomicBoolean active = new AtomicBoolean(true);
|
||||
|
||||
|
||||
/**
|
||||
* Initialized the main NetEventHandler fields
|
||||
@ -99,17 +94,11 @@ public abstract class NetEventHandlerAbstract implements NetEventHandlerInterfac
|
||||
* @param h host (self)
|
||||
* @param p parser
|
||||
*/
|
||||
public void start(Host h, Parser p) {
|
||||
Objects.requireNonNull(h);
|
||||
Objects.requireNonNull(p);
|
||||
active.set(true);
|
||||
}
|
||||
public void start(Host h, Parser p) {}
|
||||
|
||||
/**
|
||||
* Stops the NetEventHandler
|
||||
*/
|
||||
public void stop() {
|
||||
active.set(false);
|
||||
}
|
||||
public void stop() {}
|
||||
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ public class NetHandlerFD extends NetEventHandlerAbstract {
|
||||
public synchronized void beat() {
|
||||
hosts.forEach(h-> {
|
||||
alive.computeIfPresent(h.getId(),(k, v) -> {
|
||||
if(v > -1) broadcastNextAsync(NetEvent.MessageHRTB(h));
|
||||
broadcastNextSync(NetEvent.MessageHRTB(h));
|
||||
return v+1;
|
||||
});
|
||||
if(alive.getOrDefault(h.getId(),-1) >= NetManager.FD_MAX_TRIES){
|
||||
crashNextAsync(NetEvent.Message(h, Message.EMPTY()));
|
||||
if(alive.getOrDefault(h.getId(),0) > NetManager.FD_MAX_TRIES){
|
||||
crashNextSync(NetEvent.Message(h, Message.EMPTY()));
|
||||
alive.remove(h.getId());
|
||||
}
|
||||
});
|
||||
@ -49,11 +49,9 @@ public class NetHandlerFD extends NetEventHandlerAbstract {
|
||||
|
||||
@Override
|
||||
public void deliver(NetEvent ne) {
|
||||
alive.computeIfPresent(ne.peer.getId(),(k,v)->-1);
|
||||
alive.computeIfPresent(ne.peer.getId(),(k,v)->0);
|
||||
if (ne.message.tpe != Message.TYPE.HRTB) {
|
||||
deliverNextSync(ne);
|
||||
}else{
|
||||
broadcastNextSync(NetEvent.MessageHRTB(ne.peer));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,11 @@ public class NetHandlerFIFO extends NetEventHandlerAbstract {
|
||||
@Override
|
||||
public void deliver(NetEvent ne) {
|
||||
pending.add(ne.message);
|
||||
deliverIf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return pending.stream().noneMatch(hmp -> hmp.id.equals(rsn.getOrDefault(hmp.src, 1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -88,7 +88,7 @@ public class NetHandlerSCKT extends NetEventHandlerAbstract {
|
||||
}
|
||||
|
||||
tex.execute(()->{
|
||||
while (active.get()) {
|
||||
while (true) {
|
||||
deliver(NetEvent.EMPTY());
|
||||
}
|
||||
});
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cs451.net.handler;
|
||||
|
||||
import cs451.net.NetManager;
|
||||
import cs451.net.event.Message;
|
||||
import cs451.net.event.*;
|
||||
import cs451.parser.Host;
|
||||
@ -32,14 +33,15 @@ public class NetHandlerSL extends NetEventHandlerAbstract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void broadcastIf(){
|
||||
public synchronized void beat(){
|
||||
sending.removeIf(ppm -> hasTimeout.contains(ppm.first()));
|
||||
sending.forEach(ppm -> hosts.stream().filter(hl->hl.getId()==ppm.first()).findFirst()
|
||||
sending.stream().limit(NetManager.WINDOW_WIDTH).forEach(ppm -> hosts.stream().filter(hl->hl.getId()==(ppm.first())).findFirst()
|
||||
.ifPresent(host -> broadcastNextSync(NetEvent.Message(host, ppm.second()))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(NetEvent ne) {
|
||||
if (!hasTimeout.contains(ne.peer.getId()))
|
||||
sending.add(new Pair<>(ne.peer.getId(),Message.MSG(ne.message)));
|
||||
broadcastNextSync(ne);
|
||||
}
|
||||
@ -66,13 +68,6 @@ public class NetHandlerSL extends NetEventHandlerAbstract {
|
||||
crashNextSync(ne);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recover(NetEvent ne) {
|
||||
hasTimeout.remove(ne.peer.getId());
|
||||
recoverNextSync(ne);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return sending.isEmpty();
|
||||
|
@ -46,7 +46,6 @@ public class NetHandlerTOPL extends NetEventHandlerAbstract {
|
||||
@Override
|
||||
public void broadcast(NetEvent ne) {
|
||||
status.set(true);
|
||||
broadcastIf();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,7 +54,6 @@ public class NetHandlerTOPL extends NetEventHandlerAbstract {
|
||||
delivered.incrementAndGet();
|
||||
waiting.decrementAndGet();
|
||||
}
|
||||
broadcastIf();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,13 +62,11 @@ public class NetHandlerURB extends NetEventHandlerAbstract {
|
||||
if(pending.add(smp)){
|
||||
broadcastNextAsync(ne);
|
||||
}
|
||||
deliverIf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void crash(NetEvent ne) {
|
||||
correct.remove(ne.peer.getId());
|
||||
deliverIf();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,14 +30,14 @@ public abstract class ParamDetector {
|
||||
|
||||
int messages = p.messageCount();
|
||||
int processCount = p.hosts().size();
|
||||
int windowWidthMult = Math.toIntExact(Math.round(Math.pow(2.0,(5-(processCount/5.0)))));
|
||||
int windowWidthMult = Math.toIntExact(Math.round(Math.pow(2.0,(4-(processCount/4.0)))));
|
||||
int windowWidth = bound(coresPerProcess*windowWidthMult,4,messages);
|
||||
|
||||
System.out.println("Process expected to broadcast "+messages+" messages.");
|
||||
System.out.println("Starting Process with WindowWidth of "+windowWidth+" (~ x"+windowWidthMult+").");
|
||||
NetManager.WINDOW_WIDTH = windowWidth;
|
||||
|
||||
NetManager.INTERNAL_WAIT = 500;
|
||||
NetManager.INTERNAL_WAIT = 50;
|
||||
|
||||
//We might want to PingPong To set Custom Timing Limitations....
|
||||
NetManager.FD_MAX_TRIES = 10;
|
||||
|
Loading…
x
Reference in New Issue
Block a user