One, memory overflow problem
Linux Setup startup script
[Email protected] ~]# vi/usr/local/tomcat/bin/catalina.sh
#______________________________________________________________________________________________________________ __start
225 # Bugzilla 37848:only Output This if we have a TTY
226 if [$have _tty-eq 1]; Then
227 java_opts= "$JAVA _opts-server-xms512m-xmx4096m-xx:maxnewsize=256m-xx:maxpermsize=256m"
228 echo "Using catalina_base: $CATALINA _base"
#______________________________________________________________________________________________________________ __end
Explain
-XMS: Initial value
-XMX: Maximum Value
-XMN: Minimum value
The general "-XMS" is the "-xmx" of the Quarter, "-xxermsize" is "-xx:maxpermsize" of 1/2.
Therefore, it is generally recommended that the maximum heap value be set to 80% of the maximum available memory.
Reason:
It is found that many people attribute the problem to: Spring,hibernate,tomcat because they dynamically produce classes that cause the permanent heap overflow in the JVM.
And then there's a lot of talk about how to upgrade the Tomcat version to the newest and even no Tomcat, and some doubt that spring's problem is very much discussed on the Spring Forum because spring uses cblib in AOP to generate many classes dynamically.
But the question is why the same problem arises from the open source of these trump cards, is it a more basic reason?
Tomcat answered this very vaguely in q&a, and we know the problem, but the problem is caused by a more basic problem, and someone has checked the more basic JVM and found the key to the problem.
The original Sun's JVM has divided the memory into different areas, one of which is the Permenter area used to store a lot of classes and class description, originally Sun Design thought this area was fixed when the JVM started, but he did not expect the current dynamic will be used so widely.
And this area has a special garbage recovery mechanism, now the problem is that the dynamic loading class to this area, the GC has no way to recycle!
=============================================================================================================== ==================================================================
Second, the Connection pool optimization
1, configuration file resolution
Accept the port that closed the Tomcat command:
[Email protected] ~]# Vi/usr/local/tomcat/conf/server.xml
<server port= "8005" shutdown= "Shutdown" >
To define a database connection pool:
[Email protected] ~]# Vi/usr/local/tomcat/conf/server.xml
<resource name= "Userdatabase" auth= "Container"
Type= "Org.apache.catalina.UserDatabase"
description= "User database that can be updated and saved"
factory= "Org.apache.catalina.users.MemoryUserDatabaseFactory"
Pathname= "Conf/tomcat-users.xml"/>
</GlobalNamingResources>
Define the configuration shared thread pool, which is used for client and server-side connection control:
[Email protected] ~]# Vi/usr/local/tomcat/conf/server.xml
#______________________________________________________________________________________________________________ __start
<executor name= "Tomcatthreadpool" nameprefix= "catalina-exec-"
minsparethreads= "100"
Maxsparethreads= "500"
Maxthreads= "3000"
acceptcount= "100"
Maxidletime= "60000"
/>
#______________________________________________________________________________________________________________ __end
Configure the engine, note that the defaulthost= "" must be the same as one in host, which specifies the default Web site.
[Email protected] ~]# Vi/usr/local/tomcat/conf/server.xml +99
<engine name= "Catalina" defaulthost= "www.00peixun.com" >
Use the database connection pool configured above
[Email protected] ~]# Vi/usr/local/tomcat/conf/server.xml +99
<realm classname= "Org.apache.catalina.realm.UserDatabaseRealm" resourcename= "Userdatabase"/>
The shared thread pool configured above is used to control client connections and to optimize dispatch server resources.
[Email protected] ~]# Vi/usr/local/tomcat/conf/server.xml
#______________________________________________________________________________________________________________ __start
<connector port= "8080" protocol= "http/1.1"
Connectiontimeout= "30000"
Redirectport= "8443"
Executor= "Tomcatthreadpool"
Enablelookups= "false"
Usebodyencodingforuri= "true"
/>
#______________________________________________________________________________________________________________ __end
Configuring a virtual Host
[Email protected] ~]# Vi/usr/local/tomcat/conf/server.xml
#______________________________________________________________________________________________________________ __start
Unpackwars= "true" autodeploy= "true"
Xmlvalidation= "false" Xmlnamespaceaware= "false" >
<context path= "" docbase= "/home/www/game" debug= "0" reloadable= "false"
Crosscontext= "true"/>
<!--Singlesignon valve, share authentication between Web applications
Documentation at:/docs/config/valve.html--
<!--
<valve classname= "Org.apache.catalina.authenticator.SingleSignOn"/>
-
<!--Access log processes all example.
Documentation at:/docs/config/valve.html--
<!--
<valve classname= "Org.apache.catalina.valves.AccessLogValve" directory= "Logs"
Prefix= "Localhost_access_log." suffix= ". txt" pattern= "common" resolvehosts= "false"/>
-
</Host>
#______________________________________________________________________________________________________________ __end
1, minsparethreads= "100": Sets the number of socket threads created when Tomcat is initialized, and after some threads are used, new threads are constantly created to cause the idle thread to keep at least the number set by Minsparethreads, with a default value of 4
2. maxsparethreads= "500": Set the maximum number of free socket threads for the Tomcat connector, and when some of the connections are broken, the thread will be released continuously, when the number of empty threads exceeds maxsparethreads set Proactively shuts out threads to save resources by default of 50
3, maxthreads= "3000": Set the maximum number of threads handling customer requests, this value also determines the server can respond to the maximum number of customer requests, this value does not affect the performance of the additional, so it can be appropriately increased, but let the General Assembly encounter traffic attack Oh, the default value is 200.
4, acceptcount= "100": Set the maximum number of client requests in the listening port queue, the default value is 10, if the queue is full the client request will be rejected. When all the available threads are exhausted, the other connections are all put in the queue, and the maximum number in the queue is acceptcount set, exceeding this number will deny the connection
5. ConnectionTimeout: Defines the time to establish the client connection timeout, which is 20000 milliseconds by default. If 0, indicates that the time to establish a client connection is not limited.
6, Maxidletime= "60000": threads that exceed the minimum number of active threads, will be closed if idle time exceeds this setting. Default is 1 minutes
7. Usebodyencodingforuri: Indicates whether the data submitted by the URL and the data submitted in the form are re-encoded with the request.setcharacterencoding parameter, and the default value is False.
8, Redirectport: Specify the forwarding port.
9. ConnectionTimeout: Defines the time to establish the client connection timeout, which is 20000 milliseconds by default. If 1, the time that the client connection was established is not limited.
10. Usebodyencodingforuri: Indicates whether the data submitted by the URL and the data submitted in the form are re-encoded with the request.setcharacterencoding parameter, and the default value is False.
Attention
TOMCAT4 can be controlled by modifying the values of Minprocessors and maxprocessors ....
(minprocessors: The minimum number of processing threads created at server startup, even if there are no HTTP requests, Tomcat should keep at least so many threads waiting to be processed;
Maxprocessors: At the same time the maximum number of processing threads, if the system already has this number of threads, then more connection requests will enter the queue. )
TOMCAT5 can be controlled by modifying the values of Minsparethreads and minsparethreads.
Apr Library Use
Using the APR library in Tomcat is actually a way of using JNI in Tomcat to read files and network transmissions.
Can greatly improve the performance of Tomcat for static files, and if you use HTTPS mode, you can also improve the processing performance of SSL.
In general, under Windows, you can download the compiled binary DLL library file directly to enable Tomcat for APR, it is generally recommended that the Copy library file Tcnative-1.dll to the Tomcat bin directory.
Under Linux, you can directly unzip and install the tomcat_native.tar.gz file in the bin directory, before compiling to ensure that the APR library is installed.
How can I tell if Tomcat has enabled the APR library? The method is by looking at the Tomcat's boot log:
If APR is not enabled, the boot log typically has one of these:
Org.apache.coyote.http11.Http11Protocol start
If APR is enabled, this log will become:
Org.apache.coyote.http11.Http11AprProtocol start
tcnative-1.dll:http://archive.apache.org/dist/tomcat/tomcat-connectors/native/
Tomcat Optimization Summary