Home >Java >javaTutorial >What protocols does the java language support?
The following is a comparison of several commonly used communication protocols and protocol performance in the Java language
1.RMI
RMI call As expected, RMI is of course the fastest, taking the fewest milliseconds in almost all cases. Especially when the data structure is complex and the amount of data is large, the gap with other protocols is particularly obvious. In order to give full play to the performance of RMI, a test class was created. Instead of using Spring, the original RMI form (inheriting the UnicastRemoteObject object) was used to provide services and make remote calls. The efficiency was compared with Spring's RMI packaged by POJO. The results show that the two are basically the same, and the service provided by Spring is slightly faster. It is initially believed that this is because Spring's proxy and caching mechanisms are relatively powerful, which saves the time of re-acquiring objects.
2.Hessian
Hessian calls caucho company's resin server, which is known as the fastest server and has a certain reputation in the java field. As a component of resin, Hessian's design is also very streamlined and efficient, and the actual operation has proven this. On average, Hessian is about 20% slower than RMI, but this can only be reflected when the amount of data is particularly large and the data structure is complex. When there is medium or small amounts of data, Hessian is not slower than RMI. The advantage of Hessian is that it is streamlined and efficient, can be used across languages, and the protocol specifications are public. We can develop implementations of its protocols for any language. The currently implemented languages include: java, c, .net, python, and ruby. There is no implementation of delphi yet. In addition, Hessian is very well integrated with the WEB server. With the functions of the WEB server, it will have great advantages in handling concurrent access from a large number of users. Resource allocation, thread queuing, exception handling, etc. can all be guaranteed by a mature WEB server. RMI itself does not provide a multi-threaded server. Moreover, RMI needs to open a firewall port, but Hessian does not.
3.Burlap
Burlap and Hessian are both open source products of Caucho Company, but Hessian uses binary format, while Burlap uses xml format. The test results show that Burlap's efficiency is still acceptable when the data structure is not complex and the amount of data is medium, but if the amount of data is large, the efficiency will drop sharply. On average, Burlap's call time per millisecond is 3 times that of RMI. I think there are two reasons for its low efficiency. One is that there are too many XML data description contents, and the transmission volume of the same data structure is much larger. On the other hand, as we all know, parsing xml is relatively resource-intensive, especially This is especially true for large data volumes.
4.HttpInvoker
HttpInvoker is a JAVA remote calling method provided by Spring Framework, which uses java's serialization mechanism to handle the transmission of objects. Judging from the test results, its efficiency is still acceptable, basically the same as RMI. However, it can only be used for communication between JAVA languages, and both the client and the server are required to use the SPRING framework. In addition, HttpInvoker has not been tested in practice, and no projects that apply this protocol have yet been found.
5.web service
This test selected the AXIS component of apache as the implementation of WEB SERVICE. AXIS is relatively mature and established in the field of WEB SERVICE. In order to only test the time of data transmission, encoding, and decoding, both the client and the server use caching, and the object only needs to be instantiated once. However, test results show that the efficiency of web service is still 10 times slower than other communication protocols. If you take into account the transfer of multiple references pointing to the same object, web services lag even further behind. Because RMI, Hessian and other protocols can pass references, and the number of references a web service has depends on how many copies of object entities it has. The excessive redundant information transmitted by the Web service is one of the reasons for its slow speed. Monitoring found that for the same access request, describing the same data, the amount of data returned by the Web service is 6.5 times that of the Hessian protocol. In addition, the processing of WEB SERVICE also takes a lot of time. The current XML parser is generally not efficient, and processing xml <-> beans takes a lot of resources. From the test results, remote calls are faster than local calls, which also shows that the time is mainly spent on encoding and decoding xml files. This is more serious than redundant information. Redundant information only occupies network bandwidth, and the resource consumption of each call directly affects the load capacity of the server. (MS engineers once said that WEB SERVICE cannot load more than 100 concurrent users.) During the test, it was also found that web service coding is not very convenient. For non-basic types, serialization and deserialization classes need to be registered one by one, which is very difficult. Troublesome, generating stub is more tiring and not as smooth and concise as spring RMI/hessian processing. Moreover, the web service does not support collection types and can only use arrays, which is inconvenient.
The above is the detailed content of What protocols does the java language support?. For more information, please follow other related articles on the PHP Chinese website!