Multiple Asset Hosts

Hey there,

I’ve been wondering if the assumption of four asset hosts for the sake of speed improvements is still valid.

Rails documentation about asset hosts:

Browsers typically open at most two simultaneous connections to a single host, which means your assets often have to wait for other assets to finish downloading. You can alleviate this by using a %d wildcard in the asset_host. For example, “assets%d.example.com”. If that wildcard is present Rails distributes asset requests among the corresponding four hosts “assets0.example.com”, …, “assets3.example.com”. With this trick browsers will open eight simultaneous connections rather than two

According to this (http://www.browserscope.org/?category=network), browsers are supporting typically 6 - 8 simultaneous connections per host nowadays. However, there’s an average max connection limit of 2 times of that.

Would it make sense to adjust the behaviour to generate only two asset hosts by default?

Cheers,

Sebastian

## On Perf Changes

Any performance improvements that have wide implications such as this, need to be benchmarked before they could be merged.

It’s not enough to do the research, we would need actual experimental proof that it works, provides a significant speed boost to justify the extra code costs and doesn’t have any major downsides.

If you add a new feature, it has to be tested. If you do a perf change, it needs to be benchmarked. It’s not good enough to shoot in the dark

## On multiple asset hosts

You can do this today. Rails accepts a proc for the asset_host that you can use to randomize an asset host however…

I looked into this extensively in the last 6 months and the general consensus is that it doesn’t help much, and even then it can make performance slower. Most connections are fast these days, but the overhead in making new connections is still there. Basically the browser doesn’t know that www.domain and www1.domain are the same and must connect separately. The result can be a slower page render.

Go ask igrigorik, he knows this stuff backwards and forwards (browser behavior and speed). Here’s two good articles

https://insouciant.org/tech/network-congestion-and-web-browsing/

http://perf.fail/post/96104709544/zealous-sharding-hurts-etsy-performance

## However

If you feel strongly, go test it. Build up repeatable benchmarks and instructions for others to run them. Don’t take my word on this, test it.

Domain sharding is still useful but our guidance is outdated. It's from a pre-SSL-everywhere, pre-SPDY era where browsers had low per-domain connection caps.

http://www.stevesouders.com/blog/2013/09/05/domain-sharding-revisited/

(TIL that chrome will "unshard" SPDY requests to different hosts with the same IP and SSL cert!)

The other thing to consider is that the connection overhead is much, much higher for mobile. If you have a responsive site and/or a high proportion of mobile visitors performance may be much worse for these visitors when using asset domains.

refs:

http://www.mobify.com/blog/domain-sharding-bad-news-mobile-performance/

http://chimera.labs.oreilly.com/books/1230000000545/ch08.html