In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Tomcatl introduction
Tomcat is a core project of the Jakarta project of the Apache Software Foundation (Apache Software Foundation), which is jointly developed by Apache, Sun and other companies and individuals. With the participation and support of Sun, the latest Servlet and JSP specifications are always reflected in Tomcat, and Tomcat 5 supports the latest Servlet 2.4 and JSP 2.0 specifications. Because of its advanced technology, stable performance and free, Tomcat is deeply loved by Java enthusiasts and recognized by some software developers, and has become a popular Web application server.
Tomcat components and their characteristics
Tomcat component
Servlet (application or container) is a component provided by java for developing web server applications. It runs on the server side. Servlet is used to generate dynamic page content. Servlet is a java class on the platform. To write a servlet is actually to install the servlet specification and write a java class.
Configure Tomcat virtual hosts and optimize
Case requirement
1) deploy the Tomcat service.
2) configure the virtual host.
3) Tomcat optimization.
4) Analysis and treatment of common errors.
Case realization train of thought
1) the environment required to install Tomcat.
2) install the Tomcat service.
3) configure the virtual host.
4) the client side installs the pressure test software for pressure test and tuning.
5) description of common errors.
Experimental process
1. Download and install JDK and deploy the Tomcat service
For more information, please see: https://blog.51cto.com/14557905/2464661
two。 View the directory structure after Tomcat installation
1) bin
Storage of startup and shutdown Tomcat script files, the more commonly used are catalina.sh, startup.sh, shutdown.sh three files.
2) conf
Store a variety of Tomcat server configuration files, the more commonly used are server.xml, context..xml, tomcat-users.xml, web.xml four files.
3) lib
The jar package that holds the Tomcat server is generally unchanged, unless you connect to a third-party service, such as redis, you need to add the corresponding jar package.
4) logs
Store Tomcat logs.
5) temp
Stores the files generated by the Tomcat runtime.
6) webapps
The directory where the project resources are stored.
7) work
Tomcat working directory, which is usually used when clearing the Tomcat cache.
II. Virtual host configuration
It is possible that sometimes a company has multiple projects to run, so it is certainly impossible to run multiple Tomcat services on a single server, which consumes too many system resources. At this point, you need to use the Tomcat virtual host. For example, we now add two new domain names, www.test.com and bbs.test.com, through which we hope to access different project contents.
1. Create www and bbs project directories and files
[root@localhost ~] # mkdir / usr/local/tomcat/webapps/www [root@localhost ~] # echo "This is www page\!" > / usr/local/tomcat/webapps/www/index.jsp [root@localhost ~] # mkdir / usr/local/tomcat/webapps/bbs [root@localhost ~] # echo "This is bbs page\!" > / usr/local/tomcat/webapps/bbs/index.jsp
two。 Modify the Tomcat main configuration file
Modify the Tomcat main configuration file / usr/local/tomcat/conf/server.xml by adding the following:
/ / about www.test.com virtual host configuration / / about bbs.test.com virtual host configuration [root@localhost ~] # / usr/local/tomcat/bin/shutdown.sh [root@localhost ~] # / usr/local/tomcat/bin/startup.sh
3. test
Client binds two domain names that need to be written to the native hosts,Tomcat. The default port is 8080.
192.168.9.236 www.test.com
192.168.9.236 bbs.test.com
III. Tomcat optimization
The default configuration of Tomcat is not suitable for the production environment, it will frequently appear fake death phenomenon and need to be rebooted. Only through continuous stress testing and optimization can it run stably and efficiently. There are three main aspects of optimization, including operating system optimization (kernel parameter optimization), Tomcat profile parameter optimization, Java virtual machine (JVM) tuning. One of the most difficult to understand is jvm tuning.
Parameter optimization of 1.Tomcat profile
There are many default configuration items in the Tomcat main configuration file server.xml, but they can not meet the business requirements. The commonly used optimization parameters are as follows.
MaxThreads:Tomcat uses threads to process each request received, and this value represents the maximum number of threads that Tomcat can create. The default value is 200. MinSpareThreads: the minimum number of idle threads, the number of threads initialized when Tomcat starts, indicating that there are so many empty threads waiting even if no one is using it. The default value is 10. MaxSpareThreads: the maximum number of standby threads, and once the created thread exceeds this value, Tomcat shuts down socket threads that are no longer needed. The default value is-1 (unlimited). Generally, there is no need to specify. URIEncoding: specify the URL encoding format of the Tomcat container. The language encoding format is not as convenient as other Web server software configuration and needs to be specified separately. ConnnectionTimeout: network connection timeout (in milliseconds). Setting to 0 means never timeout. This setting has hidden dangers. Usually the default is 20000 milliseconds. EnableLookups: whether to reverse the domain name to return the hostname of the remote host. The value is true or false. If set to false, the IP address is returned directly. In order to improve the processing power, it should be set to false. DisableUploadTimeout: whether to use timeout mechanism when uploading. Should be set to true. ConnectionUploadTimeout: upload timeout. After all, file upload may take more time. This can be adjusted according to your own business needs, so that Servlet has a longer time to complete its execution. It needs to be used in conjunction with the previous parameter to take effect. AcceptCount: specifies the maximum queue length that can be passed in connection requests when all available threads are used. Requests beyond this number will not be processed. The default is 100. Compression: whether to perform GZIP compression on the response data. Off: disable compression; on: allow compression (text will be compressed), force: compression is carried out in all cases. The default value is off. After compressing the data, you can effectively reduce the page size. Generally, you can reduce the size of the page by about 1x3, saving bandwidth. CompressionMinSize: indicates the minimum value of the compressed response. The message will be compressed only when the response message size is greater than this value. If compression is enabled, the default value is 2048. CompressableMimeType: compression type that specifies which types of files are compressed.
NoCompressionUserAgents= "gozilla, traviata": compression is not enabled for the following browsers.
If the code has been separated, static pages and images and other data do not need to be processed by Tomcat, then there is no need to configure compression in Tomcat. Because there is only one Tomcat server, and the pressure test is the Tomcat home page, there will be images and static resource files, so compression is enabled here.
Third, the above are some commonly used configuration parameters, and there are many other parameter settings, which can be further optimized. The parameter attribute values of HTTP Connector and AJP Connector can be learned by referring to the detailed instructions in the official documentation. Link the address http://tomcat.apache.org/tomcat-9.0-doc/config/http.html, and the next section starts to compare the Tomcat profile optimization before and after.
The stress test script sets the number of 4000 threads started in 20 seconds, the concurrency is 2000, and the timeout is 50000 milliseconds. It can also be modified according to your own needs. In order to be less complicated, we only focus on the aggregate report from the pressure test results, and the aggregation report only focuses on the three columns Average, 90% Line and Error%. Because the pressure on the home page of the stress test Tomcat is not too high, it is normal that the Error is 0. First, take a look at a group of pressure test screenshots before optimization (default configuration).
Open the Tomcat main configuration file, server.xml, and locate the default configuration:
Modify the default configuration:
Restart the Tomcat server, jmeter or continue to maintain the same parameters for pressure testing, optimized pressure test screenshot
Common error description
1.java.lang.OutOfMemoryError: Java heap space--JVM Heap (heap) overflow
JVM automatically sets the value of JVM Heap when it starts, and its initial space (- Xms) is 1x64 of physical memory, and the maximum space (- Xmx) cannot exceed physical memory. It can be set with options such as-Xmn-Xms-Xmx provided by JVM. The size of Heap is the sum of Young Generation and Tenured Generaion. In JVM, if 98% of the time is spent on GC, and the available Heap size is less than 2%, this exception information will be thrown.
Solution: manually set the size of the JVM Heap (heap).
2.java.lang.OutOfMemoryError: PermGen space--PermGen space overflow
The full name of PermGen space is Permanent Generation space, which refers to the permanent storage area of memory. The reason for the memory overflow is that this memory is mainly stored in Class and Meta information by JVM. Class is put into the PermGen space area when it is Load. Unlike the Heap area where Instance is stored, the GC of sun does not clean up PermGen space during the run time of the main program. So, if your APP loads a lot of CLASS, there is a good chance that PermGen space will overflow.
Solution: set the MaxPermSize size manually.
3.java.lang.StackOverflowErrormuri-Stack overflow
JVM is still a stack virtual machine, which is the same as C and Pascal. The calling process of the function is reflected in the stack and unstack. There are so many "layers" calling the constructor that the stack area is overflowed. Generally speaking, the stack area is much smaller than the stack area, because the function call process is often no more than thousands of layers, and even if each function call requires 1K space (which is equivalent to declaring 256variables of type int in a C function), then the stack area only needs 1MB space. Usually the size of the stack is 1-2MB.
Usually recursion does not have too many levels of recursion, which is easy to overflow. Solution: modify the program.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.