1

マルチスレッド実行でマップタスクから実行する次のメソッドがありますが、これはスタンドアロンモードでは正常に機能しますが、Hadoop YARN でこれを実行すると、1GB の物理メモリが不足し、仮想メモリもシュートします上。

プログラミングの観点から間違ったことをしているかどうかを知る必要があります。開いているすべてのストリームをできるだけ早く閉じていると思うので、メモリ リークが発生する理由はわかりません。お知らせ下さい。

ありがとう。

public static void manageTheCurrentURL(String url) {

logger.trace("Entering the method manageTheCurrentURL ");

InputStream stream = null;
InputStream is = null;
ByteArrayOutputStream out = null;
WebDriver driver = null;
try {

    if (StringUtils.isNotBlank(url)) {

        caps.setJavascriptEnabled(true); // not really needed: JS
                                            // enabled by default
        caps.setCapability(
                PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                "/usr/local/bin/phantomjs");

        // Launch driver (will take care and ownership of the phantomjs
        // process)
        driver = new PhantomJSDriver(caps);
        driver.get(url);
        String htmlContent = driver.getPageSource();

        if (htmlContent != null) {

            is = new ByteArrayInputStream(htmlContent.getBytes());

            ByteArrayDocumentSource byteArrayDocumentSource = new ByteArrayDocumentSource(
                    is, url, "text/html");

            Any23 runner = new Any23();
            runner.setHTTPUserAgent("test-user-agent");

            out = new ByteArrayOutputStream();
            TripleHandler handler = new NTriplesWriter(out);

            try {
                runner.extract(byteArrayDocumentSource, handler);
            } catch (ExtractionException e) {


            } finally {

                if (driver != null) {
                    driver.quit();
                    //driver.close();
                }

                try {
                    handler.close();

                } catch (TripleHandlerException e) {

                }
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException e) {
                    }
                }

            }

            if (out != null) {

                stream = new ByteArrayInputStream(out.toByteArray());
                Iterator<Node[]> it = new DeltaParser(stream);
                if (it != null) {

                    SolrCallbackForNXParser callback = new SolrCallbackForNXParser(
                            url);
                    callback.startStory();

                    while (it.hasNext()) {
                        Node[] abc = it.next();
                        callback.processStory(abc);
                    }

                    callback.endStory();
                }
            }

        }

    }

} catch (IOException e) {
    return;
}

finally {

    if (stream != null) {
        try {
            stream.close();
        } catch (IOException e) {
        }
    }
    if (out != null) {
        try {
            out.close();
        } catch (IOException e) {
        }

    }
}

logger.trace("Exiting the method manageTheCurrentURL ");

}

4

0 に答える 0