Difference between web server and application server

What is the difference between a WEB server, an application server, and an HTTP server? Which server does IIS, Apache, Tomcat, Weblogic, and WebSphere belong to? These questions have been confusing for a long time, and today I finally sorted out:

The basic function of a Web server is to provide Web information browsing services. It only needs to support HTTP protocol, HTML document format and URL. Works with the client's web browser. Because the main protocol supported by the web server is HTTP, usually the HTTP server and the WEB server are equal (there is no web server that supports protocols other than HTTP, the author has not verified it), it is the same thing.

Application server (referred to as application server), let's take a look at Microsoft's definition of it: "We define an application server as "the underlying system software that executes shared business applications as a server". Just like a file server provides many users with Like files, an application server allows multiple users to use an application (usually a customer-created application) at the same time"

In layman's terms, a Web server serves pages that browsers can browse, while an application server provides methods that client applications can call. To be precise, you can say: Web servers specialize in handling HTTP requests, but application servers serve business logic for applications through many protocols.

Taking Java EE as an example, the web server mainly handles static page processing and acts as a servlet container, interpreting and executing servlet/JSP , while the application server runs business logic, mainly J2EE APIs such as EJB, JNDI and JMX API, and also Including transaction processing, database connection and other functions, so in enterprise-level applications, the functions provided by the application server are much more powerful than the WEB server.

With this definition, IIS, Apache, and Tomcat can all belong to Web servers, and Weblogic and WebSphere can all belong to application servers.

Apache: In web server, Apache is pure web server and is often paired with Tomcat. It has a strong ability to interpret HTML pages, but cannot interpret the server-side script code (JSP/Servlet) embedded in the page.

Tomcat: The early Tomcat is a JSP/Servlet interpretation engine embedded in Apache. Apache+Tomcat is equivalent to IIS+ASP. Later Tomcat is no longer embedded in Apache, and the Tomcat process runs independently of the Apache process. Moreover, Tomcat is already an independent Servlet and JSP container, and the code of the business logic layer and the code of the interface interaction layer can be separated. Therefore, some people call Tomcat a lightweight application server.

IIS: Microsoft's early IIS is a pure Web server. Later, it embedded ASP engine, can interpret VBScript and JScript server-side code, at this time, it can double as application server. Of course, it is not comparable to a J2EE application server at all, but functionally and in principle, it can barely be called an application server. Rather, it's a web server with a little application server functionality.

To sum up: Apache is a pure web server, while Tomcat and IIS can be called lightweight application servers or web servers with server functions because of their ability to interpret and execute server-side code.

Because Weblogic and WebSphere can provide powerful J2EE functions, there is no doubt that they are absolute application servers.

For Tomcat in the middle, it can be used with the pure web server Apache, or it can be deployed alongside the application server as a secondary:

1. Tomcat and application server

So far, Tomcat has been considered the executor of the Servlet/JSP API, also known as the Servlet container. However, Tomcat is not only that, it also provides the implementation mechanism of JNDI and JMX API. Still, Tomcat is not an application server because it does not provide support for most of the J2EE APIs.

很有意思的是,目前许多的应用服务器通常把Tomcat作为它们Servlet和JSP API的容器。由于Tomcat允许开发者只需通过加入一行致谢,就可以把Tomcat嵌入到它们的应用中。遗憾的是,许多商业应用服务器并没有遵守此规则。

对于开发者来说,如果是为了寻找利用Servlet、JSP、JNDI和JMX技术来生成Java Web应用的话,选择Tomcat是一个优秀的解决方案;但是为了寻找支持其他的J2EE API,那么寻找一个应用服务器或者把Tomcat作为应用服务器的辅助,将是一个不错的解决方案;第三种方式是找到独立的J2EE API实现,然后把它们跟Tomcat结合起来使用。虽然整合会带来相关的问题,但是这种方式是最为有效的。。

二、Tomcat与Web服务器

