Posted by ezmobius
Fri, 29 Dec 2006 23:51:00 GMT
Here is a little tip that can drastically speed up your page loads for pages that have a lot of static assets. Especially for pages with tons of little images.
Most browsers will only open up 2 concurrent connections per cname. this means that if all of your assets are being served from http://example.com and you have a lot of little images and scripts on the page, the clients browser will only open two connections to example.com and pipeline or use those two connections to download all the assets on the page.
By using a wildcard subdomain or manually setting dns so that you spread out the static assets over a few different subdomains, you let the browser open two connections per subdomain so all the assets will download in a more parallel fashion. This can be the difference between your page loads lagging at the end while they load up all the little assets and having the page snap into place and seem a lot quicker to the user.
So if we use a simple little view helper method for all of our image urls we can spread the load out by faking the browser into thinking it is connecting to multiple servers. For example if we serve all our images from these subdomains:
asset1.example.com
asset2.example.com
asset3.example.com
asset4.example.com
This will give us 8 concurrent connections from the browser to the server for static assets which dramatically decreases page load time. The thing to watch out for is that you always want to serve the same asset from the same subdomain or else you defeat browser caching and won’t gain anything from this trick. So we will use an Zlib hash of the asset url modulo 4 to choose a subdomain. Here is a simple helper:
require 'zlib'
# balance images across many domains to force the opening of more connections
# updated to use Zlib.crc32 instead of md5 as per
# comment from David
def balanced_asset_url(asset)
idx = (Zlib.crc32(asset || "error" ) % 4) + 1
%!http://asset#{idx}.#{request.domain}#{asset}!
end
Then use it like this:
<%= image_tag balanced_asset_url('/images/foo.png') %>
By hashing the asset path we make sure that each time this helper is called for the same asset it will always return the same subdomain.
This technique is most useful when you have many objects on a page that need to make an additional http request each to render. By tricking the browser into making more concurrent connections when fetching assets we can speed up our page load times and make our sites seem more ‘snappy’
I’m sure you could make this into a nice little plugin or integrate it into the normal image_tag helper if you so desired. This is just an illustration.
Tags rails | 15 comments
Posted by ezmobius
Sat, 16 Dec 2006 18:49:00 GMT
I am happy to announce the release of Merb 0.0.8. This release is a huge improvement over the last release. There are too many changes to list. So here are some highlights:
* Performance optimization of mime parsing.
* Refactoring of entire codebase.
* reorganize layout of source files.
* Added GlobaleHelper that all view can use.
* Helpers named after the current controller will be available in the view as well as global helper.
* Added support for returning an IO stream from your controller.
* Merb::SimpleModel is a transactional yaml storage for smaller projects.
* Cleaned up the app_skeleton, it is now up to date.
* Added Merb::Const module to incapsulate constants
* Added HTTP status codes module
* Optimized and improved the ViewContext object
* Added rails session parasite mode
* Added new improved ActivceRecord session store. much faster
* Added Request object to encapsulate all helpers that use the headers to grab info
* Added merb_upload_hanlder for upload progress.
* Added merb_upload_progress class. if only one merb is being run then it will just load the upload prgress class in memory. When more then one merb is run, merb has a drb server that gets started and holds the state for the upload progress meter.
* Added merb_exceptions for custom, exceptions
* Added Kernel#aquire, like require on steroids with glob
* Huge improvements in the before/after filter code
* Added after filter capability to Merb::Controller.
I am working on a tutorial that I will post this weekend as a quick primer to getting started with Merb. The rdoc is improved though now and has some good information. The new implementation of befopre and after filters is really sweet too.
sudo gem install merb
rdoc: http://merb.rubyforge.org
Tags erb, merb, mongrel, server | no comments
Posted by ezmobius
Sun, 10 Dec 2006 23:47:00 GMT
Yup that all she wrote. Merb is going to stay merb. Sorry to the folks who wanted a new name. I like merb enough and it is already all over the codebase.
If you don’t think merb is a good enough name to sell your pointy haired bosses on then all you need to do is think back on the name mongrel. A lot of folk tried to get Zed to change mongrel to be something more enterprisy. Nowadays mongrel is an everyday household term. Just think, soon enough even your mom will know what merb is and she will undoubtedly think its a cute name ;)
Anyway, I’m glad people responded with support for the Merb name. I didn’t realize how much I liked the name until I started to consider alternatives. And we can always have nicknames for releases.
Also I have just finished registering #merb on irc.freenode.net . I will be hanging out in there most of the time. Come on over if you need help or want to talk merb.
Tags merb | 11 comments
Posted by ezmobius
Fri, 08 Dec 2006 21:48:00 GMT
Heya Folks. Now that merb is no longer a two day hack for file uploads I think it needs a little better name. I have ended up spending quite a bit of time on it and it is in a production worthy state and is indeed being used in production on some high traffic sites.
I think merb will always be its codename but I want to come up with a new public name for my framework.
So if you have any suggestions please leave a comment. Merb is currently at version 0.0.8 in trunk which will be released as a gem soon. I would like to have a new name for the framework by the 0.1.0 release that will happen in a few weeks.
So bring it on. What should we call this thing?
P.S. You can also come find me in #merb on irc.freenode with ideas, but please leave them here in the comments as well..
Tags merb | 10 comments