开发者

Java File Transfer, EJB, SOAP or REST, performance comparison

开发者 https://www.devze.com 2023-03-23 03:08 出处:网络
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:

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:

  1. 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.
  2. 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).
  3. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消