Marcos Placona Blog

Programming, technology and the taming of the web.

Month: July 2009

Speed up yor website – Part 2 – The Free CDN

Reading time: 6 – 9 minutes

To continue with our series of website optimization tricks, I’ll talk a little bit more about Content Delivery Network (CDN), and will talk you though the steps of creating a totally free CDN for your website.
Basically, as I’ve already stated on my previous post, a CDN is an external network which specializes in serving static content. It normally consists of a few servers spread around the world, so the data will travel the shortest route to get to their destination based on Geolocation.
In other words, if you’re in Japan, why should you have to wait for the data to travel from Europe, if there’s a server just next door to you.

CDN With multiple=

What you can see from the image, is that you have all of your servers in a “Cloud of Computers“, and the requests are mapped to the nearest one. In some cases you have more than one server per country or region. The beauty of it, is that applications deployed on the cloud are highly scalable, and you normally don’t need to manage the servers, as they are managed by the provider.
There are some companies offering CDN for a very reasonable price, but today we’re gonna be talking about free stuff!
Before I start with this tutorial, I have to make it clear that the form of CDN we’re going to be using here, is not truly CDN, as it doesn’t offer a very high scalability, and hasn’t been developed for the sole purpose of serving static files, so it won’t have the same high performance of a service designated only for the task.
For some (like myself), it won’t make such a huge difference, as this method still is better than nothing, and is immensely faster than much servers around. I host my applications on my own VPS and don’t have bandwidth limitations. But for most people who use Hosting Companies and have limited bandwidth, this will be a huge improvement.

Step one – The Idea:

Google provides us with it’s wonderful Google App Engine. It’s free for anyone, you can store up to 500mb (enough for static content), and have about 5 million page views a month. Anything beyond it is charged (very tiny fee). Everybody knows Google, so you know they have servers almost everywhere. Put this all together, and you’ll get started.
To make this idea start to happen, simply create an account with Google App Engine. Simply use your Google login details, and and confirm your application with the code Google sends to you visa SMS (you need to have a mobile phone).
Now, you will need to download and install Python (it’s only required for the App Engine can run on your computer). I find Python 2.5 works better than Python 3, so you can get it from here.
It’s time to install the App Engine Client on your computer. Once it’s installed, you should be ready to go.

Step two – Create an Application:

Simply login to your newly created App Engine Account and click the button Create an Application

App Engine - Create Application
Give it a name and title, and then save it. Use a short name, as it will be you application’s handler, and you’ll access it by going to [app_name].appspot.com

Step three – Create your Application Folder:

If you are on a windows environment, normally the App Engine will be installed on “C:Program FilesGooglegoogle_appengine”. If not, it will be installed wherever you chose during installation.

Go to this folder, and create a new folder with the same name as the application you have just created on step 2.

You will now copy your assets folder into this folder. I like to keep the same structure, so by only changing one variable on my website, I can change the the domain it uses to look for images.

So if for example my website was looking for images at http://images.domain.com/images, I’d just change this variable to point to [app_name].appspot.com/images

So, on my folder I’ll have exactly the same structure as I had on my website plus a few files I’ll describe now:
app.yaml: this is our application configuration including URL’s and versions. More info here.

application: my-application
version: 1
runtime: python
api_version: 1
handlers:
- url: /images
static_dir: images
- url: /styles
static_dir: styles

Notice I’m specifying my static directories and their relative paths. You have to change it accordingly.

deploy.bat: This is a file I create for convenience. It executes command lines for me, so i don’t have to type them all the time I want to deploy. The contents of this file will normally be:

"C:Python25python" "C:Program FilesGooglegoogle_appengineappcfg.py" update "C:Program FilesGooglegoogle_appengine[app_name]"

Notice that on the first part of, I’m simply telling my script what I use when it comes to running python scripts. I then update my application by its name, and giving the application folder.

So manually it would be something like:

python "C:Program FilesGooglegoogle_appengineappcfg.py" update "C:Program FilesGooglegoogle_appengine[app_name]"

Step four – Deploying your Application:

Now it’s the big time. Simply double click the file called deploy.bat and you should see a screen like this:
Deploying to CDN

If it doesn’t give you any warning or error message, you should be ready to access your file.

If you decide to delete this file, simply delete it from the folder, and deploy again, and the file will be deleted. You don’t need to worry about minor versions, as the App Engine will deal with it for you.

To be honest, I never worry too much about the version numbers, as I’m constantly uploading stuff to my server. But if for some reason you do, you can simply change the “version” flag on you app.yaml file.

