use of com.nhnent.eat.entity.Messages in project eat by nhnent.
the class ManagerActor method doRun.
/**
* doRun of Actor. It performs requests on Actor Mailbox.
*/
@Override
protected Void doRun() throws SuspendExecution {
try {
NettyClient.initEventLoopGroup();
MDC.put("playerId", "Manager");
MDC.put("strand", Strand.currentStrand().getName());
// Read config, and Spawn TestActor according to config.
int cntOfTest = Config.obj().getScenario().getPlayerCount();
spawnActor();
// Request test preparation to TestActors
for (int idx = 0; idx < cntOfTest; idx++) {
ActorRef tester = actorList.get(idx);
tester.send(makeRequestTestPreparationMessage(idx));
logger.debug("Request preparation to tester actor (" + tester.toString() + ")");
}
// Wait for preparation from all of TestActors
int receivedPreparedCnt = 0;
while (true) {
Object o = receive();
if (o instanceof Messages) {
Messages m = (Messages) o;
if (m.type == MessageType.TestPrepared) {
receivedPreparedCnt++;
logger.info("Receive message(Test Preparation is Finish), " + receivedPreparedCnt + "/" + cntOfTest);
if (receivedPreparedCnt >= cntOfTest) {
break;
}
}
}
}
Date testStartDateTime = new Date();
// Request test to TestActors
for (int idx = 0; idx < cntOfTest; idx++) {
ActorRef tester = actorList.get(idx);
tester.send(new Messages(this.ref, MessageType.TestStart));
logger.info("Request preparation to tester actor (" + tester.toString() + ")");
if (Config.obj().getScenario().getTestActorStartGap() != 0) {
Strand.sleep(Config.obj().getScenario().getTestActorStartGap());
}
}
// Wait for test finishing from all of TestActors
int receivedTestFinishCnt = 0;
ScenarioExecutionResult[] results = new ScenarioExecutionResult[cntOfTest];
for (; ; ) {
Object o = receive();
if (o instanceof Messages) {
Messages m = (Messages) o;
if (m.type == MessageType.TestFinished) {
results[receivedTestFinishCnt] = m.scenarioExecutionResult;
receivedTestFinishCnt++;
logger.info("[userId:{}] Receive message(Test is Finished), {}/{}", m.userId, receivedTestFinishCnt, cntOfTest);
if (receivedTestFinishCnt >= cntOfTest) {
break;
}
}
}
}
JMXClient.obj().disconnect();
Date testEndDateTime = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
logger.info(String.format("Testing period : %s ~ %s", dateFormat.format(testStartDateTime), dateFormat.format(testEndDateTime)));
long diff = testEndDateTime.getTime() - testStartDateTime.getTime();
logger.info("Elapsed time(sec) : " + (diff / 1000));
logger.info("Total transferred packet : " + transmitDataTotalCount);
double avgTransPacketCount = (double) transmitDataTotalCount / (diff / 1000.0);
logger.info("Average Transferred packet for 1 sec: " + String.format("%.2f", avgTransPacketCount));
ReportHandler reportHandler = new ReportHandler();
reportHandler.writeFinalStatisticsResult(results);
NettyClient.shutdownEventLoopGroup();
} catch (final Exception e) {
logger.error("Exception is raised", e);
}
MDC.remove("playerId");
MDC.remove("strand");
MDC.remove("logfileName");
return null;
}
use of com.nhnent.eat.entity.Messages in project eat by nhnent.
the class ManagerActor method makeRequestTestPreparationMessage.
/**
* Make execute message of test preparation.
*
* @param idx index of test player
* @return generated message
*/
private Messages makeRequestTestPreparationMessage(final int idx) {
String userId = EmptyString;
int playerCount = Config.obj().getScenario().getUserId().length;
if (idx < playerCount) {
userId = Config.obj().getScenario().getUserId()[idx];
previousSnoString = userId;
} else if (idx >= playerCount) {
String tempSno = previousSnoString;
int endNumber;
Pattern p = Pattern.compile("[\\D]*[\\d]+$");
Matcher m = p.matcher(tempSno);
Boolean isEndByNumber = false;
while (m.find()) {
isEndByNumber = true;
tempSno = m.group(0);
}
if (isEndByNumber) {
String beforeSno = tempSno.replaceAll("[\\D]", "");
endNumber = Integer.parseInt(beforeSno);
int endNumberLength = Integer.toString(endNumber).length();
endNumber++;
userId = previousSnoString.substring(0, previousSnoString.length() - endNumberLength) + Integer.toString(endNumber);
previousSnoString = userId;
} else {
userId = Integer.toString(idx);
}
}
// TODO : it should changed later
// try {
// previousSno = Long.parseLong(userId);
// } catch (Exception e) {
// //it means, the userId is not Numeric.
// previousSno = playerCount;
// }
String scenarioFile;
int scenarioFileCount = Config.obj().getScenario().getScenarioFile().length;
int recursiveScenarioIdx = idx % scenarioFileCount;
scenarioFile = Config.obj().getScenario().getScenarioFile()[recursiveScenarioIdx];
return new Messages(this.ref, MessageType.PrepareTest, userId, scenarioFile, idx);
}
use of com.nhnent.eat.entity.Messages in project eat by nhnent.
the class TesterActor method doRun.
/**
* doRun of Actor. It performs requests on Actor Mailbox.
*/
@Override
protected Void doRun() throws InterruptedException, SuspendExecution {
TesterActor.globalVariable.set(new HashMap<>());
List<ScenarioUnit> listScenarioPacket = new ArrayList<>();
while (true) {
Object o = receive();
logger.debug("Received testing execute (" + this.ref().toString() + ")");
if (o instanceof Messages) {
Messages m = (Messages) o;
// Handle execute of test preparation
if (m.type == MessageType.PrepareTest) {
userInfo.set(m.userId);
actorIndex = m.actorIndex;
String playerId = String.format("Player_%06d", actorIndex + 1);
MDC.put("playerId", playerId);
MDC.put("strand", Strand.currentStrand().getName());
String logfileName;
if (Config.obj().getCommon().isLoggingOnSameFile()) {
logfileName = String.format("%s", playerId);
} else {
Date now = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
String format = formatter.format(now);
logfileName = String.format("%s_%s", format, playerId);
}
MDC.put("logfileName", logfileName);
logger.debug("Load Scenario [" + m.scenarioFile + "]");
listScenarioPacket.addAll(loadScenario(m.scenarioFile, m.userId));
Messages finishMessage = new Messages(this.ref, MessageType.TestPrepared);
m.sender.send(finishMessage);
}
// Handle execute of test start
if (m.type == MessageType.TestStart) {
ScenarioExecutor scenarioExecutor = new ScenarioExecutor(userId);
StreamPacket.obj().initialize(userId);
scenarioExecutor.addCommunication(new RestCommunication());
scenarioExecutor.addCommunication(new JmxCommunication());
scenarioExecutor.addCommunication(new NettyCommunication(userId, actorIndex));
ScenarioExecutionResult result = scenarioExecutor.runScenario(listScenarioPacket);
listScenarioPacket.clear();
Messages finishMessage = new Messages(this.ref, MessageType.TestFinished);
finishMessage.userId = userId;
finishMessage.scenarioExecutionResult = result;
m.sender.send(finishMessage);
break;
}
} else {
Strand.sleep(1);
}
}
logger.info("Test is finished");
MDC.remove("playerId");
MDC.remove("strand");
MDC.remove("logfileName");
return null;
}
Aggregations