在ruby中启动时,播放启动进程运行高CPU

时间:2013-12-30 16:17:35

标签: ruby scala playframework playframework-2.0 cpu-usage

我在玩游戏!在Ubuntu上使用2.1.1(使用Java 1.7.0_45和Scala 2.10.0)。

它只是直接击中100%,我的猜测是与stdout / stdin / stderr或类似的东西有关,但我不确定。

然后在使用该东西时,我会在应用程序日志中等待两分钟:

2013-12-30 15:53:44,942 - [INFO] - from application in play-akka.actor.default-dispatcher-2
Formed query 'DELETE FROM MatchPlayer WHERE mp_id='17';'

2013-12-30 15:55:44,735 - [INFO] - from application in play-akka.actor.default-dispatcher-2 
Asked to delete from table MatchPlayer with id 18

以下是用于启动它的ruby代码:

TestServer::start_and_wait(TestConfig::SERVER_PORT)

def TestServer.start_and_wait(port)
    start(port)
    #wait_for_start()
end

def TestServer.start(port)

    # Play blocks, so start this on a new thread
    thread = Thread.new do
    TestConfig.get_logger.info("Starting server on port #{port}")
    output = Util::Process::run_command("play \"start #{port}\"", true)

end

def Process.run_command(command, verbose = false)

    logger = TestConfig::get_logger

    if(verbose)
        logger.info("Ran command '#{command}'")
    end

    Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|

        # We don't need stdin
        stdin.close

        # Wait for process to finish and then grab stdout, stderr
        out = stdout.gets
        err = stderr.gets

        stdout.close
        stderr.close

        rc = wait_thr.value.exitstatus

        if(verbose)
            logger.info("Stdout was: \n")
            logger.info("#{out}\n")
            logger.info("Stderr was: \n")
            logger.info("#{err}\n")
            logger.info("Return code was '#{rc}'")
        end

        return ProcessResult.new(command, out, err, rc)

    end

end

0 个答案:

没有答案