Skip to content

Commit

Permalink
add 'afr' for user to set wrok accptable failure in configure file
Browse files Browse the repository at this point in the history
  • Loading branch information
Cxquan committed Mar 27, 2014
1 parent 7712367 commit 7ca68e6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<field name="rampdown" type="integer">
<bind-xml name="rampdown" node="attribute" />
</field>

<field name="afr" type="integer">
<bind-xml name="afr" node="attribute" />
</field>

<field name="totalOps" type="integer">
<bind-xml name="totalOps" node="attribute" />
Expand Down
24 changes: 24 additions & 0 deletions dev/cosbench-config/src/com/intel/cosbench/config/Work.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class Work implements Iterable<Operation> {
private int runtime = 0;
private int rampup = 0;
private int rampdown = 0;
private int afr = 0; // acceptable failure ratio, the unit is samples per one million, default is 0.
private int totalOps = 0;
private long totalBytes = 0;
private String driver;
Expand Down Expand Up @@ -133,6 +134,16 @@ public void setRampup(int rampup) {
throw new ConfigException("illegal ramp up time: " + rampup);
this.rampup = rampup;
}

public int getAfr() {
return afr;
}

public void setAfr(int afr) {
if (afr < 0)
throw new ConfigException("illegal afr: " + afr);
this.afr = afr;
}

public int getRampdown() {
return rampdown;
Expand Down Expand Up @@ -204,6 +215,14 @@ public void setStorage(Storage storage) {
throw new ConfigException("a work must have its storge");
this.storage = storage;
}

public List<String> getOperationIDs() {
List<String> opIds = new ArrayList<String>();
for (Operation operation : operations) {
opIds.add(operation.getId());
}
return opIds;
}

public List<Operation> getOperations() {
return operations;
Expand Down Expand Up @@ -233,6 +252,7 @@ private void toPrepareWork() {
name = "prepare";
setDivision("object");
setRuntime(0);
setAfr(0);
setTotalBytes(0);
setTotalOps(getWorkers());
Operation op = new Operation();
Expand All @@ -252,6 +272,7 @@ private void toCleanupWork() {
name = "cleanup";
setDivision("object");
setRuntime(0);
setAfr(0);
setTotalBytes(0);
setTotalOps(getWorkers());
Operation op = new Operation();
Expand All @@ -271,6 +292,7 @@ private void toInitWork() {
name = "init";
setDivision("container");
setRuntime(0);
setAfr(0);
setTotalBytes(0);
setTotalOps(getWorkers());
Operation op = new Operation();
Expand All @@ -286,6 +308,7 @@ private void toDisposeWork() {
name = "dispose";
setDivision("container");
setRuntime(0);
setAfr(0);
setTotalBytes(0);
setTotalOps(getWorkers());
Operation op = new Operation();
Expand All @@ -301,6 +324,7 @@ public void toDelayWork() {
name = "delay";
setDivision("none");
setRuntime(0);
setAfr(0);
setTotalBytes(0);
setWorkers(1);
setTotalOps(getWorkers());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<field name="rampdown" type="integer">
<bind-xml name="rampdown" node="attribute" />
</field>

<field name="afr" type="integer">
<bind-xml name="afr" node="attribute" />
</field>

<field name="totalOps" type="integer">
<bind-xml name="totalOps" node="attribute" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import java.util.*;
import java.util.concurrent.*;

import com.intel.cosbench.bench.Metrics;
import com.intel.cosbench.bench.Sample;
import com.intel.cosbench.config.Operation;
import com.intel.cosbench.config.Stage;
import com.intel.cosbench.config.Work;
import com.intel.cosbench.controller.model.*;
import com.intel.cosbench.controller.schedule.*;
import com.intel.cosbench.controller.tasklet.*;
Expand Down Expand Up @@ -144,8 +148,39 @@ private void runStage() {
return;
}
}

if (!reachAFRGoal()) {
stageContext.setState(FAILED);
return;
}
stageContext.setState(COMPLETED);
}

private boolean reachAFRGoal() {
String id = stageContext.getId();
stageContext.setReport(stageContext.mergeReport());
for (Work work : stageContext.getStage().getWorks()) {
List<String> operationIDs = work.getOperationIDs();
int sumSampleCount = 0;
int sumTotalSampleCount = 0;
for (Metrics metric : stageContext.getReport().getAllMetrics()) {
if (operationIDs.contains(metric.getOpId())) {
sumSampleCount +=
metric.getSampleCount() > 0 ? metric.getSampleCount() : 0;
sumTotalSampleCount +=
metric.getTotalSampleCount() > 0 ? metric.getTotalSampleCount() : 0;
}
}
LOGGER.debug("succ-ratio of work {} = {}", id+"-"+work.getName(),
sumTotalSampleCount > 0 ? (double)sumSampleCount / sumTotalSampleCount : "N/A");
if (sumTotalSampleCount - sumSampleCount > sumTotalSampleCount * work.getAfr() / 1000000) {
LOGGER.info("fail to reach the goal of acceptable failure ratio in stage {} - work {}", id, work.getName());
return false;
}
LOGGER.info("successfully reach the goal of acceptable failure ratio in stage {} - work {}", id, work.getName());
}
return true;
}

private void bootTasks() {
String id = stageContext.getId();
Expand Down

0 comments on commit 7ca68e6

Please sign in to comment.