性能的调优,不可忽视的教训(转)

    有一台服务器,CPU是1G,内存是512M,配置很低了。在上面运行着几个asp的站点,还有一个jboss的应用,此外,在jboss里还运行着一个 xplanner。不过jboss的前端没有apache服务器,用户直接访问jboss。就是这么一个服务器,发现jboss的应用访问的时候特别的 慢。到底是什么原因?

  1.     有可能是程序的问题。
        但是程序在开发环境运行的时候,速度没有任何问题。即使在服务器上,通过log也可以看出来,后台的处理速度
        很快,但是在客户端显示页面却非常慢。
  2.     有可能是服务器性能的问题。
        但是其他的j应用则没有问题。

    经过多次测试发现,程序的处理速度不是问题,问题在于页面显示需要大量的时间。因为在页面中hidden了许多变量,难道是这些hidden变量导致了页 面信息过多,所以显示慢?这也很难成立,因为在许多其他的应用了,hidden的信息更多,也没有这么慢的情况。

    最后,推测可能的原因就是缺少apache的缘故。那么前端为什么需要一个apache?在网上找了一些,又问了许多人,都是仅仅知道一个模糊的概念,没有人从根本上说明为什么大部分的应用都需要在前端放置一个apache。

    不过,个人猜测或许jboss提供的http服务性能太差,而apache可以弥补这一点。不管怎么样,还是先试验一下。按照文档,将jboss 和 apache进行了整合。然后测试速度,结果发现:响应时间提高了很多倍!

    因为之前没有真正地架设过站点,所以一直以为有没有apache这样的web服务器是无所谓的,今天终于发现,区别是如此的大。原因还没有从根本上找到答案,但至少可以确定,application server的http服务,是不能用在产品环境里的。

附录一下 jboss 和  apache整合的文档:

