Memory and CPU limits for PhantomJS Page? - phantomjs

PhantomJS Page executed in sandbox, but there's still a possibility for infinite loop and memory flooding.
Is there a way to set limits for memory and CPU available for the Page?

Related

what cause vue.js memory leak

Memory leakage occurs in the browser with less memory (448MB). The chrome debugger was used to determine the cause, and the graph of the test is as shown in the image below. It has been confirmed that JS Heap, Nodes, and EventHandler are all reduced at the time of GC. Can the increase in Nodes and EventHandler also cause memory leakage?
Unfortunately, we can't allocate more memory...
The increase in nodes will increase the DOM elements therefore will contribute to the memory leakage. In addition to that there are also other factors that could be a cause for the memory leakage. Please check the below link to get to know the ways how to fix those problems
https://nolanlawson.com/2020/02/19/fixing-memory-leaks-in-web-applications/

Why some GPU micro-benchmarks contain page size for measure global memory access and L1/L2 cache access?

I am trying to run a GPU micro-benchmark to get latency of global memory access and L1/L2 access of Jetson TK1. But in the micro-benchmark, it contains page size as one of parameters when using pointer-chasing code.
Does anyone know why the benchmark include page size when measuring memory access latency?

How to Test Android App Under Low Disk Memory Conditions?

All mobile devices have limited storage options. Therefore, it is imperative for a tester to test an app under low memory conditions. To simulate these conditions, a tester has to fill device memory using dummy files. This is very tedious and time consuming process.
Is there any app or any proper steps to overcome this situation..!!
If you're using emulator to perform test execution have variety of options to control memory availability (both RAM, internal storage and SD card) Just limit the size of the memory type you need to the application size + 5% and you'll get "low memory" environment
There are also other ways already present at Stack Overflow on how to simulate memory shortage. See links below:
How can I force memory pressure for Android debugging?
How do you simulate low memory in the Android emulator?
You can specify the VM Heap parameter when creating the AVD. However, for a real device it doesn't look like you can change the parameters.

How to reduce PhantomJS's CPU and memory usage?

I'm using PhantomJS via Python's webdriver lib. It eats lots of RAM and CPU, and it's an issue because I'd like to run as many instances as it's possible.
Some google'ing didn't give me anything helpful. So I'll ask directly:
Does the size matter? If I set driver.set_window_size(1280, 1024), will it eat more memory than 1024x768?
Is there any option in the source code which can be turned off without real issues and which lead to significant memory usage reduce? Yes I still need images and CSS and JS loading and applying, but I can get rid of some other features... For example, I can turn off caching (and load all media files every time). Yes, I do need to speed it up and make it less greedy and I'm ready to re-compile it... Any ideas here?
Thanks a lot!
I assume you call phantomjs once for every rendering job. This creates a new phantomjs process every time. You could try batching as many as you could in the one js script and call phantomjs once for the whole batch.

Using webkit for headless browsing

I am using webkit based tools to built a headless browser for crawling webpages (I need this because I would like to evaluate the javascript found on pages and fetch the final rendered page). But, the two different systems I have implemented so far exhibit very poor performance. I have implemented two different systems, both of which use webkit as the backend:
Using Google Chrome: I would start Google Chrome and communicate with each tab using webSockets exposed by Chrome for remote debugging (debugging over wire). This way I can control each tab, load a new page and once the page is loaded I fetch the DOM of the loaded webpage.
Using phantomjs: phantomjs uses webkit to load pages and provides a headless browsing option. As explained in the examples of phantomjs, I use page.open to open a new URL and then fetch the dom once the page is loaded by evaluating javascript on the page.
My goal is to crawl pages as fast as I can and if the page does not load in the first 10 seconds, declare it failed and move on. I understand that each page takes a while to load, so to increase the number of pages I load per second, I open many tabs in Chrome or start multiple parallel processes using phantomjs. The following is the performance that I observe:
If I open more than 20 tabs in Chrome / 20 phantomjs instances, the CPU usage rockets up.
Due to the high CPU usage, a lot of pages take more than 10seconds to load and hence I have a higher failure rate (~80% of page load requests failing)
If I intend to keep the fails to less than 5% of the total requests, I cannot load more than 1 URL per second.
After trying out both the webkit based systems, it feels like the performance bottleneck is the webkit rendering engine and hence would like to understand from other users here, the number of URLs per second that I can expect to crawl. My hardware configuration is:
Processor: Intel® Core™ i7-2635QM (1 processor, 4 cores)
Graphics card: AMD Radeon HD 6490M (256MB)
Memory: 4GB
Network bandwidth is good enough to be able to load pages more than the performance that I am observing
The question I am trying to ask this mailing list is, does any one have experience using webkit for crawling web pages for a random set of URLs (say picking 10k URLs from twitter stream), how many URLs can I reasonably expect to crawl per second?
Thanks
This question is actually more related to hardware than the software but let me point you in some better directions anyway.
First, understand that each page is itself spawning multiple threads. It will download the page, and then start spawning off new download threads for elements on the page such as javascript files, css files and images. [Ref: http://blog.marcchung.com/2008/09/05/chromes-process-model-explained.html ]
So depending on how the page is structured, you could end up with a fair number of threads going at the same time just for the page, add on top your trying to do too many loads at once and you have a problem.
The Stack Overflow thread at Optimal number of threads per core gives further information on the situation you are experiencing. Your overloading your cpu.
Your processor is 4 physical 8 logical cores. I would recommend spawning no more than 4 connections at one time, leaving the secondary logical cores to handle some of the threading there. You may find that you even need to reduce this number but 4 is a good starting point. By rendering pages 4 at a time instead of overloading your whole system trying to render 20 you will actually increase your overall speed since you end up with far less cache swapping. Start by clocking your time against several easily timed locations. Then try with less and more. There will be a sweet spot. Note, the headless browser version of PhantomJS is likely going to be better for you as in headless mode it probably won't download the images (a plus).
Your best overall option here though is to do a partial page rendering yourself using the webkit source at http://www.webkit.org/. Since all it seems you need to render is the html and the javascript. This reduces your number of connections and allows you to control your threads with far greater efficiency. You could in that case then create an event queue, spool all your primary url's into there. Spawn off 4 worker threads that all work off of the worker queue, as they process a page and need to download further source they can add those further downloads to the queue. Once all files for a page are downloaded into memory (or disk if your worried about ram) for a particular url, you can then add an item into the event queue to render the page and then parse it for whatever you need.
Depends on what data you are trying to parse, if you only care that javascript and the html , then hypertext query langage would offer an immense speedup, http://htql.net/ , or you can look to setting up something in the cloud such as http://watirmelon.com/2011/08/29/running-your-watir-webdriver-tests-in-the-cloud-for-free/