Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Load Balancing Using web.xml

DZone's Guide to

Load Balancing Using web.xml

Testing an app's performance in the prod environment may require creating a replica, which may not be feasible. See how to create a load balancing app with just web.xml.

· Performance Zone
Free Resource

Transform incident management with machine learning and analytics to help you maintain optimal performance and availability while keeping pace with the growing demands of digital business with this eBook, brought to you in partnership with BMC.

If you are wondering how you can test the performance of your newly developed application in a production environment, then probably you have to create a replica — which is not feasible in most of the cases. By following some simple tricks, you can create a production-like environment in your dev set-up only. A major restriction is the SSL, networking, load balancing, and clustering of the server for creating the replica of the production environment. Today, I would be telling you how to create a load balancing application in your dev environment using just web.xml.

Here's my reference from the Oracle site.

Create a dynamic web project in your IDE and place the below code in web.xml:

<web-app>
	<servlet>
		<servlet-name>HttpClusterServlet</servlet-name>
		<servlet-class>weblogic.servlet.proxy.HttpClusterServlet</servlet-class>
		<init-param>
			<param-name>WebLogicCluster</param-name>
			<param-value>localhost:7002|localhost:7003</param-value>
		</init-param>
		<init-param>
			<param-name>DebugConfigInfo</param-name>
			<param-value>ON</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>HttpClusterServlet</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>HttpClusterServlet</servlet-name>
		<url-pattern>*.jsp</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>HttpClusterServlet</servlet-name>
		<url-pattern>*.htm</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>HttpClusterServlet</servlet-name>
		<url-pattern>*.html</url-pattern>
	</servlet-mapping>
</web-app>

Creat the WAR and deploy it into a new managed server that is not pointing to any of the clusters. Add the URLs of the managed servers for which you wish to use for the load balancing: <param-value>localhost:7002|localhost:7003</param-value>.

Access your application with the port number of the deployed load balancing application and you will get the required result. And you're done!

Evolve your approach to Application Performance Monitoring by adopting five best practices that are outlined and explored in this e-book, brought to you in partnership with BMC.

Topics:
load balancing ,performance ,app development ,web.xml

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}