首页 / 软件开发 / JAVA / 浅析weblogic10 plugin中的DynamicServerList
浅析weblogic10 plugin中的DynamicServerList2011-01-11 BlogJava 走走停停又三年几乎所有使用weblogic的大一点的企业环境中,都会使用到cluster, 使用cluster势必要采用proxy, proxy有很多,apache, iis及weblogic提供的HttpClusterServlet。plugin的配置参数有很多,可参考下面的链接,http://e-docs.bea.com/wls/docs92/plugins/plugin_params.html#wp1157622。这篇文章中,我们主要看看DynamicServerList 内部实现是什么样子的。首先我们来看一下DynamicServerList 的具体解释,默认值是enable的,When set to OFF, the plug-in ignores the dynamic cluster list used for load balancing requests proxied from the plug-in and only uses the static list specified with the WebLogicCluster parameter. Normally this parameter should remain set to ON. There are some implications for setting this parameter to OFF:1:If one or more servers in the static list fails, the plug-in could waste time trying to connect to a dead server, resulting in decreased performance. 2:If you add a new server to the cluster, the plug-in cannot proxy requests to the new server unless you redefine this parameter. WebLogic Server automatically adds new servers to the dynamic server list when they become part of the cluster. 从上面的描述可以看出,DynamicServerList 用于使proxy实时获取后端cluster中的server列表(比如 cluster中的member增加、删除,member状态的变化(startup、shutdown)),这样proxy在load balance request的时候可以避免去try dead server。同时可以将请求dispatch到cluster中的新增member上(比如预定义的cluster中有server1, server2,某时刻发现后端server load比较高,新增加一个server3,这时候,如果DynamicServerList 为on,你就不需要重新定义 WeblogicCluster,当然也不需要重起plugin)。顺便提一下,DynamicServerList为on的时候,http.conf或 HttpClusterServlet对应的web.xml中的WeblogicCluster无需定义所有的cluster member,指定任意一个即可。WebLogicCluster 10.130.2.41:7021,10.130.2.42:7021,10.130.2.43:7021WebLogicCluster 10.130.2.41:7021上面两种写法是等效的,但DynamicServerList若为off,则必须采用上面的写法。下面我们来看看proxy是如何感知后端cluster状态的变化,从而及时更新自己手里的server list以便提高dispatch request的速度。1:plugin端(以HttpClusterServlet为例)在plugin处理client端请求的时候,它在将请求dispatch到后端server的时候,会在http header中加上一个名为X_WEBLOGIC_REQUEST_CLUSTERINFO的internal header, 如下:HttpClusterServlet.java1 protected void addRequestHeaders(HttpServletRequest request, PrintStream headerOut, Object o1, Object o2) {
2 super.addRequestHeaders(request, headerOut, o1, o2);
3
4 headerOut.print(ServletResponseImpl.X_WEBLOGIC_REQUEST_CLUSTERINFO + ": true");
5 headerOut.print(EOL);
6 }