1

The program I’m about to write require downloading huge amount of HD images. The idea of the program disclaims downloading all of them in one HTTP request (it’s impossible to archive all of them into one file). For this reason, program will be requesting one image from server at once. I’ve found out, that HTTP/2 can help, because it supports multiplexing technology. All requests HTTP will be executed on one TCP connection. I found stats on this website encouraging: https://www.tunetheweb.com/blog/http-versus-https-versus-http2/. Presented tests of downloading 360 images show huge difference between HTTP/1.1 and HTTP/2. I started to configure my Apache server (v. 2.4.29) step-by-step with this tutorial: https://helgeklein.com/blog/2018/11/enabling-http-2-in-apache-on-ubuntu-18-04/. Downloading about 300 images with size about 1MB every, differences between those 2 versions of HTTP protocol are negligible. Tests were run on HTML file, that contains tags with hiperlinks to images stored on the same server.

HTTP/1.1 Example

HTTP/2 Example

Sizes of HTTP requests differ only in 0.1MB, and downloading time is greater. Tests were rerun on various browsers (Google Chrome, Opera, Firefox) and result always was similar – the change of protocol gave small profit. I also tried to use “HTTP Server Push” technique, but it also didn’t help in getting rewarding result.

Does using HTTP/2 protocol in certain problem is good step? Does configuration the server is incorrect? Does test environment well-constructed?

Andret2344
  • 653
  • 1
  • 12
  • 33
  • `it’s impossible to archive all of them into one file` why? – tkausl Mar 01 '19 at 08:26
  • @tkausl Because it's not obvious if I have to download all of them or not. Sometimes I have to download 5 of them, another time all, and next only half of them. Archiving every time doesn't sounds as a good plan – Andret2344 Mar 01 '19 at 08:30
  • It is quite easy to download files one after another. But if you want to show only images that are actually in view, you should use lazy loading technique, like this: https://appelsiini.net/projects/lazyload/ – ZorgoZ Mar 01 '19 at 08:33
  • @ZorgoZ described HTML website was only the simple test of protocols. Target requests will be send from mobile app, and the main point is to download lot of big images fast. But not to render them, rather to save them. I reject the possibility to download them dynamically on request from app (need all of them downloaded) – Andret2344 Mar 01 '19 at 08:40
  • @Andret Ok, that makes your goal clearer. What about streaming them? Concatenate on server side in a stream and split on client side. – ZorgoZ Mar 01 '19 at 08:41
  • @ZorgoZ sure, but HTTP does have multiplexing and the difference between HTTP/1.1 and HTTP/2 should be really big. I'm curios why it isn't... – Andret2344 Mar 01 '19 at 09:37
  • @Andret maybe. But you still want to push all data over a single TCP connection. It's throughput will be a/the potential bottleneck. No multiplexing or any other technique expect compression will have a positive effect on that (and as your data is already compressed, you might not get anything by adding an other layer - except if your images are frames of a video). So your choice should be the method that adds the less overall overhead to the data stream. – ZorgoZ Mar 01 '19 at 09:44
  • @ZorgoZ maybe it's the solution, but I'd like to understand why in the link i provided difference is 15s (HTTP/1.1) to 3s (HTTP/2). Why I cannot achieve this difference manually? – Andret2344 Mar 01 '19 at 11:15
  • @Andret Beware of your test environment. Run your test on a mobile device over a mobile network. A PC and wired or WiFi have much fewer constraints, thus you might actually experiencing the result of parallel channels. Use WireShark and see what's going on under the hood... – ZorgoZ Mar 01 '19 at 11:28

1 Answers1

3

Author of that site your linked to (https://www.tunetheweb.com/blog/http-versus-https-versus-http2/).

HTTP/2 allows better use of the network by allowing multiple downloads in near parallel through multiplexing. This can make dramatic difference for sites with large numbers of small bandwidth requests. This so because the TCP connection(s) are typically idle for a lot of the time under HTTP/1.1 as small requests make it back and forth between client and server so you are not making full usage of your available bandwidth. HTTP/2 fixes that to make better use of bandwidth.

For bandwidth-bound sites, HTTP/2 will have less of an impact as you are making the most use of your bandwidth anyway as, after a few requests, the bandwidth is fully used anyway. So there is no real inefficiency in the HTTP layer. Additionally the ramp up penalties of multiple HTTP/1.1 connections are worth while as you will be using those connections a lot more (unlike on a typical website where, by the time, you have opened the 6th connection, you often only use it for one request and close it again).

In fact HTTP/2 can work to your detriment in scenarios such as yours as approximately 100 resources can be downloaded in parallel getting 1/100th of the bandwidth and so downloading in batches of 100 instead of batches of 6 under HTTP/1.1. This means there can be a long delay and then 100 images show, when you may prefer images to be downloaded sequentially and so drip feed in slowly. Chrome prioritises sequentially for this reason, while Firefox works more in a parallel fashion. I do not know what your app does.

Shameless plug but I’ve actually published a book on this while thing, if you want a lot more detail on it: https://www.manning.com/books/http2-in-action. See the discount code at the top of my website for cheaper price!

P.S. I’d also question why you’d want to send a huge number of HD images to a mobile device. Seems wasteful especially on mobile which may have limited bandwidth and storage. At the very least you should only do this when the mobile device is on WiFi to reduce chance of your users incurring high costs. But that is all somewhat unrelated to your question (though with smaller “preview images” you may not be as bandwidth bound and so may start to see differences between HTTP/1.1 and HTTP/2).

Barry Pollard
  • 40,655
  • 7
  • 76
  • 92
  • why this answer give some generic insights in the right direction it is NOT an answer to the question. So how do you make use of the HTTP 2 with 300 – DATEx2 Mar 14 '23 at 15:35
  • That was not the question asked. I answered the question asked: "Does using HTTP/2 protocol in certain problem is good step?" and explained why, in this example of 300 x 1 MB images, there may be little difference between the two protocols - which is what the OP saw. For smaller images it will maker a big difference (as shown in the demo page the OP linked). – Barry Pollard Mar 15 '23 at 11:43
  • please reread this "The idea of the program disclaims downloading all of them in one HTTP request" – DATEx2 Mar 16 '23 at 15:01
  • I don't see a question mark in that sentence. That was not the question. The question as I read it was "why did they observe what they did, and should HTTP/2 have made a bigger difference". And I explained both. And the OP accepted the answer so he obviously felt it was answered. So, if you have another question then feel free to ask it. And feel free to downvote this answer if you honestly believe it doesn't answer the question if that makes you feel better. Or to add your own answer if you have a better answer. – Barry Pollard Mar 16 '23 at 21:55