Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Aug 28, 2024
1 parent a35085e commit e5ad28a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/org/jgroups/protocols/TP.java
Original file line number Diff line number Diff line change
Expand Up @@ -1214,10 +1214,12 @@ public void passMessageUp(Message msg, byte[] cluster_name, boolean perform_clus
}
return;
}
TpHeader hdr=msg.getHeader(id);
if(hdr != null && hdr.flag() > 0) {
rtt.handleMessage(msg, hdr);
return;
if(rtt.enabled()) {
TpHeader hdr=msg.getHeader(id);
if(hdr != null && hdr.flag() > 0) {
rtt.handleMessage(msg, hdr);
return;
}
}
up_prot.up(msg);
}
Expand Down Expand Up @@ -1245,12 +1247,14 @@ public void passBatchUp(MessageBatch batch, boolean perform_cluster_name_matchin

if(batch.multicast() && discard_own_mcast && local_addr != null && local_addr.equals(batch.sender()))
return;
for(Iterator<Message> it=batch.iterator(); it.hasNext();) {
Message msg=it.next();
TpHeader hdr=msg.getHeader(id);
if(hdr != null && hdr.flag() > 0) {
it.remove();
rtt.handleMessage(msg, hdr);
if(rtt.enabled()) {
for(Iterator<Message> it=batch.iterator(); it.hasNext(); ) {
Message msg=it.next();
TpHeader hdr=msg.getHeader(id);
if(hdr != null && hdr.flag() > 0) {
it.remove();
rtt.handleMessage(msg, hdr);
}
}
}
if(!batch.isEmpty())
Expand Down
7 changes: 7 additions & 0 deletions src/org/jgroups/util/RTT.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class RTT {
protected TP transport;
protected short tp_id;

@Property(description="Enables or disables RTT functionality")
protected boolean enabled;

@Property(description="The number of RPCs to send")
protected int num_reqs=10;

Expand All @@ -36,6 +39,8 @@ public class RTT {
protected final Map<Address,AverageMinMax> rtts=Util.createConcurrentMap();
protected final Map<Address,long[]> times=Util.createConcurrentMap(); // list of start times (us)

public boolean enabled() {return enabled;}
public RTT enabled(boolean f) {enabled=f; return this;}
public int numReqs() {return num_reqs;}
public RTT numReqs(int n) {this.num_reqs=n; return this;}
public long timeout() {return timeout;}
Expand Down Expand Up @@ -74,6 +79,8 @@ public String rtt(int num_reqs, boolean details) {
*/
@ManagedOperation(description="Sends N RPCs to all other nodes and computes min/avg/max RTT")
public String rtt(int num_reqs, int size, boolean details, boolean exclude_self) {
if(!enabled)
return "RTT functionality is disabled";
Map<Address,AverageMinMax> m=_rtt(num_reqs, size, exclude_self);
return m.entrySet().stream()
.map(e -> String.format("%s: %s", e.getKey(), print(e.getValue(), details, TimeUnit.MICROSECONDS, num_reqs)))
Expand Down

0 comments on commit e5ad28a

Please sign in to comment.