Shall I use persistent connections to upload files in intranet?

276 Views Asked by At
  1. In intranet, the network is good
  2. Server A will send lots of files to server B by http service at the same time
  3. Http protocol is HTTP 1.1, which uses persistent connection by default
  4. [update] Use a connection pool to hold 100 connections
  5. [update] One connection sends a file at one time
  6. [update] Onnection will not be closed(persistent connection), and will be reused to send next file
  7. Each file has size of 7K to 30K

Question:

In the above condition, will persistent connection have better performance than non-persistent connections?

I ask this question because we found the connections would be blocked for a huge long time when upload files. I suggest to use non-persistent connection, since I think it's more stable, but my colleage inisit to use persistent connection, because he think persistent has better performance.


UPDATE

See the updated question, thank you ~

1

There are 1 best solutions below

3
On

In HTTP 1.1, your persistent connection allows pipe-lining but not parallelism. (See RFC 2616) That means that if you share your connection among 100 threads and each one sends a file, you will send those 100 files one at a time (in some ordering) and receive responses for each file in the order it was sent. You are not getting any advantage out of sending on 100 threads, because they're just lining up to send and receive one at a time.

You may be able to send faster using multiple connections, because that would allow them to actually run in parallel. But this is dependent on lots of other factors. Depending on your network, setting up and tearing down 100 connections may be slower than pipe-lining through one connection. Also, the server may not appreciate you opening 100 separate connections. Worse, the server may reject you only some of the time, which is a big headache.

I suggest taking the middle road: open, say, 5 persistent connections (using only 5 threads) and send 20 documents down each connection. HTTPClient has a BasicConnPool to do this sort of thing, though it may be too basic for your needs.