{"id":6554,"date":"2017-07-26T16:00:03","date_gmt":"2017-07-26T19:00:03","guid":{"rendered":"http:\/\/blog.plataformatec.com.br\/?p=6554"},"modified":"2017-08-06T05:04:22","modified_gmt":"2017-08-06T08:04:22","slug":"the-fallacies-of-web-application-performance","status":"publish","type":"post","link":"https:\/\/blog.plataformatec.com.br\/2017\/07\/the-fallacies-of-web-application-performance\/","title":{"rendered":"The fallacies of web application performance"},"content":{"rendered":"
Web application performance has always been a hot topic, especially in regards to the role frameworks play in it. It is common to run into fallacies when those discussions arise and the goal of this article is to highlight some of those.<\/p>\n
While I am obviously biased towards Elixir and the role it plays in the performance of web applications, I will do my best to explore fallacies that overplay and underplay the role of performance in web applications. I will also focus exclusively on the server-side of things (which, in many cases, is a fallacy in itself).<\/p>\n
In my opinion, the most worrisome aspect of performance discussions is that they tend to focus exclusively on production numbers. However, performance drastically affects development and can have a large impact on developers. The most obvious examples I give in my presentations are compilation times and\/or application boot times: an application that takes 2 seconds to boot compared to one that takes 10 seconds has very different effects on the developer experience.<\/p>\n
Even response times have direct impact on developers. Imagine web application A takes 10ms on average per request. Web application B takes 50ms. If you have 100 tests that exercise your application, which is not a large number by any measure, the test suite in one application will take 1s, the other will take 5s. Add more tests and you can easily see how this difference grows. A slow feedback cycle during development hurts your team’s productivity and affects their morale. With Elixir and Phoenix, it is common to get sub-millisecond response times and the benefits are noticeable.<\/p>\n
When discussing performance, it is also worth talking about concurrency. Everything you do in your computer should be using all cores. Booting your application, compiling code, fetching dependencies, running tests, etc. Even your wrist watch has 2 cores<\/a>. Concurrency is no longer the special case.<\/p>\n However, you don’t even need multiple cores to start reaping the benefits of concurrency. Imagine that in the test suite above, 30% of the test time is spent on the database. While one test is waiting on the database, another test should be running<\/strong>. There is no reason to block your test suite while a single test waits on the database and this change in itself already improves build times.<\/p>\n If multiple cores are available, you should demand even more gains in terms of performance throughout your development and test experiences. The Elixir compiler and built-in tools will use multiple cores whenever possible. The next time a library, tool or framework is taking too long to do something, ask how many cores it is using and what you can do about it.<\/p>\n Once we start to venture into concurrency, a common fallacy is that “if a programming language has threads, it will be equally good at concurrency as any other language”. To understand why this is not true, let’s look at Amdahl’s law<\/a>.<\/p>\n To quote Wikipedia, Amdahl’s law is a formula which gives the theoretical speedup in latency of the execution of a task at fixed workload that can be expected of a system whose resources are improved:<\/p>\nFallacy 2: Threads are enough for multi-core concurrency<\/h2>\n