Analysis of Tomcat and WAS application middleware differentiation

- Reproduced http://blog.chinaunix.net/uid-25723371-id-5759072.html

We are currently in use JAVA-based presentation application logic middleware provides two types, one is a web application middleware software business WAS represented, the other is an open source web application middleware tomcat representatives. In order to better manage the use of these two types of middleware, so I picked up part of the time to study and analyze the similarities and differences between the two middleware it is necessary and valuable. We really only have these two middleware knowledge and understanding to be able to achieve the best use targeted. Sincerely I hope that I have done some basic work to be able to engage in the development of JAVA-based staff to bring some inspiration. Regardless of tomcat or was on the skill technology or are very profound in the operating mechanism, the author of this writing seeks to when the process of rigorous, correct, but given the author is limited, it is inevitable view the document proposed deviation, if inappropriate place, please criticism. The purpose of this document is intended to organize analysis and comparison of Tomcat and WAS own characteristics and suitable type of business, for the follow-up to better use, management Tomcat, WAS application middleware to provide some suggestions and references. I also hope some of the content of the document is engaged in providing valuable information based colleagues tomcat, was the development and maintenance work, and apply the associated characteristics related to work or go into the resolution process we use tomcat or was in the case of to some of the problems.
A, Tomcat and Was Benchmarking
1. Implement Schema Compare
   Was there on Tomcat and application architecture serves the same purpose, tomcat is a relatively lightweight web application middleware, its core component consists of two parts: Connector and Container, Container can choose a corresponding number Connector. More Connector and a Container on the formation of a Service. Was it similar to the design ideas, but slightly different terminology. tomcat and was all use a modular design and realization of ideas, are very complex in structure, but the relative ratio up, tomcat in the realization of quite lightweight, tomcat deal only partially functional web application, there are a lot enterprise-level applications do not support the management component is relatively simple, and there is perfect container for different scenarios on Was supported on each application scenarios, in addition to the management component is relatively perfect.
2.JDK type and version comparison
   Tomcat uses the open source community of Sun's jdk, we can choose a compatible JDK version can be deployed in accordance with the appropriate manual version of tomcat. Was carried out on the basis of the open source community version of the jdk on custom development, does not need to consider when installing the jdk Was, Was because it has customized the IBM JDK software package dedicated to the mounting of media Was. 
3.JVM type comparison
   Tomcat using the type of HotSpot JVM, Was developed using the IBM J9 JVM virtual machine. Was Tomcat and select a different JDK as their operating environment at the same time, it basically determines the choice of different types of virtual machine back to achieve their JAVA engine. So when we come across JVM failure, need to use different diagnostic tools for analysis. This place is a particular need to pay attention to the point. 
4. Support Feature Comparison
   Apache Tomcat is the Servlet container Foundation, which supports key J2EE technologies JSP, Servlet and JDBC, etc., so users can use Tomcat to develop a Web-based database applications, Servlet and JSP pages. However, Tomcat is not EJB container, that is to say, Tomcat does not support EJB. Then, using the EJB component development of Web applications will not run on Tomcat below. As we all know, EJB is the core technology of distributed applications, so that those who need to develop applications using EJB can not be used Tomcat. This is also the Tomcat Was the main differences in functionality. Though Was there a lot of other advanced features but unfortunately many companies holding these big stuff is actually doing just Tomcat live.
5. Performance Comparison
   HotSpot dynamic modeling techniques using sampled data from the application is running, so that the code can be optimized, and thus obtain a good performance. It is equivalent to mimic artificial methods of optimization. At the beginning of the program to run, Java code is still interpreted, but HotSpot engine start sampling (Profiling). HotSpot engine can focus on to optimize the depth of the HotSpot code, thus accelerating the speed of code execution. Due Was adopted IBM's J9 VM virtual machine type, due to the closed-source operating mechanism implemented so on internal JVM Was the presentation aspects of the data are extremely rare, not here in the repeat. According to IBM official information on its garbage collection algorithm is very prominent, to ensure that the vast majority of applications running in real-time, stop time less than 3 milliseconds, its best performance in the industry is the JAVA virtual machine. But from the JVM development history, theory, performance should be the best type of HotSpot virtual machine, rather than IBM's J9 virtual machine.