I hope this article is helpful. please don’t hesitate asking me questions or sending suggesting on how to improve this article.

Speed up yor website – Part 1

Reading time: 4 – 6 minutes

Assets such as stylesheets, images and videos are often the major hit taken by a webserver when a webpage is loaded. I’m often trying to improve my page loads by using published pages (flat html) and rewrites, so I don’t need to run a dynamic page when it’s not necessary.

Publishing usually brings a great deal of improvement, and browser cache and compression often help a lot too, but sometimes you just need to load assets on every single page load, and if you have lots of new users every day, browser cache will usually do very little, as this new users will need to hit the webserver and get the images for the first time in order to have it cached.

It’s been proved that loading assets from different domains helps “trick” the browser into multi-tasking, so it doesn’t have to wait until asset1 on the domain domain.com is loaded to start downloading asset2 on the same domain.

The first approach:

Most people simply create sub-domains such as assets1. domain.com, assets2.domain.com and so on. The assets are then called from the sub-domains, so the browser “thinks” it’s coming from a different location, when in reality, they normally always target the same structure.

This approach helps a lot, and if you, like me, enjoy monitoring this kind of thing, there’s a noticeable difference in loading times.

A downside to it is that you’re still hitting your webserver, and now even harder, as you’re making multiple connections at once to it. If you are loading images or small files, you shouldn’t have a problem, but things will start to get uglier if you try to load videos or heavier files.

Sub-domains approach

The second approach:

This consists in having a second webserver only to load assets while your main webserver deals with the other calls. A summary of this would be something like:

Two webservers

Basically what this horribly mocked-up image is trying to say is: You have two webservers using two different ports. The main webserver is the responsible for all the requests, but will redirect every asset call to your second webserver. What people normally do here is use two different kinds of webservers. Most commonly Apache (as the main webserver) and lighttpd as the secondary webserver. The reason why people use lighttpd, is because it’s incredibly light, and you won’t even notice it’s there.

The concept is really pretty, but it also means you’ll now have to maintain two webservers. The second one (lighttpd) should really be a one off, as once it’s configured, it will just serve static contents, but still, it’s two webservers on your server, and if anything goes wrong, it’s a bit difficult to find what and where it went wrong.

The third approach:

This is by far my favourite one. Basically it consists in hosting your assets somewhere else, where you wont have to maintain or keep an eye on performance, as this server’s primary task is to serve this kind of content. A “Buzz Word” really springs to mind here, as we are talking about the so called “Cloud Computing“. Basically it consists of a network of servers in strategic places. We call it strategic places, as the servers are located near you. Well, not near you, but from your IP, it redirects you to the closest server, from where you’re gonna be picking up the assets as they are needed.

It works pretty much as a load balancer, but based on location, instead of number of connections. It makes sure that the bits travel the shortest way in order to get to you. Works pretty much like terrestrial TV, where residences located closest to the tower will eventually get a better reception (signal) than the ones far away from it.
There’s a similarity with approach two when using this method, as it pretty much does the same thing, but uses an external server for serving and caching images. As previously mentioned, this servers are optimized for this task, therefore serving images much faster than the local server.

A representation of it would be as such:

Cloud Server

On part two, I will be showing how to have a free “CDN” for your server, and how to maintain it. I put the word CDN surrounded by quotes, as the approach I’ll be showing besides being a very common one, doesn’t really have all the benefits a true CDN has. But hey, it’s free!

New Railo admin leaked?

Reading time: 1 – 2 minutes

Of course not! The guys over Railo Technologies GmbH are pretty serious about their stuff, but today Mark Drew CEO for Railo UK “accidentally” let some pictures of the administration interface leak over Twitter.
Here’s a preview of what’s coming up on the new version.
It looks quite clean and slick in my opinion. Just the sort of thing I’d expect from these guys

Google Chrome OS and e few more changes

Reading time: 3 – 5 minutes

Yesterday the Google team posted an entry on all their blogs about a new operating system that is to come. They are going to call it Google Chrome OS.

The blog entry doesn’t really give away a great deal of details, but it states that this new OS will be open source, and be as lightweight as Google Chrome (the browser) is.
I have to be honest and say that initially I was very reluctant and sceptical about using Google Chrome, and it took me a while (about 6 months) to finally give up and give it another try.

In fact it’s been proving to be very stable, and really much faster than Firefox now. I still use Firefox on a daily basis, as it’s got all the plugins I need, and some of them are really necessary for my workflow, and I don’t know what I’d do without them.

