The Often Misunderstood Importance of Performance and Scalability
The perils of a sound bite. Whenever the subject of performance is brought up the same old quote by Donald Knuth is always dredged up:
“Premature Optimization is the root of all evil”
We all know that use of short sound bites is a dumbing down, yet we still do it out of convenience.
This sound bite is often used as an argument to avoid performance tuning altogether.
The surrounding quote explains what the point that Knuth actually means:
“Programmers waste enormous amounts of time…worrying about the speed of noncritical parts of their programs…We should forget about small efficiencies, say about 97% of the time…Yet we should not pass up our opportunities in that critical 3%“
This is something I learned from the video clip Focus on the Critical Path with Kyle Simpson stating this should be:
“noncritical path optimization is the root of all evil” -Donald Knuth
Adding that mature optimization is the path to success and it is immature (i.e. inexperienced and naive) optimization that will lead you down the wrong path.
Large companies such as Amazon have found that even a delay of one tenth of a second can cost their company tens of millions of dollars. There is a major link between sales and web performance. Because a slow user experience is a poor user experience.
This page covers any useful courses, online links and books I have come across on performance optimization and scalability. I have included links on some NoSQL products because two major reasons for their adoptions are performance and scalability.
“An acre of performance is worth a whole world of promise.” – Red Auerbach
0.1 second (or less) – feels instantaneous
1.0 second – limit for the user’s flow of thought to stay uninterrupted, even though the user will notice the delay. Normally, no special feedback is necessary during delays of more than 0.1 but less than 1.0 second, but the user does lose the feeling of operating directly on the data.
10 seconds – is about the limit for keeping the user’s attention. For longer delays, users will want to perform other tasks while waiting for the computer to finish, so they should be given feedback.
For further information on this see Response Times 3 Important Limits
Nik Molnar taught me Aarron Walter’s Hierarchy in the video clip Why Does Performance Matter?
This is based on the original Maslow’s Hierarchy but for Software Experience:
Aarron Walter has written a book called Designing for Emotion and you can read Chapter 3 here
“We’ve been designing usable interfaces, which is like a chef cooking edible food…Why do we settle for usable when we can make interfaces both usable and pleasurable?” – Aarron Walter
Walter’s Hierarchy is:
Pleasurable – Shows personality and enjoyable to use
Performant – Speed matters
Usable – Easy to learn and remember
Reliable – Solves it in the same way every time
Functional – Solves the problem in some way
So from this hierarchy we can see that performance is not the most important user need.
When developing software we should invest more heavily in addressing the needs for the software to be functional, reliable and usable.
However, if an application is not scalable, then once the system reaches a certain load, it won’t just be a performance problem anymore. Users will start seeing timeouts, and the software will no longer be functional for them. At this point the software has failed the users most important and most basic need of all.
Application scalability is not usually something that can be solved with a quick code tweak. It is usually a matter of getting the software architecture correct in the first place. If we get our design wrong, or fail to do the design work at all before we write our code, we can hit problems that are enormously expensive and time consuming to put right.
“If you can’t find the 5 hours to do the job right the first time, where are you going to find the 50 hours to do it right later?” – Steve McConnell, Rapid Development
That said, it is important to ask for performance requirements to be reassessed if they are found to be impractical or not economical. Some projects budgets have successfully cut by millions of dollars just by removing one performance requirement which was never actually important in the first place.
This is sometimes called HTML5 WebSockets but doesn’t have anything to do with the HTML5 spec. WebSockets are a communication protocol that offers faster “real-time” communication between client and server.
Communication over HTTP 1.1 tends to be very inefficient. One reason is cookies are transmitted in the header of each request, but modern applications tend to use many AJAX requests with small request bodies. This is a good use case for Web Sockets.
The specification never got passed Candidate Recommendation status (since September 2012) but is supported by most modern browsers.
See can i use for the latest status on browser support. WebSockets are not currently compatible with HTTP/2. All major languages and platforms have at least one library for using WebSockets:
On Github you can find all of the specifications that make up HTTP2.
Like Web Sockets and any other protocol, HTTP2 requires that both the client and the server support it. See Can i use for browser support.
With the most popular web servers, it is supported in Apache and Nginx, and will be supported in IIS 10 which will ship with Windows Server 2016. It is also supported by Jetty and Tomcat.
If you want to host a Node JS app you can use node-http2 or node-spdy
Andy Davies did a talk with Front End London in September 2015 that you can watch for free: The case for HTTP/2
What has been found is the performance increase of HTTP/2 on real world websites tends very limited because web sites are either optimised for HTTP/1.1 or not optimised at all. About 30 minutes into this talk Andy covers when do we optimise our web sites for HTTP/2 instead of HTTP/1.1?
All of the latest browsers now support HTTP2, but most servers do not yet support it. For latest information on this see
There is a great new course on Pluralsight called HTTP 2 Fundamentals by Hadi Hariri, which covers the theory behind the protocol as well as advice and code examples for implementing it in various languages. Because the semantics are the same between HTTP 1.1 and HTTP/2, mostly the same code works for both versions of the protocol.
However Server Push is a new feature in HTTP/2 and if you want to do that programmatically that will be a new experience for you. Additionally, optimising an existing application for HTTP/2 is effectively a process of de-optimization because the optimisations that tend to work for HTTP/2 can be counter-productive for HTTP/2:
– Domain Sharding, or multiple TCP connections, is no longer desirable. HTTP2 is single connection, and creating any connection involves TCP and DNS overhead.
– Bundling (concatenation of files) is a no-brainer in HTTP 1.1, but it adds complexity to the build process, and prevents the ability to cache on a per file basis. It also impacts rendering because the client needs to receive the entire bundle before each file within it can be processed. In HTTP/2 it is better to remove the concatenation.
– Similarly spriting of images has the same caching and delayed rendering disadvantages and aren’t appropriate anymore.
– Inlining of resources inside a HTML page is another practice with caching disadvantages. When moving to HTTP2 we should replace with Server Push
– Minification, and Content Delivery Networks are two approaches that remain best practices in HTTP2, so no change will be needed there.
This is all complicated by the fact that not all of your users will be running a browser that supports HTTP/2. You will need to make an assessment on whether to optimise for HTTP 1.1 or 2, or introduce more optimization but also more complexity by adding a different process for each protocol. A technique called Scout files is covered in the web performance section below.
Introduction to Web RTC
Web RTC is a specification for allowing clients to talk to each other peer to peer. This is usually done using a modern web browser. For the latest browser support see iswebrtcreadyyet.com. Web RTC implementations often use Web Sockets but can use HTTP instead.
The most obvious use case for Web RTC is high quality video conferencing, but there are many other possibilities for the emerging era of “Internet of Things”. Web RTC is made up of three main APIs:
MediaStream – handling access to users’ web cameras and microphones
RTCPeerConnection – enables audio and video calls with bandwidth management and encryption
RTCDataChannel – allows peers to generically pass data back and forth
One technology that was built on top of the RTCDataChannel is PeerCDN, which was bought out by Yahoo.
RTCDataChannel is very similar to WebSockets, but because peers are connecting directly, it is faster.
There are two chapters in the book Code Complete on code tuning.
SQL Server Performance
The course that I would most recommend to general purpose application developers is
SQL Server Indexing Basics. Although it does not cover every detail of indexes, it goes way beyond what most application developers know about indexes. At the time I watched it, it was almost all new to me.
I also highly recommend SQL Server Performance: Introduction to Query Tuning also by Pinal Dave and Vinod Kumar
Pinal Dave also teams up with Geoffrey Grosenbach to discuss performance tuning and Server Administration
Glenn Berry has a useful course called SQL Server 2012 Evaluating and Sizing Hardware. If you use or want to use SQL Server 2014 or even 2016, don’t let the title put you off, it describes a process that’s just as relevant for newer versions as well.
Kimberly Tripp has several courses on SQL Server performance. Unfortunately the only one I’ve watched so far is the first in the series: SQL Server: Why Physical Database Design Matters. I hope to watch at least one of her other courses in the future.
Joe Sack has a short course on SQL Server 2012: Nonclustered Columnstore Indexes. If you are interest in using these or what to find out what they are check it out.
Play by Play: Database tuning with Rob Sullivan covers Index Tuning, Server Configuration, Plans and Caching, other Server Tweaks, Analyzing Rollups and Tuning Search
If you use Entity Framework, and especially if you haven’t been using it for very long, I highly recommend Entity Framework Database Performance Anti Patterns. It has highlighted some big mistakes in my code and helped me fix them.
SQL Server isn’t the only good database solution available. For some problems you might find a No SQL solution is more performant and/or more scalable.
Nuri Halperin can give you an Introduction to Mongo DB
Oren Eini has written a good alternative to Mongo DB called Raven DB. Learn why you might want it with a tour of Raven DB
(Not sure how to categorise this one)
Jafar Husain (Netflix Tech lead, TC39 member) has a good talk on data access over the Web, discussing how a RESTful design is not suitable for many high performance web applications, the pros and cons of REST and RPC APIs, and introducing Falcor, called Why Falcor
.NET Performance and Scalability Optimization
The following two books come highly recommended by Steve Smith in the pluralsight course Web Application Performance and Scalability Testing
.NET Performance Testing and Optimization – The Complete Guide
Written by Paul Glavich and Chris Farrell, this is the more up to date of the two books
Improving .NET Application Performance and Scalability
You can download the e-book for free.
If you prefer physical media, the 1152 page paperback is selling pretty cheap.
Some parts of this book are out of date, but some parts remain current and useful. Advice that is tied to specific technology is always going to date much faster than more general advice and design principles. The chapters in this book are:
Chapter 1 – Fundamentals of Engineering for Performance
Chapter 2 – Performance Modeling
Chapter 3 – Design Guidelines for Application Performance
Chapter 4 – Architecture and Design Review of a .NET Application for
Performance and Scalability
Chapter 5 – Improving Managed Code Performance
Chapter 6 – Improving ASP.NET Performance
Chapter 7 – Improving Interop Performance
Chapter 8 – Improving Enterprise Services Performance
Chapter 9 – Improving XML Performance
Chapter 10 – Improving Web Services Performance
Chapter 11 – Improving Remoting Performance
Chapter 12 – Improving ADO.NET Performance
Chapter 13 – Code Review: .NET Application Performance
Chapter 14 – Improving SQL Server Performance
Chapter 15 – Measuring .NET Application Performance
Chapter 16 – Testing .NET Application Performance
Chapter 17 – Tuning .NET Application Performance
Most of Steve Smiths course is focused on the tooling in Visual Studio, so if you’re not a Visual Studio user I recommend only watching the first module “Measuring Web Application Performance and Scalability” which will give you a more general introduction to performance and scalability testing.
Links on the course are for “stevesmithblog.com” but this is now ardalis.com
This is the correct link for installing visual studio load test agents and controllers
Dr Joe Hummel also has two courses on Asynchronous Programming with the Transaction Processing Library. The first of these is Introduction to Async and Parallel Programming in .NET 4
You can also create performance problems for yourself if you misunderstand and misuse IDisposable. Elton Stoneman explains the Best Practices that will ensure you avoid those problems.
Steve Souders is a pioneer in web performance and in 2007 observed that 80-90% of the end-user response time is spent on the frontend. I recommend reading The Web Performance Golden Rule to fully appreciate this fact.
All of the following courses cover front and middle end optimizations rather than database query optimization:
Pluralsight/Frontend Masters courses (subscription only)
My article Two first time web performance authors that blew me away describes a couple of very good pluralsight courses on web performance: Tracking Real World Web Performance by Nik Molnar, and ASP.NET Bundling, Minification and Resource Optimization by Travis Gosselin. Travis’s course is specific to ASP.NET and Nik’s course is more general.
Kyle Simpson (getify) has a great Website Performance course which is available on both Frontend Masters and Pluralsight. The quality of the commentary throughout it was one of the things that lead me to request an interview with him on career strategy
Some of the things covered include:
- webpagetest.org (see Performance and User Experience)
- YSlow (see YSlow rules
- Image compression
- Data validation, JSON, and Resource loading
Kyle’s course includes a great commentary on measurement vs perception on a website, speed vs memory when as components of efficiency, and benchmarking vs optimization effort, in the clip How We Get Web Performance
Robert Boedigheimer has a similarly named Web Performance course. Robert covers many of the same topics as Kyle but is presented differently and is a much shorter course. If you are very short of time it’s probably better to watch the whole of this course than only part of Kyle’s course.
Jon Flanders’ Mobile First Responsive Web Design course includes a module on performance. If your users are accessing your site on a 3G or 4G connection (and of course increasing numbers are) then performance issues will be magnified for them.
I did not know how much slower inline styles were until Jon showed me this demo:
There’s a short course by Sam Saffron and Rob Conery called Speed: ASP.NET MVC Edition where Sam takes a sluggish application and performance tunes the hell out of it.
Fiddler is an enormously useful tool for performance testing, and Robert Boedigheimer has a course on learning Fiddler
If you’re just looking for some quick tips on some basics, check out the final module of Joe Eames’
Front End Web Development
There are also several performance courses which I have not watched, but might be worth watching. Search the library and see what you can find.
Steve Souders Talks
Ilya Grigorik Resources
High Performance Browser Networking is an excellent book by Ilya Grigorik and is available to view online for free. It includes coverage of HTTP/2. He also has slides from his velocity conference talk
Here are a couple of talks that he’s given.
There are many others. To find them all, you can subscribe to his YouTube channel.