Java File Transfer, EJB, SOAP or REST, performance comparison
I need to Transfer some files from one server to another, using java, and my performance is my top prio开发者_运维问答rity, which of these three options should be the right choice for me.
My 2 cents:
- EJB; given the assumption that you do not intend to wrap your EJB by a Web Service this will end up in RMI calls, which means your client must understand RMI. This may become a problem if your in the public internet because the protocol and ports may be blocked by certain intermediates (firewalls, etc.). You may run into scalability problems. Scale-out (clustering) is much easier if it comes to web protocols like SOAP or REST as load balancers and web servers understand those protocols.
- SOAP; definitly an option, as filesize can be up to 10mb you should consider MTOM to transfer the files itself. Embedding the files inside the SOAP message may require you to base 64 encode then, this depends on the file content itself (e.g. binary). In average base 64 enc results in an overhead of factor 1.3 (10mb > 13.33mb).
- With REST you will end up with the same problem as with SOAP regarding file encoding.
To conclude: it depends, I'd look at SOAP + MTOM first and do some tests. You may also consider the "not so hip" protocols like FTP, SFTP, FTPS. If you require guaranteed delivery you may want to look at Managed File Transfer (MFT) concepts: http://en.wikipedia.org/wiki/Managed_file_transfer
Using SOAP will, i think, involve base64-encoding the data, which will inflate it considerably - by 33%!
I don't think RMI base64 encodes, so that and a REST transfer with a binary body will be roughly equally efficient.
REST uses HTTP, which is a protocol whose implementations have been heavily tuned and thoroughly tested for transferring large files. JRMP and IIOP, the protocols used for RMI, are usually used with smaller requests, and so have not had that tuning. Therefore, i would lean towards using HTTP rather than JRMP or IIOP for this, and so towards using a REST PUT rather than RMI.
I would guess that the difference between RMI and HTTP would be small, though.
However, and above all, nothing beats a benchmark. I urge you to do a quick test of transferring a large file with all three options, and measure the speed.
When you talk about EJB, I assume you're actually referring to RMI (Remote Method Invocation) . It uses object serialization. If it is an option for your application, this is the best way to go.
With SOAP you have the overhead of the XML creation / parsing (computation wise). You also have the code headache of translating XML to/from your objects.
With REST, it ends up being the same issue as SOAP. However, this is the direction everyone seems to be going for most public APIs.
精彩评论