Commit 5c55954d authored by Stefan Dähling's avatar Stefan Dähling
Browse files

add jade benchmarks

parent cff20dcc
Pipeline #347419 passed with stages
in 1 minute and 32 seconds
......@@ -110,7 +110,7 @@ func pingPong(ag *agency.Agent, config CustomAgentData) (err error) {
var rtts []int
var msg schemas.ACLMessage
msg, err = ag.ACL.NewMessage(config.PeerID, schemas.FIPAProtQuery, schemas.FIPAPerfInform,
"test msg")
"hello world")
if err != nil {
fmt.Println(err)
}
......@@ -214,7 +214,7 @@ func pingPongft(ag *agency.Agent, config CustomAgentData) (err error) {
var rtts []int
var msg schemas.ACLMessage
msg, err = ag.ACL.NewMessage(config.PeerID, schemas.FIPAProtQuery, schemas.FIPAPerfInform,
"test msg")
"hello world")
if err != nil {
fmt.Println(err)
}
......
package benchmark.CPULoad;
import jade.core.*;
import jade.core.behaviours.*;
import jade.lang.acl.ACLMessage;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.util.Logger;
/**
*/
public class CPULoad extends Agent {
private Logger myLogger = Logger.getMyLogger(getClass().getName());
private class CPULoadBehaviour extends CyclicBehaviour {
ACLMessage msg;
ACLMessage msg2;
long startTime;
long lastSentTime;
double[] a;
double[] b;
double[] c;
float T;
float Tr;
public CPULoadBehaviour(Agent ag) {
super(ag);
Object[] args = getArguments();
T = Float.parseFloat(args[2].toString());
Tr = Float.parseFloat(args[3].toString());
a = new double[100];
b = new double[100];
c = new double[100];
for (int i = 0; i < 100; i++) {
a[i] = Math.random();
b[i] = Math.random();
c[i] = Math.random();
}
msg2 = new ACLMessage(ACLMessage.INFORM);
msg2.setSender(myAgent.getAID());
AID receiver = new AID(args[0].toString(), AID.ISLOCALNAME);
msg2.addReceiver(receiver);
msg2.setProtocol("p");
msg2.setContent("hello world");
lastSentTime = 0;
try{
Thread.sleep(80000);
}
catch (InterruptedException temp){
}
}
public void action() {
startTime = System.nanoTime();
for (;;) {
for (int i = 0; i < 100; i++) {
a[i] = b[i] + c[i];
}
float diff = (System.nanoTime() - startTime) / 1000000;
if (diff > T*Tr) {
break;
}
}
if (System.nanoTime() > lastSentTime+1000000) {
lastSentTime = System.nanoTime();
send(msg2);
msg = myAgent.receive();
}
try{
Thread.sleep((long)(T*(1-Tr)));
}
catch (InterruptedException temp){
}
}
}
protected void setup() {
CPULoadBehaviour CPUBehaviour = new CPULoadBehaviour(this);
addBehaviour(CPUBehaviour);
}
}
package benchmark.DF;
import java.util.Random;
import jade.core.*;
import jade.core.behaviours.*;
import jade.lang.acl.ACLMessage;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.util.Logger;
/**
*/
public class DF extends Agent {
private Logger myLogger = Logger.getMyLogger(getClass().getName());
private class DFBehaviour extends OneShotBehaviour{
Agent agnt;
long[] rtts;
public DFBehaviour(Agent ag) {
super(ag);
agnt = ag;
rtts = new long[11];
Object[] args = getArguments();
try{
Thread.sleep(10000);
}
catch (InterruptedException temp){
}
}
public void action() {
Random r = new Random();
for (int i = 0; i < 100; i++) {
DFAgentDescription searchAgentTemplate = new DFAgentDescription();
ServiceDescription searchServiceTemplate = new ServiceDescription();
searchServiceTemplate.setType("svc"+String.valueOf(r.nextInt(7)));
searchAgentTemplate.addServices(searchServiceTemplate);
try{
DFService.search(agnt, searchAgentTemplate);
}
catch (FIPAException fe) {
fe.printStackTrace();
}
}
long startTime = System.nanoTime();
try {
DFAgentDescription registerAgentTemplate = new DFAgentDescription();
registerAgentTemplate.setName(getAID());
ServiceDescription registerServiceTemplate = new ServiceDescription();
registerServiceTemplate.setName(getAID().getName());
registerServiceTemplate.setType("svc"+String.valueOf(r.nextInt(7)));
registerAgentTemplate.addServices(registerServiceTemplate);
DFService.register(agnt, registerAgentTemplate);
}
catch (FIPAException fe) {
fe.printStackTrace();
}
long regTime = System.nanoTime();
rtts[0] = (regTime - startTime) / 1000;
for (int i = 0; i < 8; i++) {
long searchStart = System.nanoTime();
DFAgentDescription searchAgentTemplate = new DFAgentDescription();
ServiceDescription searchServiceTemplate = new ServiceDescription();
searchServiceTemplate.setType("svc"+String.valueOf(r.nextInt(7)));
searchAgentTemplate.addServices(searchServiceTemplate);
try{
DFService.search(agnt, searchAgentTemplate);
}
catch (FIPAException fe) {
fe.printStackTrace();
}
long searchStop = System.nanoTime();
rtts[i+1] = (searchStop-searchStart) / 1000;
}
long deregStart = System.nanoTime();
try{
DFService.deregister(agnt);
}
catch(FIPAException fe) {
fe.printStackTrace();
}
long stopTime = System.nanoTime();
rtts[9] = (stopTime - deregStart) / 1000;
rtts[10] = (stopTime - startTime)/1000;
for (int i = 0; i < 100; i++) {
DFAgentDescription searchAgentTemplate = new DFAgentDescription();
ServiceDescription searchServiceTemplate = new ServiceDescription();
searchServiceTemplate.setType("svc"+String.valueOf(r.nextInt(7)));
searchAgentTemplate.addServices(searchServiceTemplate);
try{
DFService.search(agnt, searchAgentTemplate);
}
catch (FIPAException fe) {
}
}
String content = "";
for (int i = 0; i < 11; i++) {
content += String.valueOf(rtts[i]);
if (i < 10) {
content+= ";";
}
}
ACLMessage logmsg = new ACLMessage(ACLMessage.INFORM);
logmsg.setSender(myAgent.getAID());
AID receiver = new AID("logag", AID.ISLOCALNAME);
logmsg.addReceiver(receiver);
logmsg.setProtocol("p");
logmsg.setContent(content);
send(logmsg);
}
}
protected void setup() {
DFBehaviour df = new DFBehaviour(this);
addBehaviour(df);
}
}
package benchmark.DF;
import jade.core.*;
import jade.core.behaviours.*;
import jade.lang.acl.ACLMessage;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.util.Logger;
import java.util.Arrays;
/**
*/
public class LogAgent extends Agent {
private Logger myLogger = Logger.getMyLogger(getClass().getName());
private class LogBehaviour extends CyclicBehaviour {
int numAgs;
int numMeas;
ACLMessage msg;
long avgSum, minSum, maxSum, percSum, avgReg, minReg, maxReg, percReg, avgSearch, minSearch, maxSearch, percSearch, avgDereg, minDereg, maxDereg, percDereg;
int[] rttsSum, rttsReg, rttsSearch, rttsDereg;
public LogBehaviour(Agent a) {
super(a);
Object[] args = getArguments();
numAgs = Integer.parseInt(args[0].toString());
avgSum = 0;
minSum = 1000000;
maxSum = 0;
percSum = 0;
avgReg = 0;
minReg = 1000000;
maxReg = 0;
percReg = 0;
avgSearch = 0;
minSearch = 1000000;
maxSearch = 0;
percSearch = 0;
avgDereg = 0;
minDereg = 1000000;
maxDereg = 0;
percDereg = 0;
rttsSum = new int[numAgs];
rttsReg = new int[numAgs];
rttsSearch = new int[numAgs*8];
rttsDereg = new int[numAgs];
numMeas = 0;
}
public void action() {
msg = myAgent.receive();
if(msg != null){
String[] temp = msg.getContent().split(";");
if (temp.length == 11) {
for (int i = 0; i < 11; i++) {
if (i == 0) {
rttsReg[numMeas] = Integer.parseInt(temp[i]);
} else if (i == 9) {
rttsDereg[numMeas] = Integer.parseInt(temp[i]);
} else if (i == 10) {
rttsSum[numMeas] = Integer.parseInt(temp[i]);
} else {
rttsSearch[numMeas*8+(i-1)] = Integer.parseInt(temp[i]);
}
}
}
numMeas++;
if (numMeas == numAgs) {
Arrays.sort(rttsSum);
minSum = rttsSum[0];
maxSum = rttsSum[numAgs-1];
int percindex = numAgs*95/100;
if (percindex < numAgs) {
percSum = rttsSum[percindex];
}
for (int i = 0; i < numAgs; i++) {
avgSum += rttsSum[i];
}
avgSum = avgSum / numAgs;
myLogger.log(Logger.INFO, "Sum: "+ String.valueOf(minSum)+","+String.valueOf(maxSum)+","+String.valueOf(avgSum)+","+String.valueOf(percSum));
Arrays.sort(rttsReg);
minReg = rttsReg[0];
maxReg = rttsReg[numAgs-1];
percindex = numAgs*95/100;
if (percindex < numAgs) {
percReg = rttsReg[percindex];
}
for (int i = 0; i < numAgs; i++) {
avgReg += rttsReg[i];
}
avgReg = avgReg / numAgs;
myLogger.log(Logger.INFO, "Reg: "+ String.valueOf(minReg)+","+String.valueOf(maxReg)+","+String.valueOf(avgReg)+","+String.valueOf(percReg));
Arrays.sort(rttsSearch);
minSearch = rttsSearch[0];
maxSearch = rttsSearch[8*numAgs-1];
percindex = numAgs*8*95/100;
if (percindex < numAgs*8) {
percSearch = rttsSearch[percindex];
}
for (int i = 0; i < 8*numAgs; i++) {
avgSearch += rttsSearch[i];
}
avgSearch = avgSearch / (8*numAgs);
myLogger.log(Logger.INFO, "Search: "+ String.valueOf(minSearch)+","+String.valueOf(maxSearch)+","+String.valueOf(avgSearch)+","+String.valueOf(percSearch));
Arrays.sort(rttsDereg);
minDereg = rttsDereg[0];
maxDereg = rttsDereg[numAgs-1];
percindex = numAgs*95/100;
if (percindex < numAgs) {
percDereg = rttsDereg[percindex];
}
for (int i = 0; i < numAgs; i++) {
avgDereg += rttsDereg[i];
}
avgDereg = avgDereg / numAgs;
myLogger.log(Logger.INFO, "Dereg: "+ String.valueOf(minDereg)+","+String.valueOf(maxDereg)+","+String.valueOf(avgDereg)+","+String.valueOf(percDereg));
}
}
else {
block();
}
}
}
protected void setup() {
LogBehaviour LBehaviour = new LogBehaviour(this);
addBehaviour(LBehaviour);
}
}
package benchmark.PingPong;
import jade.core.*;
import jade.core.behaviours.*;
import jade.lang.acl.ACLMessage;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.util.Logger;
import java.util.Arrays;
/**
*/
public class LogAgent extends Agent {
private Logger myLogger = Logger.getMyLogger(getClass().getName());
private class LogBehaviour extends CyclicBehaviour {
int numPairs;
int numMeas;
ACLMessage msg;
long avg, min, max, perc;
int[] rtts;
public LogBehaviour(Agent a) {
super(a);
Object[] args = getArguments();
numPairs = Integer.parseInt(args[0].toString());
numMeas = 0;
avg = 0;
min = 1000000;
max = 0;
perc = 0;
rtts = new int[numPairs*1000];
}
public void action() {
msg = myAgent.receive();
if(msg != null){
String[] temp = msg.getContent().split(";");
if (temp.length == 1000) {
for (int i = 0; i < 1000; i++) {
rtts[numMeas*1000+i] = Integer.parseInt(temp[i]);
}
}
numMeas++;
if (numMeas == numPairs) {
Arrays.sort(rtts);
min = rtts[0];
max = rtts[numPairs*1000-1];
int percindex = numPairs*950+1;
if (percindex < numPairs*1000-1) {
perc = rtts[percindex];
}
for (int i = 0; i < numPairs*1000; i++) {
avg += rtts[i];
}
avg = avg / (numPairs*1000);
myLogger.log(Logger.INFO, String.valueOf(min)+","+String.valueOf(max)+","+String.valueOf(avg)+","+String.valueOf(perc));
}
}
else {
block();
}
}
}
protected void setup() {
LogBehaviour LBehaviour = new LogBehaviour(this);
addBehaviour(LBehaviour);
}
}
package benchmark.PingPong;
import jade.core.*;
import jade.core.behaviours.*;
import jade.lang.acl.ACLMessage;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.util.Logger;
/**
*/
public class PingPong extends Agent {
private Logger myLogger = Logger.getMyLogger(getClass().getName());
private class PingPongBehaviour extends CyclicBehaviour {
ACLMessage msg;
ACLMessage msg2;
private boolean finished = false;
long startTime;
int counter = 0;
long[] rtts;
boolean start = false;
public PingPongBehaviour(Agent a) {
super(a);
Object[] args = getArguments();
msg2 = new ACLMessage(ACLMessage.INFORM);
msg2.setSender(myAgent.getAID());
AID receiver = new AID(args[0].toString(), AID.ISLOCALNAME);
msg2.addReceiver(receiver);
msg2.setProtocol("p");
msg2.setContent("hello world");
rtts = new long[1000];
try{
Thread.sleep(10000);
}
catch (InterruptedException temp){
}
startTime = System.nanoTime();
if(args[1].toString().equals("true")) {
start = true;
send(msg2);
}
}
public void action() {
msg = myAgent.receive();
long stopTime = System.nanoTime();
long elapsedTime = (stopTime - startTime)/1000;
if(msg != null){
msg = null;
if (counter < 10000) {
if (counter >= 1000 && counter < 2000) {
rtts[counter-1000] = elapsedTime;
}
msg2.setContent(String.valueOf(counter));
startTime = System.nanoTime();
send(msg2);
counter++;
}
if (counter == 3000) {
String content = "";
long avg, min, max;
min = 1000;
max = 0;
avg = 0;
for (int i = 0; i < 1000; i++) {
content += String.valueOf(rtts[i]);
if (i < 999) {
content+= ";";
}
if (rtts[i] > max) {
max = rtts[i];
}
if (rtts[i] < min) {
min = rtts[i];
}
avg += rtts[i];
}
avg = avg / 1000;
ACLMessage logmsg = new ACLMessage(ACLMessage.INFORM);
logmsg.setSender(myAgent.getAID());
AID receiver = new AID("logag", AID.ISLOCALNAME);
logmsg.addReceiver(receiver);
logmsg.setProtocol("p");
logmsg.setContent(content);
if(start) {
send(logmsg);
}
}
}
else {
block();
}
}
}
protected void setup() {
PingPongBehaviour PPBehaviour = new PingPongBehaviour(this);
addBehaviour(PPBehaviour);
}
}
package benchmark.RepPingPong;
import jade.core.*;
import jade.core.behaviours.*;
import jade.lang.acl.ACLMessage;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.util.Logger;
import java.util.Arrays;