If so I recommend the use of IBM software or server, consider using J9, because IBM J9 itself is based on its own hardware and software system is specifically designed to optimize, there should be some improvement in performance, the use of open platforms still highly recommended choice HotSpot virtual machine type, because this is the mainstream industry practices.
From the above it can be seen tomcat is now able to cover more than 80% Was middleware functions, that is to say Was able to do things, Tomcat also basically competent. But tomcat in place many of the details of doing is not detailed enough, unlike Was that like a well-built craft is that easy to use and engaging. But on Tomcat flexibility is impossible Was, Was there commercial support, free Tomcat, and Tomcat Was Both middleware has a short foot inch a director, with good can solve our problems.
A review of the official found a lot of information, whether or Tomcat Was very profound in the design and implementation, if you really fine-grained to analyze the differences between the two, I am afraid that a book never finish. Given the limited level, I can only superficially with the great masters, the initiate. If inappropriate, please criticized the correction.
Second, difficult debugging and troubleshooting
1. Chinese character issues
  a) HTML Chinese encoding conversion
if the JSP file static text garbled, Chinese disposed between the need to increase the code in
the following: 
 
charset specified set of Chinese characters may of course be specify other Chinese encoding, such as GBK and so on. 
In addition, modifications may be converted MIME encoding Chinese character codes as shown below. 
 
HTM  
text / HTML; charset = GB2312  
 
 
HTML  
text / HTML; charset = GB2312  
  b) JSP Chinese encoding conversion
Chinese Tomcat under dynamic content for the garbage problem, there are several solutions: 
(1) increase at the beginning of each JSP file the following code: 
<% @ Page Language = "Java" contentType = "text / HTML; GBK charset ="%> 
(2)设置编码参数: 
request.setCharacterEncoding("gb2312"); 
(3)使用编码过滤器,修改web.xml: 
 