Tomcat是提供一个支持Servlet和JSP运行的容器。Servlet和JSP能根据实时需要,产生动态网页内容。而对于Web服务器来 说, Apache仅仅支持静态网页,对于支持动态网页就会显得无能为力;Tomcat则既能为动态网页服务,同时也能为静态网页提供支持。尽管它没有通常的 Web服务器快、功能也不如Web服务器丰富,但是Tomcat逐渐为支持静态内容不断扩充。大多数的Web服务器都是用底层语言编写如C,利用了相应平 台的特征,因此用纯Java编写的Tomcat执行速度不可能与它们相提并论。

一般来说,大的站点都是将Tomcat与Apache的结合,Apache负责接受所有来自客户端的HTTP请求,然后将Servlets和JSP的请求 转发给Tomcat来处理。Tomcat完成处理后,将响应传回给Apache,最后Apache将响应返回给客户端。

而且为了提高性能,可以一台apache连接多台tomcat实现负载平衡。

 

关于WEB服务器、应用程序服务器的更详细区别可以参考下面这篇文章:

通俗的讲,Web服务器传送(serves)页面使浏览器可以浏览,然而应用程序服务器提供的是客户端应用程序可以调用(call)的方法(methods)。确切一点,你可以 说:Web服务器专门处理HTTP请求(request),但是应用程序服务器是通过很多协议来为应用程序提供(serves)商业逻辑 (business logic)。

  下面让我们来细细道来:

  Web服务器(Web Server)

  Web服务器可以解析(handles)HTTP协议。当Web服务器接收到一个HTTP请求(request),会返回一个HTTP响应 (response),例如送回一个HTML页面。为了处理一个请求(request),Web服务器可以响应(response)一个静态页面或图片, 进行页面跳转(redirect),或者把动态响应(dynamic response)的产生委托(delegate)给一些其它的程序例如CGI脚本,JSP(JavaServer Pages)脚本,servlets,ASP(Active Server Pages)脚本,服务器端(server-side)JavaScript,或者一些其它的服务器端(server-side)技术。无论它们(译者 注:脚本)的目的如何,这些服务器端(server-side)的程序通常产生一个HTML的响应(response)来让浏览器可以浏览。

  要知道,Web服务器的代理模型(delegation model)非常简单。当一个请求(request)被送到Web服务器里来时,它只单纯的把请求(request)传递给可以很好的处理请求 (request)的程序(译者注:服务器端脚本)。Web服务器仅仅提供一个可以执行服务器端(server-side)程序和返回(程序所产生的)响 应(response)的环境,而不会超出职能范围。服务器端(server-side)程序通常具有事务处理(transaction processing),数据库连接(database connectivity)和消息(messaging)等功能。

  虽然Web服务器不支持事务处理或数据库连接池,但它可以配置(employ)各种策略(strategies)来实现容错性(fault tolerance)和可扩展性(scalability),例如负载平衡(load balancing),缓冲(caching)。集群特征(clustering—features)经常被误认为仅仅是应用程序服务器专有的特征。

  应用程序服务器(The Application Server)

  根据我们的定义,作为应用程序服务器,它通过各种协议,可以包括HTTP,把商业逻辑暴露给(expose)客户端应用程序。Web服务器主要 是处理向浏览器发送HTML以供浏览,而应用程序服务器提供访问商业逻辑的途径以供客户端应用程序使用。应用程序使用此商业逻辑就象你调用对象的一个方法 (或过程语言中的一个函数)一样。

  应用程序服务器的客户端(包含有图形用户界面(GUI)的)可能会运行在一台PC、一个Web服务器或者甚至是其它的应用程序服务器上。在应用 程序服务器与其客户端之间来回穿梭(traveling)的信息不仅仅局限于简单的显示标记。相反,这种信息就是程序逻辑(program logic)。 正是由于这种逻辑取得了(takes)数据和方法调用(calls)的形式而不是静态HTML,所以客户端才可以随心所欲的使用这种被暴露的商业逻辑。

  在大多数情形下,应用程序服务器是通过组件(component) 的应用程序接口(API)把商业逻辑暴露(expose)(给客户端应用程序)的,例如基于J2EE(Java 2 Platform, Enterprise Edition)应用程序服务器的EJB(Enterprise JavaBean)组件模型。此外,应用程序服务器可以管理自己的资源,例如看大门的工作(gate-keeping duties)包括安全(security),事务处理(transaction processing),资源池(resource pooling), 和消息(messaging)。就象Web服务器一样,应用程序服务器配置了多种可扩展(scalability)和容错(fault tolerance)技术。

一个例子

  例如,设想一个在线商店(网站)提供实时定价(real-time pricing)和有效性(availability)信息。这个站点(site)很可能会提供一个表单(form)让你来选择产品。当你提交查询 (query)后,网站会进行查找(lookup)并把结果内嵌在HTML页面中返回。网站可以有很多种方式来实现这种功能。我要介绍一个不使用应用程序服务器的情景和一个使用应用程序服务器的情景。观察一下这两中情景的不同会有助于你了解应用程序服务器的功能。

  情景1:不带应用程序服务器的Web服务器

  在此种情景下,一个Web服务器独立提供在线商店的功能。Web服务器获得你的请求(request),然后发送给服务器端(server- side)可以处理请求(request)的程序。此程序从数据库或文本文件(flat file,译者注:flat file是指没有特殊格式的非二进制的文件,如properties和XML文件等)中查找定价信息。一旦找到,服务器端(server-side)程序 把结果信息表示成(formulate)HTML形式,最后Web服务器把会它发送到你的Web浏览器。

  简而言之,Web服务器只是简单的通过响应(response)HTML页面来处理HTTP请求(request)。

  情景2:带应用程序服务器的Web服务器

  情景2和情景1相同的是Web服务器还是把响应(response)的产生委托(delegates)给脚本(译者注:服务器端 (server-side)程序)。然而,你可以把查找定价的商业逻辑(business logic)放到应用程序服务器上。由于这种变化,此脚本只是简单的调用应用程序服务器的查找服务(lookup service),而不是已经知道如何查找数据然后表示为(formulate)一个响应(response)。 这时当该脚本程序产生HTML响应(response)时就可以使用该服务的返回结果了。

  在此情景中,应用程序服务器提供(serves)了用于查询产品的定价信息的商业逻辑。(服务器的)这种功能(functionality)没 有指出有关显示和客户端如何使用此信息的细节,相反客户端和应用程序服务器只是来回传送数据。当有客户端调用应用程序服务器的查找服务(lookup service)时,此服务只是简单的查找并返回结果给客户端。

  通过从响应产生(response-generating)HTML的代码中分离出来,在应用程序之中该定价(查找)逻辑的可重用性更强了。其 他的客户端,例如收款机,也可以调用同样的服务(service)来作为一个店员给客户结帐。相反,在情景1中的定价查找服务是不可重用的因为信息内嵌在 HTML页中了。

  总而言之,在情景2的模型中,在Web服务器通过回应HTML页面来处理HTTP请求(request),而应用程序服务器则是通过处理定价和有效性(availability)请求(request)来提供应用程序逻辑的。

  警告(Caveats)

  现在,XML Web Services已经使应用程序服务器和Web服务器的界线混淆了。通过传送一个XML有效载荷(payload)给服务器,Web服务器现在可以处理数据和响应(response)的能力与以前的应用程序服务器同样多了。

  另外,现在大多数应用程序服务器也包含了Web服务器,这就意味着可以把Web服务器当作是应用程序服务器的一个子集(subset)。虽然应 用程序服务器包含了Web服务器的功能,但是开发者很少把应用程序服务器部署(deploy)成这种功能(capacity)(译者注:这种功能是指既有 应用程序服务器的功能又有Web服务器的功能)。相反,如果需要,他们通常会把Web服务器独立配置,和应用程序服务器一前一后。这种功能的分离有助于提 高性能(简单的Web请求(request)就不会影响应用程序服务器了),分开配置(专门的Web服务器,集群(clustering)等等),而且给 最佳产品的选取留有余地.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327058981&siteId=291194637