如何减少PhantomJS的CPU和内存使用量? [英] How to reduce PhantomJS's CPU and memory usage?

查看:338
本文介绍了如何减少PhantomJS的CPU和内存使用量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Python的webdriver lib使用PhantomJS.它占用大量RAM和CPU,这是一个问题,因为我想尽可能多地运行实例.

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.

有些googleing并没有给我任何帮助.所以我直接问:

Some google'ing didn't give me anything helpful. So I'll ask directly:

  1. 大小重要吗?如果我设置driver.set_window_size(1280,1024),它会比1024x768占用更多的内存吗?

  1. Does the size matter? If I set driver.set_window_size(1280, 1024), will it eat more memory than 1024x768?

源代码中是否有任何选项可以在没有实际问题的情况下被关闭,从而导致显着减少内存使用?是的,我仍然需要图像以及CSS和JS的加载和应用程序,但是我可以摆脱一些其他功能...例如,我可以关闭缓存(并每次加载所有媒体文件).是的,我确实需要加快速度并使它减少贪婪,并且我准备好重新编译它了……这里有什么想法吗?

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?

非常感谢!

推荐答案

我假设您为每个渲染作业调用一次phantomjs.每次都会创建一个新的phantomjs进程.您可以尝试在一个js脚本中进行尽可能多的批处理,然后为整个批处理调用一次phantomjs.

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.

这篇关于如何减少PhantomJS的CPU和内存使用量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