Back to the OS announcements, I have a very “crude” impression that this is like another Linux distro, but with a Google’s face. I saw this comment on twitter this morning and really agreed with it.

Obviously I might be completely wrong and precipitated here, as I’ve been on Chrome’s release, but that was the impression the blog post left on me.
Also I wonder if it’s a way of Google saying “You tried to compete with us on our biggest tool, now we try to do the same on yours”. What I mean here is that Microsoft recently came up with Bing, which is a search engine aimed to compete with Google’s own search engine, and now it might be payback time.

Also, I really have a feeling that making it open source is not an act of kindness at all, as Google themselves said they will be getting help from the open source community to work on their OS. The reason why I think it’s just an act of kindness is the same reason why I think most open source projects (or at least some of them) do. They can get people to do things for them that they can’t really do.

I’ll give an example. Let’s say Windows has a very nice feature that Google Chrome OS doesn’t have. It would look bad, and sometimes be illegal for Google to go on and copy it. Of course people do it all the time, but wouldn’t it be more “graceful” if somebody else implemented this feature and signed his name? That way you can be exempt of every possible retaliation, as you’re only responsible for the core functionalities, and the ones you release, but you can’t really keep control of versions being released by “unscrupulous” third parties.

That’s more or less how I think things work, but obviously again I might be totally wrong, and this is only my sole opinion and point of view.
I really love Google and their products, and really think they have a great potential, and have some of the brightest minds, so by no reason they would need to copy anything or be competitive in an unfair way. I can really say the same about Microsoft, but still, that’s me.

On a side-note, I would like to say that after *only* 5 years in beta, Google Mail has finally reached a point where it’s no longer beta, and has its final version. It’s really funny and feels weird that they suddenly went from beta to final, as the email software has been stable for almost 4 years now.

The same happened to Google Calendar, Google Docs and Google Talk. It’s as if they suddenly realized that they forgot to remove the word beta of their logos, and did it all in one go.

I’d like to invite people to have a nice discussion and express their feelings on the comments about this whole Google Chrome OS vs Windows vs Linux.

ColdFusion 9 ORM and why I see deception

Reading time: 3 – 4 minutes

Not trying to be contradictive here (maybe a little bit) or rain on anyones parade, but I’ve been hearing and seeing loads of fuss from people who are “just waiting” for ColdFusion 9 ORM to be released, or some people who have projects where ColdFusion 9 ORM “would suit just perfectly”.

Whilst I find it to be perfectly normal and very exciting, I can also predict some deception is to come.

Obviously this doesn’t apply to everybody, but to some people who are expecting too much of it. When I say expecting too much of it, I mean people who think it will be a life saver, and everything that is ugly will become pretty.

ORM is no big news for us ColdFusion developers, as we’ve been using it for a while with Reactor and Transfer. But I still feel the need of explaining a few things in here to avoid people being mislead by the hype that is to come.

On a side note, I think it’s necessary to state that ColdFusion ORM will not write code for you (although it will save you many hours witting it), and it will not make your ugly “Select *” on the database any uglier or prettier than they are.

A few weeks ago, Terry Ryan from Adobe made a blog post stating that DBA’s are still necessary, and to be very honest, I think they will be necessary now more than they have ever been.

Also, we need to realize that ColdFusion 9 ORM will be powered by Hibernate, which is a pretty serious and very well tested ORM. It’s great news, as we are inheriting years of hard work on it, but it’s also worth mentioning that Hibernate can be dangerous if not properly handled.
Tell me something new Marcos, it’s like that with everything
You’re probably right, but I can already see lots of “bad” things being released in the very beginning, as some people will misjudge and probably misuse the ORM features only to stay afloat and be part of the “cool kids on the block” who use ORM powered applications.

We can’t forget about the KISS principle that has always been present in the ColdFusion life.
You might think I’m exagerating here, but from what I’ve been seeing, people could be very wrong (and precipitated) about the whole concept. Obviouly when things go wrong, they will blame on the technology, instead of blaming themselves for not planning ahead, and getting necessary education on what ORM really is.

One of the main gaps I can see here, is the lack of knowlewdge most of us have when it comes to Hibernate. I’ve been reading some stuff about it for a while, and can tell it’s pretty cool stuff, but the learning curve is a bit steep, and while you can probably have something up and running after a few hours of research and reading, you never know if that’s the right way to do it. In that sense, you could easily end up with the biggest overkill ever, when your project is the most up-to-date as it could go, but it’s simply not functional. Raise your hands if this doesn’t sound familiar.

I would like to hear some other people’s opinions on that matters, in regards to experiences. and if my gut feeling make sense only for me.