Ted Patrick > { Events & Community } > Adobe Systems


Speeding multiple image loading in Flash Player

Flash Player adheres to the HTTP 1.1 spec allowing only 2 connections per domain. Given this technical limitation there are a few very handy workarounds. One comes by using CNAME feature of DNS. It seems that is you add DNS CNAMES to a single domain, the browser and Flash Player allow 2 connections per listed subdomain even though they are technically the same HTTP server. In this case by simply adding several subdomains, the Flash Player can load multiple images and data in parallel over HTTP/HTTPS.

So instead of loading the following images:

http://mt3.google.com/mt?n=404&v=w2.43&x=0&y=1&zoom=15
http://mt3.google.com/mt?n=404&v=w2.43&x=0&y=2&zoom=15
http://mt3.google.com/mt?n=404&v=w2.43&x=0&y=3&zoom=15
http://mt3.google.com/mt?n=404&v=w2.43&x=2&y=4&zoom=15

These will load 2 at a time!

One might load these URLS:

http://mt0.google.com/mt?n=404&v=w2.43&x=0&y=1&zoom=15
http://mt1.google.com/mt?n=404&v=w2.43&x=0&y=2&zoom=15
http://mt2.google.com/mt?n=404&v=w2.43&x=0&y=3&zoom=15
http://mt3.google.com/mt?n=404&v=w2.43&x=2&y=4&zoom=15

These will load 4 at a time! A 2X performance improvement.

I am adding CNAMES to onflex.org to test this out.

More to come...

Ted :)

8 Responses to “ Speeding multiple image loading in Flash Player ”

  1. # Anonymous Marcelo Volmaro

    Hi Ted,
    I´m sure you know more than me on that subject, but... are you sure? I though the player uses the browser to fetch the data, so the number of connections is limited by the browser and no by flash itself. I tested an app i have made that fetches several images at time and saw that if you use IE things happens as you said, but using Opera/FF, i get more connections at the same time (depending on the number of connections the browser is set to allows, 8 in my case).  

  2. # Anonymous phillip kerman

    Yeah, what he said. I don't doubt that you looked into this, but it sounds it doesn't really add up. Plus, say it's not limited by the browser... would it really go faster? Naturally, one big download is faster than a bunch of little requests--though I realize that's a different point. I'm just saying that I'd love to see an example or results from a test.  

  3. # Anonymous Madarco

    As marcelo said, I've experienced the same thing, its seems that Flash use the browser settings.
    You can test it here:
    http://blog.madarco.net/34/flash-max-connections/
    change max-connections-per-server in the about:config in Firefox to see the difference.  

  4. # Blogger Theo

    This is an old trick in the Ajax world and it works well indeed. The URLs in the post seem to be from Google maps which use this trick.  

  5. # Blogger Ted Patrick

    The Player inherits this logic as it uses the browser loading over HTTP. Better still in Flash we can actually measure client bandwidth and programatically adjust the number of CNAMES in use. Say you are on a fast connection, opening more connections will work like Torrent, on a bandwidth limited machine there is a logical limit where there is an advantage. To fun, thanks AJAX! :)  

  6. # Blogger Aaron

    I've thought about using something like this before to get around the connection limit.

    Here's an issue that I ran up against. Unless you have a way to always request a certain image through the same CNAME, you end up with less cache hits and more bandwidth used.

    For instance, consider if you randomly spread your image requests over 5 CNAMES. When a user makes a repeat request for a particular image (page change, return visit, etc), there is an 80% chance that they will be randomly given a different CNAME and have to redownload the image.

    I still think that it's a good technique. Just have to consider the effect on cache hits. May a may not make a difference to your app.  

  7. # Anonymous Anonymous

    Aaron,

    Good point, that's why you implement a ImageCacher mechanism and a mechanism that registers completed downloads to see if one has already been done for that url ( that does not contain the domain ). That way if a non-image was already downloaded, it will always use the same URL and if an image was, then it is retrieved from the cache.

    Peace  

  8. # Anonymous Anonymous

    Anybody know how this affects AIR applications? Since it's not in the browser, does it allow more? What is the limit?  

Post a Comment



© 2008 Ted On Flash