Socket vs rmi vs WebService performance and implementation

Source: Internet
Author: User

1. Comparison of WebService and EJB call Performance
2. Test Results
Number of data entries: Percentage consumed by the time difference between WebService and non-WebService
2 0.078 0.077 0.001 1.8%
11 0.125 0.113 0.012 9.6%
20 0.187 0.153 0.033 17.9%
30 0.222 0.215 0.007 3.1%
40 0.275 0.257 0.018 6.5%
80 0.477 0.422 0.054 11.4%
100 0.576 0.495 0.081 14.1%
200 1.070 0.920 0.150 14.0%
300 1.590 1.391 0.199 12.5%
400 2.157 1.810 0.348 16.1%
500 2.627 2.234 0.393 15.0%
600 3.067 2.630 0.437 14.3%
800 4.120 3.559 0.561 13.6%
1000 5.193 4.385 0.807 15.5%
1500 7.369 6.265 1.103 15.0%
2000 10.010 8.525 1.484 14.8%
3000 14.715 12.427 2.288 15.5%
4000 19.727 16.407 3.320 16.8%
5000 24.599 21.376 3.223 13.1%
8000 38.881 34.434 4.447 11.4%
10000 48.237 40.91147 7.325 15.2%
3. Conclusion.
It seems that WebService is about 15% more efficient than the RMI method of EJB.
RMI vs Socket
Generally, there are many development technologies based on the CS (client-server) software architecture. Commonly used include socket-based network programming, RPC, Java-based RMI (of course C # also has similar technologies), and CORBA. Here, we only compare socket-based network programming with RMI, which helps us to understand their respective application fields and help us select the appropriate technology when facing a specific problem. In addition, the discussion in this article can be considered as a language-independent thing, but only a discussion of the technology itself, you are developing with C ++, C #, or Java.
I. Introduction to RMI Technology
This article takes Java as an example to briefly introduce the RMI technology.
As Java distributed object technology, remote method calling has become one of the core Java APIs (in the java. rmi. * package) Since Java1.1 ). The introduction of RMI enables flexible and scalable distributed communication between Java programs. RMI allows Java objects to exist in multiple address spaces and distributed on different Java virtual machines. Each address space can be on the same host or on different computers on the network. Because remote method calls span different virtual machine boundaries to different specified address spaces, there is no global variable shared by the Object, which requires the Object Serialization API, it enables Java objects to be passed between different JVMs. Object serialization is especially designed for Java objects, which means that objects in Java programs can be accessed as object parameters (Serializable interfaces must be implemented for Serializable objects ). Combined with the RMI and Object serialization mechanisms, you can access objects and data that are beyond the boundaries of the local Java virtual machine. Through RMI, remote methods of remote objects can be called, and objects can be passed to these methods through Java object serialization mechanism.
The most basic Java model does not provide the ability to regard the Java objects on the remote host as part of the local Java program address space, and RMI makes up for this deficiency. In addition, because Java has nothing to do with the hardware platform, RMI can run smoothly without transplantation, regardless of homogeneous or heterogeneous systems.
RMI provides a simple and direct model for Distributed Computing On the Java platform. Because Java's RMI technology is based on the Java platform, it brings the Security and portability of the Java platform to distributed computing. RMI greatly extends Java's network computing capabilities. It provides a powerful system platform for compiling enterprise-level Internet/Intranet applications based on distributed object technology.
The architecture of Java RMI is as follows:

Ii. Based onSocketNetwork Programming
When you use socket for network application development, the general idea is "message-driven logic", that is, such a software system generally has the following features:
(1) communication between the client and the server relies on messages.
(2) Both the client and server need a message dispatcher to deliver the message to the specific massage handler.
(3) The client or server uses massage handler for logical Transaction Processing
See:

