Firefox 3内存占用过大问题-都是隐私数据惹的祸

    使用Firefox近3年时间了,经历了从1.5->2.0->3.0版本的升级,见证了Firefox在功能及性能的逐步完善,尤其是3.0版本在内存占用上有了明显的改善。由于在Profile中存放了大量的扩展的数据及各种隐私数据,因此每一次升级都是先升级Firefox,然后直接拷贝原来profiles文件夹到新的版本中,然后通过firefox.exe -profile "Profiles"参数指定使用的profile。每一次升级都没有遇见太大的问题。最近Firefox由于安全漏洞问题,自动从3.0升级到了3.0.1,升级后发现Firefox内存占用狂大,启动后内存经常占用700多M,CPU占用也经常是100%,导致整个系统速度极其缓慢。

    由于采用安装完成后firefox缺省的profile,内存占用只是在50M,CPU占用也很正常,因此应该是Profile中扩展的问题,开始怀疑是一些扩展升级惹得祸。

1、漫漫调优路

  • 禁用所有的扩展、主题及插件

    直接禁用所有的扩展、主题及插件(尤其是java、Adobe Reader 、flash几个插件),启动后内存占用仍然是700多M,CPU占用也经常是100%.

    看来还不是扩展装得太多或扩展升级后的问题.

  • 调优各种参数

    browser.cache.memory.enable=true

    browser.cache.memory.capacity=18432

    security.enable_java=false 禁用java

    browser.sessionhistory.max_total_viewers=0

    config.trim_on_minimize=true

    同时把DownThemAll及下载历史数据进行了清楚

    调试上述参数后,仍然无效,内存占用和CPU占用也是很大。

  • 安装调优程序

    使用了cache status、firetune几个扩展对内存进行调优,效果也不明显

    让人快疯了,又不想重建profile,然后一个一个把profile中各个扩展的数据重新导入。

    尝试了清空隐私数据操作,把包括Tab Mix Plus 、浏览历史、下载历史、已保存表单和搜索历史、高速缓存、Cookies、脱机网站数据、已保存的密码、已通过验证的会话、DownThemAll!历史和队列所有的数据都进行了清除,Firefox的内存和CPU占用竟然神奇般的恢复了正常。

    看来可能还是这些数据惹得祸,只不过很奇怪的是使用Firefox 3的时候没有出现这样的问题.

  

2、我的Firefox配置

启用扩展: [38]

禁用扩展: [22]

全部扩展: 60
已安装主题: [5]

已安装插件: (7)

  • 2007 Microsoft Office system
  • Adobe Acrobat
  • IE Tab Plug-in
  • Microsoft? DRM
  • Mozilla Default Plug-in
  • Shockwave Flash
  • Windows Media Player Plug-in Dynamic Link Library

 

3、参考资料

http://forums.mozillazine.org/viewtopic.php?t=354828

http://hi.baidu.com/hilyjiang/blog/item/06579e51c4b38c8e8d543078.html

