Tuesday, November 24, 2015

Application Server Vs Web Server

Difference between Application Server and Web Server.

1) Web server handles HTTP protocol. The main function of a web server is keeping files active for web site browsing, twenty-four hours a day, seven days a week.
Application server provide support to other protocol support like RMI/RPC

2) Application Server supports distributed transaction, EJB, Connection Pooling, Transaction management, Load balancing and persistence.
Web server is an application for serving static content. For example Apache HTTPD is a web server. Tomcat and Jetty are called web containers or servlet containers and not the web Server.

3) Application server is heavier than web server in terms of resource utilization

4) Web server is well suited for Static content (although plugins support makes it dynamic too)
Application server is suited for Dynamic content.

5) The Web Server does not support the concept of multi-threading.

6) A web server (program) has defined load limits, because it can handle only a limited number of concurrent client connections (usually between 2 and 60,000, by default between 500 and 1,000) per IP address (and IP port) and it can serve only a certain maximum number of requests per second. On the other hand, an application server has a much higher capacity.

Web Server -> Programming Environment
IIS : ASP (.NET)
Tomcat : Servlet
Jetty : Servlet
Apache : Php, CGI

Application Servers -> Programming Environment
MTS : COM+
WAS : EJB
JBoss : EJB
WebLogic Application Server : EJB

In some cases the servers are tightly integrated such as IIS and .NET Runtime. IIS is web server. When equipped with .NET runtime environment, IIS is capable of providing application services.

More about Web Container
Tomcat is a web container, when a request is made from a Client to web server, it passes the request to web container and it’s web container job to find the correct resource to handle the request (servlet or JSP) and then use the response from the resource to generate the response and provide it to web server. Then web server sends the response back to the client.

When web container gets the request and if it’s for servlet then container creates two Objects HTTPServletRequest and HTTPServletResponse. Then it finds the correct servlet based on the URL and creates a thread for the request. Then it invokes the servlet service() method and based on the HTTP method service() method invokes doGet() or doPost() methods. Servlet methods generate the dynamic page and write it to response. Once servlet thread is complete, container converts the response to HTTP response and send it back to client.

Some of the important work done by web container are:
·         Communication Support – Container provides easy way of communication between web server and the servlets and JSPs. Because of container, we don’t need to build a server socket to listen for any request from web server, parse the request and generate response. All these important and complex tasks are done by container and all we need to focus is on our business logic for our applications.
·         Lifecycle and Resource Management – Container takes care of managing the life cycle of servlet. Container takes care of loading the servlets into memory, initializing servlets, invoking servlet methods and destroying them. Container also provides utility like JNDI for resource pooling and management.
·         Multithreading Support – Container creates new thread for every request to the servlet and when it’s processed the thread dies. So servlets are not initialized for each request and saves time and memory.
·         JSP Support – JSPs doesn’t look like normal java classes and web container provides support for JSP. Every JSP in the application is compiled by container and converted to Servlet and then container manages them like other servlets.
·         Miscellaneous Task – Web container manages the resource pool, does memory optimizations, run garbage collector, and provides security configurations, support for multiple applications, hot deployment and several other tasks behind the scene that makes our life easier.

No comments:

Post a Comment