Blog: http://elf8848.iteye.com
Struts2, springmvc, and Servlet (JSP) performance comparison tests.
Servlet's performance should be the best and can be used as a reference. Other tests should be aligned with it and should be referenced.
As a programmer, you must have a basic understanding of the performance of each framework, so that you can make correct decisions when selecting a framework.
Do not yell at anything during the test, because these are the basic knowledge of Java programmers. Everyone needs to know.
Bytes ---------------------------------------------------------------------------------------
Read "do you want to build a website that can withstand 5 million PVS per day? This article describes some basic concepts of testing. There is a good or bad standard before the test starts. Use this standard to test your program.
Bytes ---------------------------------------------------------------------------------------
Test Environment Description:
Server: 4G memory, Xeon 3.0 (4-core hyper-threading) CPU, Windows 2003
Testing Machine: 2 GB laptop memory, p8600 dual-core CPU, Windows XP
Network: MB LAN
Test software:
Jmeter 2.3.4 allocated MB of memory
Tomcat 6 default memory size
Bytes ---------------------------------------------------------------------------------------
The test configuration is as follows:In fact, jmeter is still very weak. I open "synchronizing timer", "view result tree ", any one of "view results in a table" will cause performance degradation in the test results and a small number of Request Response errors (probably because there are too many threads), so it is disabled. Only cookie manager is enabled.
Bytes ---------------------------------------------------------------------------------------
The description of the tomcat6.0 configuration file should be clear before testing.
The default server. xml file is as follows:
XML Code
- <Connector Port = "8080" maxhttpheadersize = "8192"
- Maxthreads = "150" minsparethreads = "25" maxsparethreads = "75"
- Enablelookups = "false" redirectport = "8443" acceptcount = "100"
- Connectiontimeout = "20000" disableuploadtimeout = "true"/>
Enablelookups
Whether to allow DNS query. When a web application needs to use the Domain Name Server to find the machine name and convert it to an IP address. DNS query will be used, and the network needs to be occupied for a long time
Maxthreads
The maximum number of threads that can be created by Tomcat. Each request must be processed by one thread. The original 150 is too small, and the concurrency will exceed this threshold during testing.
Acceptcount
Specify the number of threads that can be used to process requests. The number of requests that can be placed in the processing queue is the number of requests queued. Requests that exceed this number will be rejected.
Connnectiontimeout
Network Connection timeout, in milliseconds. If it is set to 0, it indicates that the request Never times out. This setting has potential risks. Generally, it can be set to 20000 Ms.
Minsparethreads
Number of threads created during Tomcat Initialization
Maxsparethreads
Once the idle thread in the created thread exceeds this value, Tomcat closes the socket thread that is no longer needed.
Note: The value of maxthreads is set to 500, that is, Tomcat can use up to 500 threads to process 500 concurrent threads at the same time (the server CPU is good, 500 is OK ), do not wait in line to avoid affecting test scores. Prepare for the following stress tests.
--------------------------------- The test has started -------------------------------------------
Server CPU usage 10% during testing
During the test, the CPU usage of the testing machine is 100% (the testing machine is not good, mainly because the jmeter performance is average and the memory is consumed. The p8600 dual-core CPU of the testing machine is still very strong)
This is the case every time the CPU is tested.
Test 1: JSP page -- 2213 requests/second
100 concurrency, 100 cycles, a total of 10000 requests, a kb JSP page is requested.
Test 2: JSP page -- 1889 requests/second
100 concurrency, 100 cycles, a total of 10000 requests, request a servlet controller, verify the permission (very simple), a new action, and then forwarded to a size of 3.34kb JSP page.
Test 3: HTML page -- 2607 requests/second
100 concurrent requests, 100 loops, a total of 10000 requests, requesting a 3.2kb HTML page.
Test 4: HTML page -- 833 requests/second
100 concurrent requests, 100 loops, a total of 10000 requests, requesting a 13.4kb HTML page. Compared with the above, the file is a little bigger, and the network card is full. The network card has become a performance bottleneck and RPS has dropped a lot !!
Test 5:Spring MVC2012 requests/second
100 concurrency, 100 loops, a total of 10000 requests, a spring3 MVC action request, and then forwarded to a 0.8k JSP, the content is simple HTML
Test 6:Spring MVC1800-1924 requests/second
100 concurrency, 100 cycles, a total of 10000 requests, a request for spring3 MVC action, two parameter types converted to int, date, a new list, and then forwarded to a 1.3k JSP, use the jstl label to display the content in the list.
The jstl label content is as follows. It seems that jstl labels have good performance.
Java code
- <C: If test = "$ {empty list}">
- <Tr>
- <TD align = "center"> no record! </TD>
- </Tr>
- </C: If>
- <C: If test = "$ {not empty list}">
- <Tr>
- <TH> iteration count starting from 1 </Th>
- <TH> number of iterations starting from 0 </Th>
- <TH> product name </Th>
- </Tr>
- <C: foreach items = "$ {list}" Var = "item" varstatus = "S">
- <Tr bgcolor =$ {S. Index % 2 = 0? "# E2e2e2": ""}>
- <TD align = "center" >$ {S. Count} & nbsp; </TD>
- <TD align = "center" >$ {S. Index} & nbsp; </TD>
- <TD align = "center" >$ {item} & nbsp; </TD>
- </Tr>
- </C: foreach>
- </C: If>
Test 7: access an image (srping method 1) 1997 requests/second
100 concurrency, 100 loops, a total of 10000 requests. Because I use spring3 MVC, intercept/, so the image cannot be accessed, so I added:
XML Code
- <Servlet-mapping>
- <Servlet-Name> default </servlet-Name>
- <URL-pattern> *. jpg </url-pattern>
- </Servlet-mapping>
Use the default servlet to access the 2.5k image.
Test 8: access an image (srping method 2) 1967 requests/second
100 concurrency, 100 loops, a total of 10000 requests, because I use spring3 MVC, intercept/, so the image cannot be accessed, so added:
<MVC: Resources Mapping = "/images/**" location = "/images/" cache-period = "31556926"/>
To access the K image, it will take a matching interceptor of spring.
Test 9: struts2 uses dozens of requests per second using the officially provided sample program (using the struts2 tag)
100 concurrency, loop 1 time, no loop 100 times, because the response of strtus2 in this test is too slow, I can't wait, so the test sample of a single URL is reduced from 10000 to 100. there are a total of 11 URLs and 1100 samples.
"Spring" uses the URL of the previous "Test 5", which is put here for comparison with strtus2.
"Html" uses the URL of the previous "Test 3", which is put here for comparison with strtus2.
"Struts2-1" uses the official built-in sample project named struts2-blank-2.1.8.1.war
"Struts2-2" uses the official built-in sample project named struts2-showcase-2.1.8.1.war, where I randomly select an action for testing
"Struts2-3" Same as above
"Struts2-4" Same as above
"Struts2-5" Same as above
"Struts2-6" Same as above
"Struts2-7" Same as above
"Struts2-8" Same as above
"Struts2-9" Same as above
Struts2 has not been optimized. It uses official examples. The test results of struts2 are not ideal. Here is a reference. "Struts2-1" is struts2 in the test result is the highest, but not very ideal.
Test 10: struts2 official sample programs (using the struts2 tag -- S: Property) 1192 requests/second
The last test results were too bad, and the next day, I thought about it again and started a retest, using the struts2-blank-2.1.8.1.war example officially provided by struts2.
Access the following action: http: // 192.168.0.5/struts2/example/helloworld. Action. The action content is simply forwarded to a JSP.
The default action in the official example is used. I have not modified it. The result is as follows:
Here we will talk about the content in the forwarded JSP, which has the struts2 tag, as follows:
XML Code
- <S: property value = "message"/>
- <S: URL id = "url" Action = "helloworld">
- <S: Param name = "request_locale"> en </S: param>
- </S: URL>
- <S: a href = "% {URL}"> English </s: A>
TEST 11: struts2 official sample programs (without the struts2 tag) 1976 requests/second-Excellent
I changed the content of the JSP file in "test 10", deleted all struts2 labels, and output only one line of text. The test result is as follows:
My God, the performance exceeds my imagination. The performance is so good that it meets my requirements. It seems that the struts2 tag has slowed down.
Test 12: struts2 official sample programs (using the struts2 tag -- S: Form) 426 requests/second
To reproduce the phenomenon, I changed the JSP in "test 10" and used other struts2 labels in JSP. The test results are as follows:
The labels used are:
XML Code
- <S: Form Action = "login">
- <S: textfield key = "username"/>
- <S: Password Key = "password"/>
- <S: Submit/>
- </S: Form>
========================================================== ==================
Conclusion:
The struts2 framework has good performance, but the tag performance of struts2 is too bad. Avoid using the struts2 label.
Struts2 uses the value stack, ognl expression, and struts2 tag library, which can seriously degrade the performance. If you want to avoid or reduce the use of these, the performance is still very good.
The performance of struts2 multi-layer interceptor and multi-instance action is good, which is not the cause of performance problems.
Note: none of the above tests have databases or complex services. The content in action and JSP is very simple. The purpose is to test the performance of MVC.
Bytes ---------------------------------------------------------------------------------------
Other test articles:
Http://zhaoshg.iteye.com/blog/356231
Http://www.iteye.com/topic/679543
Comparison of MVC Framework Performance
Http://wenku.baidu.com/view/148d7e34eefdc8d376ee32ac.html
Spring3mvc and struts2 comparison
Http://www.iteye.com/topic/646240
Bytes ---------------------------------------------------------------------------------------
Appendix: Performance Test comparison of several tags and framework combinations for parsing data
I. Data
Data is obtained by querying the log table. A total of 1302 pieces of data are obtained. The queried data is put into a static list to ensure that the data in each request is the same.
The elements on the test page are the same, but the data retrieval method is different.
Ii. test objectives
1. Performance of using the struts2 tag on the JSP page;
2. Performance of using jstl labels on JSP pages;
3. Use the struts2 tag on the freemarker page;
4. Performance of using jstl labels on the freemarker page;
5. Use its own data loading method on the freemarker page for performance.
Iii. Comparison of loading time
Time: MS Note: Each comparison is performed in the same order in the same time period in the following ways
|
Struts2 |
Jstl (c) |
Freemarker-struts2 |
Freemarker-C |
Freemarker |
First time |
306 |
58 |
1618 |
|
41 |
Second |
202 |
52 |
1643 |
|
39 |
Third time |
211 |
58 |
2047 |
|
36 |
Fourth |
196 |
49 |
1621 |
|
28 |
Fifth |
218 |
52 |
1607 |
|
40 |
Sixth |
303 |
331 |
1857 |
|
45 |
Seventh |
210 |
50 |
1671 |
|
33 |
Eighth time |
311 |
51 |
1699 |
|
47 |
Ninth |
462 |
55 |
2180 |
|
37 |
Tenth |
218 |
46 |
1721 |
|
42 |
Average Value |
263.7 |
80.2 |
1766.4 |
|
38.8 |
Remove the highest and lowest |
223.75 |
53.125 |
1547.125 |
|
39.125 |