How to optimise server performance

Why is web server performance optimization necessary?

  • Your website will get 11% fewer page views compared to your competitors and a 16% reduction in customer satisfaction
  • Your website conversions will decrease by 7%

How to optimize server response time? — Top 10 server optimization tips

1. Enable caching

  • OpCode cache — This is compiled results of previous search requests. Can save several seconds for complex applications like Magento or Drupal.
  • Memory cache — This stores bits of data generated by apps in system memory, and when the same bit of data is requested, it is served without the need for processing. Faster than OpCode cache, and ideal for large load-balanced sites.
  • HTTP cache — These are web server proxies that store whole HTML pages. So if the same page is requested, it is immediately served. This is by far the fastest and is ideal for high-traffic smaller web apps.
  • Application cache: Some applications such as Magento and Drupal store processed template files as pages to reduce processing time. This can be used in conjunction with any of the above caches.

2. Setting up a fast reverse proxy

  • Nginx — This is the hot favorite right now for the top busiest websites (as per Netcraft Jan 2018 survey). Users can use it for small and large content-heavy websites. It has proven to be reliable against traffic spikes and is a safe bet because of its stability and customizability.
  • Varnish — A bit more complex than Nginx to deploy, but sites with heavy traffic and a lot of content (eg. online publishers) can see considerable improvement with a response time using Varnish.
  • Lighttpd — If you have a monster site, and spikes in the usage of resources are common, Lighttpd can help you out. It’s lightweight and not likely to drag down the server.

3. Choose the right application server

4. Fine-tuning the webserver

  • Timeout — This setting determines how long Apache will wait for a visitor to send a request. This has to be set based on the server traffic. On average, busy servers wait up to 120 seconds, but it is best to keep this value as low as possible to prevent resource wastage.
  • KeepAlive — When “KeepAlive” is set to “On”, Apache uses a single connection to transfer all the files to load a page. This saves time in establishing a new connection for each file.
  • MaxKeepAliveRequests — This setting determines how many files can be transferred via a KeepAlive connection. Unless there’s a reason not to (like resource constraints), this setting can be set as “unlimited”.
  • KeepAliveTimeout — This setting makes sure that a KeepAlive connection is not abused. It says how long should Apache wait for a new request before it resets the connection. On average, for heavily loaded servers, 10 secs is a good limit.
  • MaxClients — This setting tells Apache how many visitors can be served simultaneously. Setting it too high will cause the wastage of resources, and setting it too low will result in lost visitors. So we set it at an ideal value based on the visitor base.
  • MinSpareServers & MaxSpareServers — Apache keeps a few “workers” on stand-by to handle a sudden surge of requests. If your site is prone to visit spikes, configure these variables. We’ve found that on average, the MinSpareServers value of 10 and the MaxSpareServers value of 15 to be a good limit in heavily loaded servers.
  • HostnameLookups — Apache can try to find out the hostname of every IP that connects to it, but that would be a waste of resources. To prevent that, we set HostnameLookups to “0”.

5. Turning on HTTP v2

  • Using a single connection instead of time-consuming parallel connections to transfer files.
  • Transferring important files first to complete a page.
  • Using compression to speed up header transfer.
  • Using binary data instead of bulky text data transfer.
  • “PUSH” ing all files needed to render a page before it is requested by the browser. It saves valuable seconds in sites using multiple CSS, JS, and images (which are all modern sites).
  • Switching the whole site to HTTPS. You’ll need to set redirects for site links. Also, you can save money by using free SSL from Let’s Encrypt.
  • Make sure your reverse proxies are also properly configured for HTTP/2.
  • Upgrade your web server to a version that supports server PUSH. (Nginx supports it in v1.13.9.)

6. Organizing the fragments of your database tables & optimizing server settings

  • max_connections — In multi-user servers, this setting prevents a single user from hogging the entire server. In heavily loaded shared servers, this limit can be as low as 10, and in dedicated servers, it can be as high as 250.
  • innodb_buffer_pool_size — In MySQL databases enabled with InnoDB, query results are stored in a memory area called “buffer pool” for fast access. We set this value anywhere between 50–70% of available RAM for MySQL.
  • key_buffer_size — This setting determines the cache size for MyISAM tables. This is set approximately at 20% of the available memory of MySQL.
  • query_cache_size — This is enabled only for single website servers, and is set to 10MB or less, depending on how slow the queries or query latency is at present.

7. Fix your DNS query speed

8. Trim down the critical rendering path of your website

  • Deleting unused themes and plugins.
  • Reducing the size of images.
  • Combining and minimizing JS and CSS files.
  • Compressing these files on disk.
  • Deferring files are not needed on the second scroll using “async” or “defer” methods.

9. Disable resource-intensive services

10. Upgrade your hard disk to SSD

Final Thoughts

--

--

--

A global community of software creators who want to influence how software is built.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Track Your Weight With Python

An open laptop with some programming code.

Everything You Need to Know About Django Models in Python

Comparing Big Data Performance with Different Data Lake Storages

How To Explore A New And Unfamiliar Codebase

How to conduct research design and developer outreach in 7 steps

A Promising Idea Towards Supporting Plugins for iOS App

From Preference to Purpose: the Forcing Function of COVID-19

Find Similar Cars — Marketcheck API

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Developer Nation

Developer Nation

A global community of software creators who want to influence how software is built.

More from Medium

Automating WordPress Application with MySQL Database on Kubernetes over AWS using Ansible…🎪🎁🎇

Encrypting passwords (via Node and Bcrypt)

Managing Docker with PHP client

FTP SFTP FTPS ต่างกันยังไง