Wat is Varnish? En maakt het je website echt 100x sneller? – Nucleus ChalkTalk

Wat is Varnish? En maakt het je website echt 100x sneller? – Nucleus ChalkTalk


Welcome to Chalk Talk a series of videos where we try to explain complicated technologies with just one chalk board. In this video we are looking at Varnish, which is a web accelarator you can introduce to your software stack to significantly improve the speed of your website. But first let’s look at what makes a website slow in the first place. Traditionally, if you have a user behind his laptop visiting your site, he is going to connect to your server. This is going to connect to a webserver – an Apache or an Nginx – that in turn will trigger a PHP process which is going to hit your code. Your code will talk to a database like MySQL or PostgresSQL. It might talk to a cache like Redis or Memcached or it might talk to external API’s that you don’t really have under control, like a Facebook or Twitter API or things like it. At the end of the day when all data is gathered your PHP will generate a response to be handed over to your Apache webserver. The response is basically the HTML code that your client is going to see. And it delivers that to your client. But he is not very happy! And the next person that comes to your webserver will trigger the exact same response, hitting Apache, followed by a PHP process, talking to the database or the API… You get the picture, it may take a while. And at the end of the day, the response being given to that user is probably the same as the previous one So why don’t we try to be smarter about that? If you start to get more and more visitors traditionally, you would use a bigger server. Or add another one. And another one. That doesn’t seem that efficient! So, how can we solve this with more finesse and more intelligence? We could introduce an additional layer on top of your Apache webserver, called Varnish. Varnish is a simple tool that is going to keep previously sent responses in memory, to be served faster to the next visitor So all this complicated logic will only be triggered once. The HTML response will be sent to Varnish. Varnish will sent it to the visitor and the next visitor will just talk to Varnish, asking “give me your homepage”, and it can deliver that in milliseconds, without talking to PHP MySQL, your API, you name it. So this makes Varnish a web accelerator. Technically it is a proxy, sitting between the client and your webserver, but it accelerates your visitors Varnish can also act as a load balancer. If the amount of visitors exceeds the capacity of a single server, you can add multiple web servers to serve all your visitors. Varnish can act as the middleman determining where that request should be sent. If your first webserver is unavailable, being in maintenance or offline, Varnish will take that one out of commission and send requests to other available servers. It also allows you to do rolling upgrades, where you gradually deploy your code to the next server without interrupting a visitor. By introducing Varnish, you can create a smarter solution for scalability Instead of throwing in more hardware, you introduce intelligence that eliminates CPU, memory and disk access. It makes everything a lot faster. If you introduce Varnish to your stack, you will have less PHP less MySQL, less database. Basically, less of everything, and more happy clients. The end result is a site that is a lot faster. Think in milliseconds instead of seconds. On top of that, you have the benefit that sites like Google and Bing, take the speed of your website as one of the indicators to determine the ranking of your site. So the faster your site, the higher you can rank. You can’t do that with just PHP You need to be smart and introduce a caching layer on top of that. In the next videos we’ll look at Varnish in depth. We will get into how you can use Varnish as a developer or sysadmin, develop a content strategy for your website and how to make integrating Varnish into your project a success. See you next time

Leave a Reply

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