Search in sources :

Example 1 with ScenarioExecutionResult

use of com.nhnent.eat.entity.ScenarioExecutionResult in project eat by nhnent.

the class ReportHandler method writeFinalStatisticsResult.

public final void writeFinalStatisticsResult(ScenarioExecutionResult[] results) {
    if (!Config.obj().getDisplay().isDisplayFinalStatisticResult()) {
        return;
    }
    NumberFormat formatter = new DecimalFormat("#0.00");
    Double mean, standardDeviation;
    Double median = 0.0, maxValue = 0.0, minValue = 1000000.0;
    Double sumOfMean = 0.0, sumOfStandardOfDeviation = 0.0;
    int countOfResult = 0;
    for (ScenarioExecutionResult result : results) {
        if (result.statisticsResult != null) {
            countOfResult++;
            sumOfMean += result.statisticsResult.mean;
            sumOfStandardOfDeviation += result.statisticsResult.standardDeviation;
            if (minValue > result.statisticsResult.minValue) {
                minValue = result.statisticsResult.minValue;
            }
            if (maxValue < result.statisticsResult.maxValue) {
                maxValue = result.statisticsResult.maxValue;
            }
        }
    }
    median = (maxValue + minValue) / 2;
    mean = sumOfMean / countOfResult;
    standardDeviation = sumOfStandardOfDeviation / countOfResult;
    logger.info("\n<======== FINAL STATISTICS RESULT (of response time)" + " result ========>");
    logger.info("(Mean) response time(ms) : " + formatter.format(mean));
    logger.info("(Standard Deviation) response time(ms) : " + formatter.format(standardDeviation));
    logger.info("(Median) response time(ms) : " + formatter.format(median));
    logger.info("(Max) response time(ms) : " + formatter.format(maxValue));
    logger.info("(Min) response time(ms) : " + formatter.format(minValue));
}
Also used : DecimalFormat(java.text.DecimalFormat) ScenarioExecutionResult(com.nhnent.eat.entity.ScenarioExecutionResult) NumberFormat(java.text.NumberFormat)

Example 2 with ScenarioExecutionResult

use of com.nhnent.eat.entity.ScenarioExecutionResult 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;
}
Also used : Messages(com.nhnent.eat.entity.Messages) ActorRef(co.paralleluniverse.actors.ActorRef) ScenarioExecutionResult(com.nhnent.eat.entity.ScenarioExecutionResult) ReportHandler(com.nhnent.eat.handler.ReportHandler) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with ScenarioExecutionResult

use of com.nhnent.eat.entity.ScenarioExecutionResult 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;
}
Also used : ScenarioUnit(com.nhnent.eat.entity.ScenarioUnit) Messages(com.nhnent.eat.entity.Messages) ScenarioExecutor(com.nhnent.eat.handler.ScenarioExecutor) ArrayList(java.util.ArrayList) RestCommunication(com.nhnent.eat.communication.communicator.RestCommunication) Date(java.util.Date) NettyCommunication(com.nhnent.eat.communication.communicator.NettyCommunication) JmxCommunication(com.nhnent.eat.communication.communicator.JmxCommunication) ScenarioExecutionResult(com.nhnent.eat.entity.ScenarioExecutionResult) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ScenarioExecutionResult (com.nhnent.eat.entity.ScenarioExecutionResult)3 Messages (com.nhnent.eat.entity.Messages)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 ActorRef (co.paralleluniverse.actors.ActorRef)1 JmxCommunication (com.nhnent.eat.communication.communicator.JmxCommunication)1 NettyCommunication (com.nhnent.eat.communication.communicator.NettyCommunication)1 RestCommunication (com.nhnent.eat.communication.communicator.RestCommunication)1 ScenarioUnit (com.nhnent.eat.entity.ScenarioUnit)1 ReportHandler (com.nhnent.eat.handler.ReportHandler)1 ScenarioExecutor (com.nhnent.eat.handler.ScenarioExecutor)1 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 ArrayList (java.util.ArrayList)1