Set Character Encoding 
SetCharacterEncodingFilter 
 
 
Set Character Encoding 
/* 
 
建立类SetCharacterEncodingFilter.java: 
import java.io.IOException; 
import javax.servlet.Filter; 
import javax.servlet.FilterChain; 
import javax.servlet.FilterConfig; 
import javax.servlet.ServletException; 
import javax.servlet.ServletRequest; 
import javax.servlet.ServletResponse; 
import javax.servlet.UnavailableException; 
public class SetCharacterEncodingFilter implements Filter { 
    public void doFilter(ServletRequest request,  
    Response the ServletResponse, the FilterChain catena alberghiera) throws IOException, 
    ServletException { 
        Request.setCharacterEncoding ( "GBK"); 
        // passes control to the next filter 
        the chain.doFilter (Request, Response); 
    } 

(. 4) the following is added in web.xml coding configuration: 
 
     
        GB2312 
     
 
(. 5) encoding filter configuration parameters. JspServlet set of Chinese encoding server.xml, add the following parameters:  
         
            javaEncoding 
            GB2312 
         
Similarly, the SSI may be provided, CGI file encoding parameters. 
(6) modifying server.xml, added in the Connector URIEncoding = "gb2312", as 
 maxSpareThreads = "75"  
enableLookups = "to false" the redirectPort = "8443" = acceptCount to "100"  
Debug = "0" connectionTimeout = "20000"  
disableUploadTimeout = " 
You can also add resource files to achieve international control.
  c) Chinese garbled database
    shown in the code database if a direct connection through JDBC, the configuration is as follows. 
jdbc: mysql: // localhost: 3306  / dbname useUnicode = true & characterEncoding = GBK?
If the source is connected by a data, first write the configuration file for the MySQL database, Context of
the configuration file as follows:
 
         type = "the javax.sql .DataSource "/> 
     
         
        Factory 
        org.apache.commons.dbcp.BasicDataSourceFactory 
         
         
            driverClassName 
            com.mysql.jdbc.Driver 
         
         
            URL 
          useUnicode to true = & characterEncoding = GBK]]> 
 
         
         
            for maxActive 
            100 
         
         
            maxIdle 
            30 
         
         
            maxWait 
            10000 
         
         
            username 
            the root 
         
         
WAS will encounter the same problem, the problem usually occurs jdbc or database level, the solution is the same as the Tomcat, not discussed here.
2. Query timeout problem
  because the database middleware applications in the process of joint use, the more cases db only as a resource pool, the passive response, the next step of action based on middleware application instructions, with which there is a the problem is, when our application after setting the timeout ended request related operations, but not in an agreed way to tell the end of database-related operations, resulting in a database of this proceeding should be terminated, the problem for the application brought two issues, first, a waste of system resources; second, if a time-sensitive applications, it may also have a negative impact on the business. For this problem WAS provides a good solution.
You can use the following method to set the query timeout:
webSphereDefaultQueryTimeout establish default query timeout, timeout before the query timeout in seconds executable SQL statements. If syncQueryTimeoutWithTransactionTimeout custom property is enabled, it will override this default during the Java Transaction API (JTA) transactions.
The default syncQueryTimeoutWithTransactionTimeout the remaining time JTA transaction as a SQL statement query timeout.
By default, the query timeout is disabled. The presence values of two data sources and custom attribute, the timeout value is calculated as: based transaction manager (TM) time-out setting, remaining time of the current JTA transaction syncQueryTimeoutWithTransactionTimeout
configuration specifies the absolute number of seconds webSphereDefaultQueryTimeout Then, using the calculated time-out of each SQL statement using the application data source configuration performed by setting a query timeout.
Configuration steps:
Open the management console;
Go to the data source WebSphere Application Server data source properties panel
a. Click Resources> JDBC> Data Sources> data_source
b. Click the WebSphere Application Server data source properties
, click Custom Properties under the "Additional Properties"
click New
in the Name field enter webSphereDefaultQueryTimeout
input to be used as the default query timeout in seconds in the value field. Timeout value in seconds meter. A value of 0 indicates the timeout is not
OK
, click New
in the Name field, enter syncQueryTimeoutWithTransactionTimeout, enter true or false in the Value field, the value of true indicates the remaining time JTA transaction as the default query timeout
click OK
to save your changes, these updates will take effect after the restart the server.
Above is a function of the standard JDBC API interface, Tomcat may be realized by this interface, but Was not so easy to implement, because this function has been Was packaging and integration.
Third, the diagnosis and debugging method
  In use Tomcat application development process, and the problem is complex and diverse inevitable, these laws do not mistake developers and managers need to have a solution to the problem. Tomcat log files can be flexibly configured, they are very helpful to analyze the problem. Each element in server.xml has debug attribute, can determine whether the log file by modifying the output value of the property. If the log file does not output is 0, you can set any value greater than 0, the greater the more the output log information. Some objects can log level to 9 or even higher, but most of the maximum of 3. If there is a problem in the process of using Tomcat, you can set the log level is between 1-9, restart Tomcat output to a log file. In Tomcat's logs directory usually contains several basic log files, standard output stdout.log, error output stderr.log, there are access_log, error_log like represent various object information log file. In case of problems, simply open the log output, in these documents can be found more problem. Of course, while log output is accompanied by a resource-intensive, it is recommended under normal circumstances is not open so many log output.
  In the face of WAS-related problems, also has similar functions and methods, but it was not as good as Tomcat on flexibility and fault diagnosis method of debugging. But fortunately we have IBM manufacturers, to carry out in-depth diagnosis of the problem for us.

Guess you like

Origin www.cnblogs.com/yachao1120/p/12030661.html