Why speed is more important than scalability

Software developers creating web applications like to talk about scalability as if it is totally unrelated to computing efficiency. They also like to argue that abstractions are important. They will tell you that their DBAL, Router, View Egine, Dependency Injection and even ORM do not have that much overhead (only a little). They will argue that the learning curve pays off and that the performance loss is not that bad. In this post I’ll argue that page loading speed is more important than scalability (or pretty abstractions).

Orders of magnitude of speed on the web

Just to get an idea of speed, I tried to search for a web action for every order of magnitude:

  • 0,1 ms – A simple database lookup from memory
  • 1 ms – Serving small static content from RAM
  • 10 ms – An very simple API that only does a DB lookup
  • 100 ms – A complex page load that calls multiple APIs
  • 1000 ms – Nothing should take this long… 🙂

But I’m sure that your website has pages that take a full second or more (even this site has). How can that be?

CPUs and web farms

Most severs have 1 to 4 CPUs. Each CPU has 2 to 32 cores. If you do a single web request, then you are using (at most) a single core of a single CPU. Maybe that is why people say that page loading speed is irrelevant. If you have more visitors, then they will use other cores or even other CPUs. This is true, but what if you have more concurrent requests than visitors? You can simply add machines and configure a web farm, as most people do.

At some point you may have 16 servers running your popular web application with page loads that average at 300 ms. If you could bring down the page load time to 20 ms, you could run this on a single box! Imagine how much simpler that is! The “one big box” strategy is also called the “big iron” strategy. Often programmers are not very careful with resources. This is because a software developers tend to aim for beautiful abstractions and not for fast software.

Programming languages matter

Only when hardware enthusiasts and software developers work together you may get efficient software. Nice frameworks may have to be removed. Toys like Dependency Injection that mainly bring theoretical value may have to be sacrificed. Also languages need to be chosen for execution speed. Languages that typically score good are: C, C# (Mono), Go and even Java (OpenJDK). Languages that typically score very bad: PHP, Python, Ruby and Perl (source: benchmarksgame). This is understandable, as these are all interpreted languages. But it should be considered when building a web application.

Stop using web application frameworks

But even if you use an interpreted language (which may be 10x slower), then you can still have good performance. Unless of course you build applications consisting of tens of thousands of lines of code that all need to be loaded. Normally people would not do that as it would take too much time to write. (warning: sarcasm) In order to be able to fail – against all odds – people have created frameworks. These are tens of thousands of lines of code that you can install on your server. With it your small and lean application will still be slow (/sarcasm). I think it is fair to say that frameworks will make your web application typically 10-100x slower.

Now let that be exactly the approach that is seen in the industry as “best practice”. Unbelievable right?

5 reasons your application is slow

If you are on shared hardware (VM or shared webhosting), then you need to fix that first. I’m sure switching to dedicated hardware will give you a better (and more consistent) performance pattern. Still, each of the following problems may give you an order of a magnitude of speed decrease:

  1. Not enough RAM
  2. No SSD disks (or wrong controllers)
  3. Using an interpreted programming language
  4. A bloated web framework
  5. Not using Memcache where possible

How many of these apply to you? Let me know in the comments.


This post will probably be considered offending by programmers that like VMs, frameworks and interpreted languages. Please, don’t use that negative energy in the comments. Use it to “Go” and try Gorilla, I dare you! It is not a framework and it is fast, very fast! It will not only going to be interesting and a lot of fun, it may also change your mind about this article.

NB: Go is almost as fast as the highly optimized C code of Nginx (about 10-100x faster than PHP).


6 thoughts on “Why speed is more important than scalability”

  1. Nice reference, the benchmarksgame. Java still has a reputation of being slow, mainly because that was true several versions ago, and because it’s running byte code. However, benchmarks often show that Java has come a long way. It’s fast and it has many nice constructs to build fast and maintainable applications.

  2. @Balthasar: Yes, ain’t it funny how languages can get a bad reputation and how that actually matters? Could this be caused by IT managers without a computer science background? Anyway, I totally agree with you, thank you for sharing!

  3. First, frameworks nowadays are modular: you can just load and use the things you need. You are not forced to use an ORM if you don’t want to, for example. In PHP there are frameworks available as C extensions, like Phalcon. These extensions are written in C. There is also HHVM, a virtual machine to run PHP code with a JIT compiler. There is a native language called Hack, there is Zephir to write extensions in a PHP like programming language, automatically translated in C.
    Performances are not so relevant, because hw is cheap and there are tools to manage a farm, like Chef. You need more power, you just clone your instance. A framework can help you to reduce drastically the development time, saving a lot of money. Gorilla, as I see, is a set of packages to handle routes, requests, cookies, sessions. etc. It doesn’t look different when compared to a framework. You will still need at least a template engine, don’t you think? Oh well, those are the components you can find in a modular framework. In Phalcon you have a dispatcher, a router, a template engine (Volt), etc.
    If your business grow up, you will probably need to hire programmers. How many programmers use Go compared to PHP, Ruby or Python? I’m not saying Go+Gorilla+some other library is bad, but when you start a business you have to make strategic choices, and I think performances, unless you are Facebook or Google, are something you don’t need to worry about, at least in the early stage. You’ll have time, and money, to even rewrite the entire application, in another language.

  4. @Filippo: Thank you for your comment, all valid points. There are several sides to this story and anyone can decide to choose either direction. To react to your first paragraph: things written in C, Hack or that use a JIT may bring better performance, but obviously at a cost (so does Gorilla). About templates in Go: I like the idea of compiled templates as described here: http://sunfmin.com/2013/03/22/a-compiled-template-for-golang.html

Leave a Reply

Your email address will not be published. Required fields are marked *