Monday, January 14, 2008
special effect for scrolling and layered display like large image browsing
Saturday, December 1, 2007
apache+tomcat+mysql 的负载平衡和集群技术.
公司开发了一个网站,估计最高在线人数是3万,并发人数最多100人。开发的网站是否能否承受这个压力,如何确保网站的负荷没有问题,经过研究决定如下:
(1) 采用负载平衡和集群技术,初步机构采用Apache+Tomcat的机群技术。
(2) 采用压力测试工具,测试压力。工具是Loadrunner。
硬件环境搭建:
为了能够进行压力测试,需要搭建一个环境。刚开始时,测试在公司局域网内进行,但很快发现了一个问题,即一个脚本的压力测试结果每次都不一样,并且差别很大。原来是受公司网络的影响,于是决定搭建一个完全隔离的局域网测试。搭建后的局域网配置如下:
(1) 网络速度:100M
(2) 三台服务器:
负载服务器 :操作系统windows2003,
Tomcat服务器:操作系统windows2000 Professional
数据库服务器:操作系统windows2000 Professional
三台机器的cpu 2.4 G, 内存 1G。
软件环境搭建:
软件的版本如下:
Apache 版本:2.054,
Tomcat5.0.30,
mysql :4.1.14.
JDK1.5
压力测试工具:Loadrunner7.8。
负载平衡方案如下:
一台机器(操作系统2003)安装apache,作为负载服务器,并安装tomcat作为一个worker;一个单独安装tomcat,作为第二个worker;剩下的一台单独作为数据库服务器。
Apache和tomcat的负载平衡采用JK1.2.14(没有采用2.0,主要是2.0不再维护了)。
集群方案:
采用Tomcat本身的集群方案。在server.xml配置。
压力测试问题:
压力测试后,发现了一些问题,现一一列出来:
(1) 采用Tocmat集群后,速度变得很慢。因为集群后,要进行session复制,导致速度较慢。Tomcatd的复制,目前不支持 application复制。复制的作用,主要用来容错的,即一台机器有故障后,apache可以把请求自动转发到另外一个机器。在容错和速度的考虑上, 我们最终选择速度,去掉了Tomcat集群。
(2) 操作系统最大并发用户的限制:
为了采用网站的压力,我们开始的时候,仅测试Tomcat的最大负载数。Tomcat服务器安装的操作系统是 windows2000 Professional。当我们用压力测试工具,并发测试时,发现只要超过15个并发用户,会经常出现无法连接服务器的情况。 经过研究,发现是操作系统的问题:windows2000 Professional 支持的并发访问用户有限,默认的好像是15个。于是我们把操作系统 全部采用windows2003 server版本。
(3) 数据库连接池的问题:
测试数据库连接性能时,发现数据库连接速度很慢。每增加一些用户,连接性能就差了很多。我们采用的数据库连接池是DBCP,默认的初始化为50 个,应该不会很慢吧。查询数据库的连接数,发现初始化,只初始化一个连接。并发增加一个用户时,程序就会重新创建一个连接,导致连接很慢。原因就在这里 了。如何解决呢?偶尔在JDK1.4下的Tomcat5.0.30下执行数据库连接压力测试,发现速度很快,程序创建数据库连接的速度也是很快的。看来 JDK1.5的JDBC驱动程序有问题。于是我们修改 JDK的版本为1.4.
(4) C3P0和DBCP
C3P0是Hibernate3.0默认的自带数据库连接池,DBCP是Apache开发的数据库连接池。我们对这两种连接池进行压力测试对比,发现在并发300个用户以下时,DBCP比C3P0平均时间快1秒左右。但在并发400个用户时,两者差不多。
速度上虽然DBCP比C3P0快些,但是有BUG:当DBCP建立的数据库连接,因为某种原因断掉后,DBCP将不会再重新创建新的连接,导致必须重新启动Tomcat才能解决问题。DBCP的BUG使我们决定采用C3P0作为数据库连接池。
调整后的方案:
操作系统Windows2003 server版本
JDK1.4
Tomcat 5.0.30
数据库连接池C3P0
仅采用负载平衡,不采用集群。
软件的配置:
Apache配置:主要配置httpd.conf和新增加的文件workers.properties
Httpd.conf:
#一个连接的最大请求数量
MaxKeepAliveRequests 10000
#NT环境,只能配置这个参数来提供性能
#每个进程的线程数,最大1920。NT只启动父子两个进程,不能设置启动多个进程
ThreadsPerChild 1900
每个子进程能够处理的最大请求数
MaxRequestsPerChild 10000
# 加载mod_jk
#
LoadModule jk_module modules/mod_jk.so
#
# 配置mod_jk
#
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
#请求分发,对jsp文件,.do等动态请求交由tomcat处理
DocumentRoot "C:/Apache/htdocs"
JkMount /*.jsp loadbalancer
JkMount /*.do loadbalancer
JkMount /servlet/* loadbalancer
#关掉主机Lookup,如果为on,很影响性能,可以有10多秒钟的延迟。
HostnameLookups Off
#缓存配置
LoadModule cache_module modules/mod_cache.so
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so
CacheForceCompletion 100
CacheDefaultExpire 3600
CacheMaxExpire 86400
CacheLastModifiedFactor 0.1
CacheEnable disk /
CacheRoot c:/cacheroot
CacheSize 327680
CacheDirLength 4
CacheDirLevels 5
CacheGcInterval 4
CacheEnable mem /
MCacheSize 8192
MCacheMaxObjectCount 10000
MCacheMinObjectSize 1
MCacheMaxObjectSize 51200
worker. Properties文件
#
# workers.properties ,可以参考
http://jakarta.apache.org/tomcat/connectors-doc/config/workers.html
# In Unix, we use forward slashes:
ps=
# list the workers by name
worker.list=tomcat1, tomcat2, loadbalancer
# ------------------------
# First tomcat server
# ------------------------
worker.tomcat1.port=8009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
# Specify the size of the open connection cache.
#worker.tomcat1.cachesize
#
# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
# ----> lbfactor must be > 0
# ----> Low lbfactor means less work done by the worker.
worker.tomcat1.lbfactor=900
# ------------------------
# Second tomcat server
# ------------------------
worker.tomcat1.port=8009
worker.tomcat1.host=202.88.8.101
worker.tomcat1.type=ajp13
# Specify the size of the open connection cache.
#worker.tomcat1.cachesize
#
# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
# ----> lbfactor must be > 0
# ----> Low lbfactor means less work done by the worker.
worker.tomcat1.lbfactor=2000
# ------------------------
# Load Balancer worker
# ------------------------
#
# The loadbalancer (type lb) worker performs weighted round-robin
# load balancing with sticky sessions.
# Note:
# ----> If a worker dies, the load balancer will check its state
# once in a while. Until then all work is redirected to peer
# worker.
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcat1,tomcat2
#
# END workers.properties
#
Tomcat1配置:
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" />
enableLookups="false" redirectPort="8443" debug="0"
protocol="AJP/1.3" />
启动内存配置,开发configure tomcat程序即可配置:
Initial memory pool: 200 M
Maxinum memory pool:300M
Tomcat2配置:
配置和tomcat1差不多,需要改动的地方如下:
启动内存配置,开发configure tomcat程序即可配置:
Initial memory pool: 512 M
Maxinum memory pool:768M
Mysql配置:
Server类型:Dedicated MySQL Server Machine
Database usage:Transational Database Only
并发连接数量:Online Transaction Processing(OLTP)
字符集:UTF8
数据库连接池的配置:
我们采用的是spring 框架,配置如下:
Monday, November 12, 2007
Why Dojo 1.0 Matters - Ajax Now Enterprise-Ready
You can't swing a dead cat at a Web 2.0 conference these days without hitting a dozen Rich Internet Application (RIA) toolkits. The Olliance Group recently identified 58 RIA products, many of them either proprietary or incompatible with the other 57 approaches.
Just to set the stage, here is my personal definition for a Rich Internet Application:
"Rich Internet Applications match the responsiveness of traditional desktop apps by minimizing web page refreshes. RIA taps into the collective power of the Internet to supply widgets and services for building web clients, like rss feeds, Google maps and Youtube. The goal of RIA is not merely to emulate a PC GUI in a browser (aka the Silverlight sell-out), but to deliver browser-based clients which far outperform PC GUIs in speed and functionality."
Ajax* is a particular architecture for building RIAs that is favored by open source libraries such as Dojo, Jquery, Ext and dozens of others. The perpetual flamewars between adherents of the various Ajax toolkits is a huge gift for the proprietary RIA products like Microsoft Silverlight and Adobe Flex.
Many Ajax toolkits seem more focused on posting esoteric animated graphics widgets to the Ajaxian web site than they are on meeting mundane but critical enterprise needs. To be fair, whizzy graphics are an important element of RIA's appeal. However there are more fundamental concerns to address before RIA can be considered enterprise-ready.
Into this maelstrom of splintered efforts comes the Dojo 1.0 release. Dojo has been in development for 3 years, making it one of the more mature toolkits available. Dojo also has the backing of IBM, BEA and Sun and will ship standard with their Java servers.
Previous versions of Dojo were criticized as being too big and too slow. Dojo 1.0 attempts to address those issues. Even more importantly, Dojo has also addressed a number of the hard issues required to gain enterprise adoption:
- Internationalization and accessibility: Dojo supports localization, keyboard navigation and vision-impaired users, making it appropriate for both global businesses and government applications.
- Excellent data handling: the Dojo grid (plug: built by ActiveGrid's own Scott Miles and Steve Orvell) easily handles 100,000+ rows with dynamic loading and complex rows, making it suitable for building the most data-intensive web clients.
- Interoperability: Dojo supports the OpenAjax hub, making it possible for an enterprise to integrate and support web applications built with different Ajax toolkits.
- Corporate look and feel: Dojo supports the ability to define a corporate look and feel or skin that can be used across a set of applications.
Saturday, October 6, 2007
JSF & Portlet
Option 1: MyFacesGenericPortlet
Make sure your JSF MyFaces application runs as a stand-alone servlet.
Remove any redirects from your faces-config.xml. Portlets can not handle these.
Create a Portlet WAR as per the instructions for your Portlet container. Make sure it contains everything that was included in step 1.
Update your portlet.xml file as follows:
DWR 简化 Ajax 的 portlet 间通信
许多开发人员都期待着利用 Ajax 技术来提高基于 Web 的应用程序的用户体验,但是 Ajax 编程可能是一项麻烦的任务。开放源码的 Direct Web Remoting (DWR) 库通过自动把 Java 类转换成 JavaScript 类,可以为 Java™ 开发人员简化 Ajax 开发。在这篇文章中,将学习如何用 DWR 和符合 JSR-168 规范的 portlet 迅速而容易地构建 Ajax 应用程序。
Portlet 是基于 Java 平台的 Web 门户应用程序。JSR-168 是开发 portlet 应用程序的 Java Community Process 标准,它描述了 portlet 生命周期管理、portlet 容器合约、打包、部署以及与门户有关的其他方面。
异步 JavaScript + XML(或者叫做 Ajax)是一项用于开发丰富、交互的 Web 应用程序的技术。Ajax 组合了 XML、HTML、DHTML、JavaScript 和 DOM。
Portlet 和 Ajax 看起来彼此之间是完美搭配,因为它们都侧重于用 Web 浏览器作为向用户呈现用户界面的工具。把这两者与 Java 技术组合在一起的简易方式就是使用 DWR 库。DWR 是 Apache 许可下的开放源码 Java 库,用于构建基于 Ajax 的 Web 应用程序。DWR 的基本目的是向开发人员隐藏 Ajax 的细节。您在服务器端使用普通 Java 对象(POJO),而 DWR 动态地生成 JavaScript 代理函数,所以使用 JavaScript 的客户端开发感觉起来就像直接调用 JavaBean。DWR 的主要组件是一个 Java servlet,处理从浏览器到服务器的调用。
本文使用 DWR、基于三个 portlet 来构建一个示例 Ajax 应用程序。我将介绍如何把 DWR 与 porlet 应用程序集成,但是我不想深入 DWR 的幕后工作细节;在这个项目的 Web 站点和 developerWorks 的页面上(请参阅 参考资料 获得细节)可以找到关于这个库的更多信息。要构建我描述的应用程序,需要 1.3 或以后版本的 Java 平台和符合 JSR-168 规范的的门户环境。我用来开发和测试这个代码的环境包含 IBM Rational Application Developer V6.0、Apache Jetspeed 2.0 portal 和 Java 5.0。
Monday, September 24, 2007
Sysdeo Tomcat PlugIn
我使用的是Tomcat5 ,插件的版本与Eclipse的版本是否匹配.在开发时,一定要注意 Eclipse的版本与对应的插件版本是否支持。否则造成意外无法启动。我在开发中有一次用Eclipse3.1使Tomcat3插件,出现很多意想不到 的原因,也找不到原因。最后更换为Tomcat3.1问题解决。可见插件的版本是否被Eclipse支持十重要要。
1.tomcat version (选择相应的Tomcat版本)
2.tomcat home (通过Browse选择在本地安装了的Tomcat的路径)
3.Context declaration Mode(选择Context声明的类型,1.如果选择server.xml,则新建Tomcat工程后,会自动在Server.xml文件中添加 Context属性.2.如果选择Context files,则会单独新建一个xml文件,这个文件中只有Context属性,并且自动以工程的名字命名这个文件)
1.Server.xml 将Context属性加入到 %TomcatHome%\conf\server.xml文件中
2.Context files 单独以工程名字建立一个XML文件,project.xml放置在%TomcatHome%\conf\\Catalina\localhost目录下文件只有
Context属性.
3.部署Web应用
1.拷贝war文件或Web应用文件夹至%Tomcat_Home%/server/webapps/目录下
2.为Web服务建立一个只包括Context内容的XML文件放置在%Tomcat_Home%/server/webapps/目录下,这时Web应用可以放置在硬盘的任何地方
4.Tomcat限制特定主机访问
deny="" />
5.Eclipse中新建一个Tomcat工程,会自动根据你在Eclipse配置Tomcat的属性
1,在%Tomcat_Home%/conf/server.xml中增加
或者
2.Tomcat_Home%/conf/Catalina/localhost目录下新建一个以工程名字的XMl文件且其中只有
Friday, September 7, 2007
“Don’t Waste Time” with Graphical Ajax Solutions
ZDNet’s Ryan Stewart argues against performing interactive graphics with Ajax (i.e. standard web technologies). The article relates to my post on different techniques for graphics with Ajax (covered on Ajaxian).
Michael responds that the main argument against Flash is the user base, then goes on to list the plusses and minuses of "richer plugins".
You simply should not be trying to create a rich, graphical experience in Ajax. The options (SVG, Canvas, VML, ect) are buggy, supported in different ways depending on the browser, and, for the most part, are a poor experience for both users and developers.
The kind of rich interactivity that Flash and Windows Presentation Foundation provide are going to be leaps and bounds ahead of what any browser technology can do, and that's why they will succeed. The web becomes richer every day. Video and Music are taking the web by storm, and with the surge in broadband adoption, people are making these things part of their every day web experience. Ajax applications can't take advantage of them in the way the Flash or WPF can.
Flash (more generally, Richer Plugins) was actualy one of the graphics techniques mentioned in the original article. It’s all about trade-offs. I’ve actually argued myself that Ajax developers ought to take Flash more seriously, as it’s an excellent complement to Ajax. Flash sometimes makes a nice sweet spot - with graphics and multimedia closer to that of the desktop than standard DHTML/Ajax, but still living in a web platform that’s often more convenient than the desktop. The two monster apps of the past 12-18 months, YouTube and MySpace, demonstrate the power of Flash and multimedia on the web.
The benefits of Flash over Ajax are self-evident and undeniable, but Flash comes with its own set of problems too - not every user has Flash installed, not every user has the latest version, not every network allows Flash applications to run, not every developer and company wants to commit to proprietary technology when viable alternatives are available. Ajax apps tend to be easier to degrade gracefully as well; Flash is more all-or-none.
What if I want to introduce a histogram to an Ajax enterprise app? I’ll happily use a DOM/CSS library like CSS Graphs. Or if I’m writing a Firefox extension, I might use a data: resource to create a whimpy graphic since I no longer care about portability or even extravagant display. Maybe I want a 16×16 heatmap next to each search result - I’ll draw it with a Canvas and keep all the search results in standard HTML. And so on. See? Competent developers don’t engage in dogmatic battles, because they know software is all about trade-offs. Many times, Flash wins. Many times, it loses.
Last word goes to Ryan:
Don’t waste time trying to build the next generation of the web with graphical Ajax solutions … you already have a solution, and it’s getting more robust by the day. As your web applications start to require a more rich environment, embrace Rich Internet Applications - you’ll be better off.