用压缩工具来提高web应用程序效率

    在网站性能优化时候,Yahoo Performance Team的rules for high performance web sites是较好的调优指南(或者yahoo的大牛Steve Souders在其《High Performance Web Sites》书中提出提高网页效率的14条准则),Firefox的插件Firebug及Yahoo提供的Firebug 插件Yslow(http://developer.yahoo.com/yslow/)也是进行性能调优较好的工具。

    按照调优指南,一个重要的原则就是对js、css等文件采用Gzip、deflate等压缩工具进行压缩,以降低网络传输带宽。

1、网页压缩原理

    网页压缩是一项由WEB服务器(应用服务器)和浏览器之间共同遵守的协议,也即WEB服务器(应用服务器)和浏览器都必须支持该技术,现在流行的浏览器(IE、FireFox、Opera )都是支持的;Lighttpd、Apache 、Ngix、 IIS、Tomcat等应用服务器或web服务器都支持。双方的协商过程如下:

  1. 浏览器请求某URL,并在请求的头 (head) 中设置属性 accept-encoding 值为 gzip, deflate,表明浏览器支持 gzip 和 deflate 这两种压缩方式(事实上 deflate 也是使用 gzip 压缩协议);
  2. WEB 服务器接收到请求后判断浏览器是否支持压缩,如果支持就传送压缩后的响应内容,否则传送不经过压缩的内容;
  3. 浏览器获取响应内容后,判断内容是否被压缩,如果是则解压缩,然后显示响应页面的内容。

    具体的交互过程可以利用Livehttpheader来查看http的交互过程。

2、网页压缩的方法

对JS、CSS文件压缩分为两大方面:

  • 对js、CSS采用yuicompressor、JsPacker这样的工具对js等文件进行压缩。主要是删除诸如空行、回车换行、注释等无用的字符,减少文件本身的大小,这也是诸如jquery、prototype等javascript库发布时候所采用的方法。
  • 采用应用服务器(web服务器)及浏览器对gzip、deflate等压缩方法的支持来对请求进行实时的压缩

    在实际应用时候,应当结合两种方法来使用。在大型应用中,会采用lighttpd、apache这样的web服务器来做前端,可以在lighttpd或apache中配置gzip、deflate支持。这里只是简单说明一下采用Jboss对gzip的支持来提高web应用程序的效率

3、修改jboss配置,让其支持gzip压缩

    这里使用jboss 4.2.2,servlet容器采用的是tomcat,因此让jboss支持gzip的配置方法,实际上就是修改tomcat的配置

    修改jboss-4.2.2.GA/server/default/deploy/jboss-web.deployer/server.xml,增加如下内容

    <Connector port=”80″ address=”0.0.0.0″

         maxThreads=”1500″ maxHttpHeaderSize=”8192″

         emptySessionPath=”true” protocol=”HTTP/1.1″

         enableLookups=”false” redirectPort=”8443″ acceptCount=”100″

         connectionTimeout=”20000″ disableUploadTimeout=”true”

         compression=”on”      

         compressableMimeType=”text/html,text/xml,text/plain,text/css,text/javascript,application/xhtml+xml,

         application/x-javascript,application/javascript,text/xhtml”

        />

    在Tomcat与gzip相关的几个参数如下,具体可以参考

http://www.jboss.org/file-access/default/members/jbossweb/freezone/docs/2.1.0/config/printer/http.html

或:

http://tomcat.apache.org/tomcat-5.5-doc/config/http.html

  • compressableMimeType

    The value is a comma separated list of MIME types for which HTTP compression may be used. The default value is text/html,text/xml,text/plain.

  • compression

    The Connector may use HTTP/1.1 GZIP compression in an attempt to save server bandwidth. The acceptable values for the parameter is “off” (disable compression), “on” (allow compression, which causes text data to be compressed), “force” (forces compression in all cases), or a numerical integer value (which is equivalent to “on”, but specifies the minimum amount of data before the output is compressed). If the content-length is not known and compression is set to “on” or more aggressive, the output will also be compressed. If not specified, this attribute is set to “off”.

  • noCompressionUserAgents

  The value is a comma separated list of regular expressions matching user-agents of HTTP clients for which compression should not be used, because these clients, although they do advertise support for the feature, have a broken implementation. The default value is an empty String (regexp matching disabled).

采用gzip压缩后,一个典型例子为struts2中所采用的dojo.js,原来大小为258K,压缩后只有72K,压缩的效果还是很显著的

4、调试

    在web开发时候firefox提供了比IE等浏览器更好的web开发工具

    Firebug:http://www.getfirebug.com/

    Yslow:http://developer.yahoo.com/yslow

    Livehttpheader:http://livehttpheaders.mozdev.org/

    Web Developer: http://chrispederick.com/work/web-developer/

4.1、采用Yslow查看对网站的建议

yslow

3.2、采用Firebug参看页面交互情况

firebug

另外今天是Firefox3正式发布的日子,下载支持一下,感谢Firefox提供了如此好的工具。

在Ubuntu上使用Xvfb或vncserver抓取网页画面制作thumbnail

1、安装xvfb或vncserver

apt-get install xvfb

apt-get install vncserver xvncviewer

不用两个都安装,xvfb和vncserver都能够在没有安装X-Windows的情况下,提供X终端服务。可以只安装其中一个,建议安装vncserver,以可以通过诸如tightvnc之类的客户端进行管理。因此就不暂时测试xvfb方式,有空再试验。

2、安装imagemagick

apt-get install imagemagick

3、创建firefox 制作thumbnail时候使用的profile,避免已安装extension的干扰。

firefox -CreateProfile Screenshot

关于firefox的command line,可以参考:

http://kb.mozillazine.org/Command_line_arguments

4、生成thumbnail

vncserver -geometry 1024×768 -depth 24

#DISPLAY=:1 firefox -P "Screenshot" &

DISPLAY=:1 firefox -P "Screenshot"  -new-window http://www.yeeach.com &

DISPLAY=:1 import -window root yeeach.png

不知为何使用命令:

DISPLAY=:1 firefox -P "Screenshot" -remote "openurl(javascript:window.open(’http://www.yeeach.com/‘,”,’fullscreen=yes,toolbar=no,width=1024,height=768′))"始终报错:

Error: No running window found

因此DISPLAY=:1 firefox -P "Screenshot" &  实际上没有起作用,因此注释掉,等有空时候再具体研究原因。

5、为了方便测试,可以首先清除掉X11相关的lock文件和进程

rm -rf /tmp/.X11-unix/* ;rm -rf /tmp/.X*lock

ps -ef|grep X|grep -v grep |awk ‘{print $2 }’ |xargs kill -9

 

5、总结:

  • 采用此种方式如果处理过程中,如果出现非正常关闭的情况,firefox打开时候会提示“恢复上次会话”的提示,因此可能导致抓取页面不成功,比较烦人。可以采用的解决方案:

    a、修改配置参数browser.startup.page,关掉firefox的崩溃恢复提示机制。
      推荐设置为 3。firefox 会恢复崩溃时的会话页面,但是正常关闭时,你可能也需要上次的那些会话页面

      0 启动打开 about:blank 空页面

      1 启动打开homepage 主页面

      2 启动打开上次最后关闭时的页面

      3 启动打开上次最后会话的那些页面

    b、采用Tab Mix PlusSessionPage 扩展设置

googledotcom

  • 此种方法实际上是利用了imagemagick抓屏的功能,抓取用firefox打开页面的thumbnail,尽管可以利用imagemagick裁剪不需要的区域,相对于诸如page saver或screengrab的方案或基于gecko的方案还是比较不是很精准,尤其是不能滚动完整抓取多屏的页面。
  • 在调试时候,用tightvnc或其他vnc客户端登录终端进行管理还是很方便,能够及时排查出现的问题,这一点比xvfb方便。

6、参考资料

http://kb.mozillazine.org/Command_line_arguments

http://www.semicomplete.com/blog/geekery/xvfb-firefox.html

http://brad.livejournal.com/2015327.html

http://pc90.narc.affrc.go.jp/meng/?p=8

 

Technorati 标签: , , , ,

关于firebug和yslow的资料汇总帖

在“Firebug 及yslow的相关资料”已经有一些相关文档,作为补充,再整理和总结关于firebug的一些相关文档,供查找。

Firebug官方文档

An In-depth Look At The Future of Javascript Debugging With Firebug

Estelle Weyl’s Introduction to Firebug

John Barton’s introduction to the Firebug source(Firebug internals

Firebug Crash Course(slideshare)

Hacking Web 2.0 Applications with Firefox

Hacking Digg With Firebug and jQuery

Firebug Tutorial - Logging, Profiling and CommandLine (Part I)

Firebug Tutorial - Logging, Profiling and CommandLine (Part II)

AJAX Debugging with Firebug

Javascript的调试利器:Firebug使用详解

初识Firebug 全文 — firebug的使用

 

Introduction to YSlow: optimizing your actual and perceived download speed

yahoo developer network YSlow project

rules for high performance web sites

High Performance Websites Lalit Patel(slideshare)

High performance web sites(slideshare)

Using Firebug & YSlow(slideshare)

yahoo yui项目组一哥们的blog

Technorati 标签: , , , ,