The socket-based software system has the following features:
(1) TCP-based communication
(2) the application itself needs to provide serialized processing of messages (the so-called serialization refers to outputting messages to the network stream)
(3) The communication protocol between the client and the server needs to be discussed in advance, that is, the message format of their interaction.
(4) because it is a message-driven logic, it is essentially difficult to target such a programming model.
III,RMI Vs Sochet
RMI technology comparison socket network programming mainly includes the following aspects:
1. RMI is object-oriented, while the latter is not.
Second,. RMI is bound to the language. For example, when you use Java RMI technology, both the client and server must use Java for development. The Network Programming of socket is independent from the development language, or even platform. Socket-based network programming allows clients and servers to use different development languages and platforms.
Third, from the network protocol stack perspective, the network programming of RMI and socket is at different levels. Socket-based network programming is based on the TCP protocol, while RMI defines its own application protocol on top of the TCP protocol. Its transmission layer adopts the Java remote method protocol (JRMP ). It can be seen that on the network protocol stack, the RMI-based application location is higher, which also determines that RMI will lose some flexibility and controllability compared with socket network programming, however, it brings more conciseness, convenience, and ease of use to application developers. For example, if you use RMI, you do not need to worry about how messages are serialized. You only need to use RMI like local method calls. The cost is: application developers cannot control the message serialization mechanism.
Fourth, this is the last difference. I think it is also important to compare the performance of the two methods, which often determines the technology you will use to develop your applications. The following is a comparison of TCP and RMI in Network-programming with RMI. The experiment mainly compares the two in terms of Network transmission bandwidth: 2 bytes of valid data are transmitted over the network. For TCP, a total of 478 bytes are additionally transmitted, whereas for RMI, 1645bytes are additionally transmitted.
The trace results of the two are as follows:
TCP:
46037> 12345 [SYN] Seq = 801611567 Ack = 0 Win = 5840 Len = 0
12345> 46037 [SYN, ACK] Seq = 266515894 Ack = 801611568 Win = 10136 Len = 0
46037> 12345 [ACK] Seq = 801611568 Ack = 266515895 Win = 5840 Len = 0
12345> 46037 [PSH, ACK] Seq = 266515895 Ack = 801611568 Win = 10136 Len = 1
46037> 12345 [ACK] Seq = 801611568 Ack = 266515896 Win = 5840 Len = 0
12345> 46037 [FIN, PSH, ACK] Seq = 266515896 Ack = 801611568 Win = 10136 Len = 1
46037> 12345 [RST, ACK] Seq = 801611568 Ack = 266515898 Win = 5840 Len = 0
RMI:
42749> rmiregistry [SYN, ECN, CWR]
Seq = 3740552479 Ack = 0 Win = 32767 Len = 0
Rmiregistry> 42749 [SYN, ACK, ECN]
Seq = 3749262223 Ack = 3740552480 Win = 32767 Len = 0
42749> rmiregistry [ACK] Seq = 3740552480 Ack = 3749262224 Win = 32767 Len = 0
JRMI, Version: 2, StreamProtocol
Rmiregistry> 42749 [ACK] Seq = 3749262224 Ack = 3740552487 Win = 32767 Len = 0
JRMI, ProtocolAck
42749> rmiregistry [ACK] Seq = 3740552487 Ack = 3749262240 Win = 32767 Len = 0
Continuation
Rmiregistry> 42749 [ACK] Seq = 3749262240 Ack = 3740552506 Win = 32767 Len = 0
JRMI, Call
Rmiregistry> 42749 [ACK] Seq = 3749262240 Ack = 3740552556 Win = 32767 Len = 0
JRMI, ReturnData
42749> rmiregistry [ACK] Seq = 3740552556 Ack = 3749262442 Win = 32767 Len = 0
JRMI, Ping
JRMI, PingAck
42749> rmiregistry [ACK] Seq = 3740552557 Ack = 3749262443 Win = 32767 Len = 0
JRMI, DgcAck
42749> rmiregistry [FIN, ACK]
Seq = 3740552572 Ack = 3749262443 Win = 32767 Len = 0
Rmiregistry> 42749 [FIN, ACK]
Seq = 3749262443 Ack = 3740552573 Win = 32767 Len = 0
42749> rmiregistry [ACK] Seq = 3740552573 Ack = 3749262444 Win = 32767 Len = 0
The result of the experiment is: RMI transmits the same valid data as TCP based socket, and RMI requires more network bandwidth (protocol overhead ). From this point, we can draw a general conclusion: RMI is mainly used for "calling" remote methods (how famous RMI is :)), and its technical connotation emphasizes "calling ", based on this, I can think of mobile computing and remote control. When your application does not need to transmit a large amount of data between the client and the server, RMI is a good choice, it is concise and easy to develop. However, once your application needs to transmit a large amount of data between the client and the server, such as an FTP application, RMI is not suitable. We should use socket.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.