Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Growing node.exe memory #9

Closed
nocelab opened this issue Feb 11, 2022 · 6 comments
Closed

Growing node.exe memory #9

nocelab opened this issue Feb 11, 2022 · 6 comments

Comments

@nocelab
Copy link
Contributor

nocelab commented Feb 11, 2022

Hi, in Windows machine I'm testing a loop with 2 load method with Playwright browser and I note that the process node.exe still grow without ever release.
Is it correct? Is there some trick to release it?

@Osiris-Team
Copy link
Owner

@nocelab can you share the code? I didnt notice anything like that when testing.

@nocelab
Copy link
Contributor Author

nocelab commented Feb 11, 2022

this is sample code (Windows 10 with OpenJDK 8u222-b10):

HBrowser hBrowser = new HBrowser();
PlaywrightWindow hb = hBrowser.openCustomWindow().headless(false).buildPlaywrightWindow();

for (int i = 0; i < 100; i++) {
    hb.load("www.google.it");
    hb.fill("[aria-label=\"Cerca\"]", "searching something");
    hb.holdKey("Tab");
    // click and wait...
    hb.getJsContext().executeJavaScript(""+
            "await Promise.all([\n"+
            " page.click(':nth-match(:text(\"Cerca con Google\"), 2)'),\n"+
            " page.waitForNavigation()\n"+
            "]);");
    System.out.println(hb.getOuterHtml().text());
}
hb.close();

and this is memory graph of node.exe process:

image

@Osiris-Team
Copy link
Owner

Ok I tested this code first just to make sure node was working fine by default:

HBrowser hBrowser = new HBrowser();
        try(PlaywrightWindow window = hBrowser.openWindow()){
            window.load("www.google.com");
            System.out.println("Loaded page! Exit the program once finished with ram analysis...");
            while (true)
                Thread.sleep(1000);
        } catch (NodeJsCodeException | InterruptedException e) {
            e.printStackTrace();
        }

image
And it looks good since the node.exe uses only a steady amount of 31mb.

Then I tested your code (slightly modified):

HBrowser hBrowser = new HBrowser();
        try(PlaywrightWindow window = hBrowser.openCustomWindow().headless(false).buildPlaywrightWindow()){
            for (int i = 0; i < 100; i++) {
                window.load("www.google.it");
                window.fill("[aria-label=\"Cerca\"]", "searching something");
                window.holdKey("Tab");
                // click and wait...
                window.getJsContext().executeJavaScript(""+
                        "await Promise.all([\n"+
                        " page.click(':nth-match(:text(\"Cerca con Google\"), 2)'),\n"+
                        " page.waitForNavigation()\n"+
                        "]);");
                System.out.println("Run: "+i);
            }
        } catch (NodeJsCodeException e) {
            e.printStackTrace();
        }

Your code throws following exception:

com.osiris.headlessbrowser.exceptions.NodeJsCodeException: Error during JavaScript code execution! Details: 
CAUGHT JS-EXCEPTION: TimeoutError
MESSAGE: page.fill: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for selector "[aria-label="Cerca"]"
============================================================
LINE: undefined
STACK: page.fill: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for selector "[aria-label="Cerca"]"
============================================================
    at REPL12:2:12
    at REPL12:8:4


	at com.osiris.headlessbrowser.js.contexts.NodeContext.executeJavaScript(NodeContext.java:383)
	at com.osiris.headlessbrowser.js.contexts.NodeContext.executeJavaScript(NodeContext.java:304)
	at com.osiris.headlessbrowser.windows.PlaywrightWindow.fill(PlaywrightWindow.java:711)
	at com.osiris.headlessbrowser.windows.PlaywrightWindow.fill(PlaywrightWindow.java:681)
	at com.osiris.headlessbrowser.issues.Issue9.main(Issue9.java:13)

Process finished with exit code 0

Thus I wasn't able to see the same increase in memory as you since it aborts. Maybe the missing try/catch was somehow your issue?

@nocelab
Copy link
Contributor Author

nocelab commented Feb 11, 2022

In my sample nothing goes in exception.
You have to adapt my code with your google.com right localized labels... this graph with your try/catch code:

image

@Osiris-Team
Copy link
Owner

image
Yeah was able to run your code successfully with the same results.
Looked at the java and js code of headless browser and there don't seem to be memory leaks.
I guess its playwright storing the previously loaded pages to allow back and forth navigation.

@nocelab
Copy link
Contributor Author

nocelab commented Feb 14, 2022

Ok... I'am happy!
You are right, perhaps something like microsoft/playwright#6319.
I will deepen with Playwright... thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants