What is the difference between jetty, resin and Tomcat? Which web server should be selected for online services?

This is the back-end small class of the monastery. Each article is shared from

[background introduction] [knowledge analysis] [common problems] [solutions] [coding practice] [extended thinking] [more discussion] [References]

Eight aspects of in-depth analysis of back-end knowledge / skills. This article shares:

[what is the difference between jetty, resin and Tomcat? Which web server should be selected for online services?]

1. Background introduction

1、 What is Tomcat

Tomcat is the Apache Software Foundation (Apache Software Foundation) a core project in the Jakarta project is developed by Apache, Sun and other companies and individuals. With the participation and support of Sun, the latest Servlet and JSP specification can always be reflected in Tomcat. Tomcat 9 supports the latest 3.2 and 2.3 specification. Because the technology is advanced and the performance is stable, And free, so it is deeply loved by java lovers and recognized by some software developers. It has become a more popular web application server at present.

2、 What is jetty

Jetty is an open source servlet container that provides a running environment for Java based web containers, such as JSPS and servlets. Jetty is written in the Java language, and its API is published as a set of jar packages. Developers can instantiate the jetty container into an object, which can quickly provide network and web connections for some stand-alone Java applications.

3、 What is resin

Resin is a product of caucho company. It is a very popular engine that supports servlets and JSP. It is very fast. Resin itself contains a web server that supports HTTP / 1.1. It can not only display dynamic content, but also display static content. Its speed is close to Apache server. Many sites are built using this web server

2. Knowledge analysis

Tomcat architecture:

Tomcat is not only an HTTP server, but also a servlet container (it can execute servlet files, and JSP and JSF will be converted into servlets). It supports a variety of functions, so it adopts a layered and modular design.

Profile content

Jetty architecture:

The jetty server is a pipeline between a connector set and a handler set. The connector is used to receive HTTP connections. The handler serves and responds to requests from connections. The jetty server uses threads from a thread pool to handle these tasks.

When the jetty request / response originates from the servlet API, the complete features of the servlet API are available only if you configure the appropriate handler. For example, the session API in a request is activated only when the request is passed to a session handler. If servlets are not required, there is little overhead for servlet request / response APIs. So you can build a jetty server that uses only connectors and handlers without servlets.

The job of configuring jetty is to build a network of connectors and handlers and provide their respective configurations. Since jetty is a simple POJO (plain old Java object), you can complete the integration and configuration of components through various methods:

1) Code;

2) Use jetty XML;

3) Use dependency injection framework: spring or xbean;

4) Use jetty webapp and context deployer.

resin:

Resin provides the fastest JSP / servlets running platform. With the support of Java and JavaScript, resin can flexibly select the appropriate development language for tasks. As an advanced language of resin, XSL (XML stylesheet language) can separate form and content. If you choose JSP platform as the support of Internet commercial sites, the speed, price and stability should be considered. Resin is very excellent, the performance is more mature, and has the requirements of commercial software.

1、 Comparison between Tomcat and jetty

Similarities:

Tomcat and jetty are both servlet engines. They both support standard servlet specifications and Java EE specifications.

difference:

1. Architecture comparison

Jetty's architecture is simpler than Tomcat's

Jetty's architecture is implemented based on handler. The main extension functions can be implemented with handler, which is simple to expand.

Tomcat's architecture is based on container design. To expand, you need to understand the overall design structure of tomcat, which is not easy to expand.

2. Performance comparison

Jetty and Tomcat have little difference in performance

Jetty can handle a large number of connections at the same time and maintain the connection for a long time. It is suitable for web chat applications and so on.

Jetty's architecture is simple, so as a server, jetty can load components on demand, reduce unnecessary components, reduce server memory overhead, and improve server performance.

Jetty ends with NiO by default, which is more advantageous in processing I / O requests and has higher performance in processing static resources

A few are very busy; Tomcat is suitable for handling a few very busy links, that is, if the link life cycle is short, the overall performance of Tomcat is higher.

Tomcat uses bio to process I / O requests by default. When processing static resources, the performance is poor.

3. Other comparisons

Jetty's application is faster, easier to modify, and better supports the new servlet specification.

Tomcat is widely used at present. It supports Java EE and servlet more comprehensively, and many features will be directly integrated.

2、 The difference between Tomcat and resin

features

3. Frequently asked questions

1. Which web server should be selected for online services?

2. Why choose jetty?

3. Comparison between jetty and Tomcat?

4. Solutions

1. These servers have their own advantages and disadvantages. When selecting servers, you should first refer to the project and estimate the scale, etc. For example, for large-scale enterprise applications, Tomcat has expanded a large number of Jee features to meet the needs of enterprise applications, so Tomcat should be selected in this case.

2. Jetty is another excellent web server in the Java field. It is also open source. Unlike tomcat, it can be used as an embedded server. In other words, if we add jetty's core jar file to the application, the application can provide HTTP services. It is also a platform independent Java Web server, which can run on both windows and Linux platforms.

3. It is not significant to simply compare the performance of Tomcat and jetty. It can only be said that their performance is different in some use scenarios, because they face different use scenarios. In terms of architecture, Tomcat has more advantages in dealing with a few very busy connections, that is, if the connection life cycle is relatively short, Tomcat has better performance.

Jetty is just the opposite. Jetty can handle a large number of links at the same time and keep them for a long time. For example, some web chat applications are very suitable for jetty server, and Taobao's Web Wangwang uses jetty as a servlet engine

5. Coding practice

6. Expand thinking

These servers have their own advantages and disadvantages. When deploying servers for that website, how should we choose to ensure more efficient operation?

7. References

8. More discussion

1. What problems does Tomcat solve?

Tomcat is a servlet container. It can help us connect HTTP requests (do some general processing), and then forward the requests to our servlet processor for processing. We only need to put our business processing in the service method of the servlet, and we don't need to pay attention to other superfluous things.

2. What is Apache?

Apache HTTP server is a modular server that can run on almost all widely used computer platforms. It belongs to the application server. Apache supports many modules with stable performance. Apache itself is static parsing, which is suitable for static HTML, pictures, etc., but it can support dynamic pages through extended scripts, modules, etc.

3. Comparison between Apache and Tomcat?

Apache is dedicated to providing HTTP services, And related configurations (such as virtual host, URL forwarding, etc.), and Tomcat is a JSP server developed by Apache organization in line with the JSP and servlet standards of Java EE. Apache is a web server environment program, which can be used as a web server when enabled, but it can't only support static web pages (such as ASP, PHP, CGI, JSP) and other dynamic web pages. If you want to run JSP in Apache environment, you need an interpreter to execute JSP Web pages, and this JSP interpreter is Tomcat. Apache: focuses on HTTP server, Tomcat: focuses on servlet engine. If it runs in standalone mode, it is functionally equivalent to Apache and supports JSP, but it is not ideal for static web pages; Apache is a web server and Tomcat is an application (Java) server. It is just a servlet (JSP is also translated into servlet) container. It can be considered as an extension of Apache, but it can run independently of Apache. In practice, Apache and Tomcat are often integrated

Come and study with me:

Tencent Video:

Ppt link video link

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>