Geeks time Tomcat 04

Tomcat Connector, which has several operating modes (optimized)?


Below, we first overview of the three operating modes Tomcat Connector.

BIO: synchronous and blocking a thread processing a request. Disadvantages: high concurrency, large number of threads, a waste of resources. Tomcat7 or less, in default Linux system in this way.
Preparation entry: protocol = "HTTP / 1.1"

NIO: synchronous non-blocking IO

Asynchronous IO processing using Java, can handle a large number of requests by a small number of threads, a plurality of treatment may be multiplexed connection (multiplexed) with a thread.

Tomcat8 default on Linux systems using this approach.

Tomcat7 Connector configuration must be modified to start.

Preparation entry: Protocol = "org.apache.coyote.http11.Http11NioProtocol"

Note: we used Jetty, Mina, ZooKeeper are all java nio implementation.

APR: namely Apache Portable Runtime, io solve the blocking problem from the operating system level. ** AIO way, ** asynchronous non-blocking IO (Java NIO2 called AIO) The main difference with the NIO main difference is the underlying operating system may be a metaphor: compared to the courier, NIO is the online shopping to their own official website to check under whether the courier has arrived (possibly several times), and then pick up express themselves; AIO is a courier delivery (not express concern progress).

Preparation entry: protocol = "org.apache.coyote.http11.Http11AprProtocol"

Note: APR library to be installed on the local server. Tomcat7 or Tomcat8 start the system default Win7 or more this way. If the apr and native Linux installation, Tomcat will start direct support apr.
 

 

  BIO tomcat default model used, there will be a serious decline in performance at several hundred concurrent. tomcat model also comes with the NIO, Alternatively, you can call the APR library to achieve the operating system level control.

    NIO model is built, it is convenient to call, just to the above configuration file protocol modified to org.apache.coyote.http11.Http11NioProtocol, restart to take effect. I have to turn the above configuration, the default is HTTP / 1.1.

    APR you need to install third-party libraries, make performance has improved significantly under high concurrency. As the default protocal is apr, but it is best to modify the protocol org.apache.coyote.http11.Http11AprProtocol, it will be more clear.

How Tomcat servlet container class instance is created? What principle is used ?
When the container starts, will read web.xml files for all web applications in the webapps directory, and then parse xml file, and read the servlet registration information. Then, each registered application loaded servlet class, and by way of example of the reflection. (Sometimes also in the first instance of the request)
plus 1 if it is positive, then at the outset instantiated in the servlet registration, if you do not write or negative, the first request instantiated.

 

Tomcat working mode
Tomcat as the servlet container, it has three operating modes:

1, separate servlet container, servlet container is a part of a web server;
2, the servlet container in process, the servlet container as implemented plug a web server and java containers, the web server plug-in opening in the internal address space of a jvm such java container able to run inside. The reaction is fast but less stretchable;
binding servlet container 3 out of the process, the servlet container running outside the web server address space as the web server and the plug container java implementation. The reaction time of the process but not as stretchable and excellent stability than the process;
the request can be divided into the following categories Tomcat depending on the mode of Tomcat:

Tomcat application server: a request from a web server front end, which may be the Apache, IIS, Nginx like;
Tomcat as a standalone server: a request from a web browser;

   More Connector and a Container on the formation of a Service, with Service can provide services, but also a living environment Service, someone must be able to give her life, grasp the power of life and death, it is none other than the non-Server up! So the whole life cycle is controlled by the Tomcat Server
 

Summary of top-level architecture Tomcat
Tomcat is only one Server, a Server can have multiple Service, a Service can have multiple Connector and a Container;

Server power of life and death in charge of the entire Tomcat;

Service is the external service provider;

Connector for receiving requests and packaged into Request and Response to a specific process;

Container for packaging and managing Servlet, and specific processing REQUEST request;

 

 

Tomcat container layer 4 

Engine: engine, used to manage multiple sites, a Service can only have a maximum of Engine;

Host: represents a site, it can also be called a virtual host, by configuring the Host can add sites;

Context: represents an application program corresponding to a normal development, or a WEB-INF directory and below web.xml file;

Wrapper: each encloses a Wrapper the Servlet;

 

Servlet life cycle can be divided into five steps

Load Servlet: When Tomcat Servlet's first visit, Tomcat will be responsible for creating an instance of the Servlet;
Initialization: When the Servlet is instantiated, Tomcat will call the init () method to initialize the object;
processing services: When a browser to access the Servlet time, Servlet calls the service () method to process the request;
destruction: when Tomcat Servlet detected from closed or deleted when Tomcat will automatically call destroy () method, so that the share of resources freed example. Servlet If a long time without being used, Tomcat will be automatically destroyed;
unloading: When the End call Servlet destroy () method, wait for garbage collection. If you need to use this Servlet again, it will re-invoke init () method initializes.


 

Published 386 original articles · won praise 2 · Views 9847

Guess you like

Origin blog.csdn.net/kuaipao19950507/article/details/104876764