Search in sources :

Example 1 with ReportHandler

use of com.nhnent.eat.handler.ReportHandler 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)

Aggregations

ActorRef (co.paralleluniverse.actors.ActorRef)1 Messages (com.nhnent.eat.entity.Messages)1 ScenarioExecutionResult (com.nhnent.eat.entity.ScenarioExecutionResult)1 ReportHandler (com.nhnent.eat.handler.ReportHandler)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1