本文介绍在 Win2k 环境下,用 modjk1.2.x 集成 Jboss 、 Tomcat 和 Apache ;文章最后用一 jsp 文件测试了该集成环境。
1.1 主要步骤
下载集成 Tomcat 的 Jboss 、 Apache 和 modjk1.2.x 。
修改 Apache 中的配置文件 httpd.conf 。
在 Apache 中创建新文件 workers.properties 。
在 Apache 中创建新文件 uriworkermap.properties 。
重新启动 Apache 。
修改 Jboss 中的 server.xml 和 jboss-service.xml 文件。
启动 Jboss Application Server 。
1.2 详细说明
1.2.1 软件的下载和安装
本文所用的软件版本为: j2sdk1.4 、 Jboss3.2.7 、 Apache2.0 和 mod_jk-1.2.14 。 jdk 的下载,安装和配置本文不再多说,用过 java 语言的人肯定都知道。
集成 Tomcat 的 Jboss 的下载
http://www.jboss.com/downloads/index 下载 Jboss 。将 Jboss 安装到 c:\javaApp 目录下。
Apache 的下载
http://httpd.apache.org/ 下载 Apache2.0 。将 Apache 安装到 c:\javaApp 目录下。
modjk 的下载
下载 mod_jk 。把 mod_jk-1.2.x.so 文件拷贝到 Apache2\modules 目录下。
1.2.2 httpd.conf文件的修改
打开 Apache2\conf 目录下的 httpd.conf 文件,找到其中的 LoadModule ,然后在 LoadModule 的最后一行,加上下面的代码:
# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk-1.2.14.so
再在 httpd.conf 文件的最后,加上下面的代码:
# Where to find workers.properties
JKWorkersFile conf/workers.properties
# Where to put jk logs
JKLogFile logs/jk.log
# Set the jk log level [debug/error/info]
JKLogLevel normal
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
# JkOptions indicates to send SSK KEY SIZE
#JkOptions+ForwardKeySize+ForwardURICompat-ForwardDirectories
# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"
# Mount your applications
JKMount /web_application/* node1
JkMount /web-console/* node1
JkMount /jmx-console/* node1
# You can use external file for mount points.
# It will be checked for updates each 60 seconds.
# The format of the file is: /url=worker
# /examples/*=loadbalancer
JkMountFile conf/uriworkermap.properties
# Add shared memory.
# This directive is present with 1.2.10 and
# later versions of mod_jk, and is needed for
# for load balancing to work properly
# If there’s no this file under logs directory, create it manually.
JkShmFile logs/jk.shm
# Add jkstatus for managing runtime data
<location></location>
JkMount status
Order deny,allow
Deny from all
Allow from 127.0.0.1
   
1.2.3 创建workers.properties文件
Apache2\conf 目录下创建一新文件 workers.properties ,文件包含下面的内容:
# Define list of workers that will be used
# for mapping requests
worker.list=loadbalancer,status
# Define Node1
worker.node1.port=8009
# You can modify the Ip address to the actual Ip address
worker.node1.host=127.0.0.1
worker.node1.type=ajp13
worker.node1.lbfactor=1
#worker.node1.local_worker=1 (1)
worker.node1.cachesize=10
# Define Node2
worker.node2.port=8009
# You can modify the Ip address to the actual Ip address
worker.node2.host= 127.0.0.1
worker.node2.type=ajp13
worker.node2.lbfactor=1
#worker.node2.local_worker=1 (1)
worker.node2.cachesize=10
# Load-balancing behavior
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1, node2
worker.loadbalancer.sticky_session=1
worker.loadbalancer.local_worker_only=1
worker.list=loadbalancer
# Status worker for managing load balancer
worker.status.type=status
1.2.4 创建uriworkermap.properties文件
Apache2\conf 目录下创建一新文件 uriworkermap.properties ,文件包含下面的内容:
# Simple worker configuration file
# Mount the Servlet context to the ajp13 worker
/jmx-console=loadbalancer
/jmx-console/*=loadbalancer
/web-console=loadbalancer
/web-console/*=loadbalancer
# You should modify the “web_application” to
# the real name of the web application
/ web_application =loadbalancer
/ web_application /*=loadbalancer
做完上面的所有步骤后,重新启动 Apache 。
1.2.5 修改Jboss中的server.xml和jboss-service.xml文件
打开 jboss-3.2.7\server\default\deploy\jbossweb-tomcat50.sar 目录下的 server.xml 文件。
<engine defaulthost="localhost" name="jboss.web"></engine> 修改为:
<engine defaulthost="localhost" name="jboss.web"></engine>
jvmRoute="node1">
因为集成 Apache 后,由 Apache 来处理 Http 请求,所以可以把下面的代码注释掉:
<connector address="${jboss.bind.address}" port="8080"></connector>
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"/>
打开 jboss-3.2.7\server\default\deploy\jbossweb-tomcat50.sar\
META-INF 目录下的 jboss-service.xml 文件。
<attribute name="UseJK">false</attribute> 修改为:
<attribute name="UseJK">true</attribute>
启动 Jboss ,在 IE 浏览器中输入 http://127.0.0.1/web-console ,如果配置成功,将显示 Jboss 的 web 管理页面。
1.3 测试jsp文件
jboss-3.2.7\server\default\deploy 目录下新建一个 helloworld 目录,然后在 helloworld 目录下新建一个 hello.war 目录。在 hello.war 目录下创建一个 test.jsp 文件,文件代码如下:
<%
String helloworld = "Hello world!";
out.println(helloworld);
%>
修改 uriworkermap.properties 文件,添加下面的代码:
/hello=loadbalancer
/hello/*=loadbalancer
修改 httpd.conf 文件,添加下面的代码:
JKMount /hello/* node1
打开IE,输入 http://127.0.0.1/hello/test.jsp ,页面将显示出
Hello world!

作者:蔡晓均
E-mail 地址: neptunecai@yahoo.com.cn
版权所有,转摘请注明:摘自 www.blogjava.net/neptune
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值