Posts tagged server

Should you use Memcache if you are already using Opcache?

Caching systems play a pretty important role in optimizing website performance, these work by storing frequently accessed data or resources in memory or disk, reducing the need to fetch them from the server or database repeatedly, this is of course on the server side, externally you can always cache with CDN (content distribution network) or other type of worker systems (these can do calculations), the combination of these both internal and external caching systems enhance website responsiveness, reduce server load, and improve scalability, contributing to a smoother user experience, and thats what we all want, right!

Im talking about this because I’ve been a big fan of Memcache/Memcached for years, but with opcache im kinda in the fence if i need to keep using both, because both do the same thing in different ways as well as different things all at the same time, in the sense that they overlap quite a bit and as we all know a caching system is useful to the point that it adds noticeable more performance for little extra resources, if it’s just adding a bit more performance, then its adding more complexity and less overall performance (since the caching system to work needs to use resources as well), so let’s check both of these caching systems, and see if you reach the same conclusion i did:

OPCache

    • OPCache is a bytecode cache for PHP scripts. It caches compiled PHP code in memory, which helps in speeding up the execution of PHP scripts by avoiding the need for PHP to recompile the scripts on each request.
    • OPCache improves PHP performance by reducing the time required for parsing and compiling PHP scripts.
    • OPCache is primarily focused on optimizing the performance of PHP code execution.

Memcache

    • Memcache, on the other hand, is a distributed memory caching system. It is used to store key-value pairs in memory across multiple servers.
    • Memcache is often used to cache data that is frequently accessed or that doesn’t change frequently.
    • Memcache is primarily focused on caching data from a database or expensive computation results, thus reducing the load on the database and improving overall application performance.

So now, regarding whether you should use Memcache if you’re already using OPCache, this is kinda the way i see it:

  • You can still use both:
    • If your application has a need for caching data that doesn’t change frequently, or if you want to reduce the load on your database by caching frequently accessed data, then using Memcache alongside OPCache can be beneficial.
    • OPCache will optimize the execution of your PHP scripts, while Memcache can cache data to improve overall application performance.
  • Maybe it’s not really required:
    • However, if your application doesn’t have a significant need for caching data or if it’s a small-scale application where caching data in memory isn’t critical, you might not need to incorporate Memcache, also of course if you don’t use a database then Memcache has less uses.
    • While OPCache alone can still provide performance benefits by caching and reusing compiled PHP scripts.

So in that sense seems like in a vacuum more often than not it’s best to use both, you use OPcache to cache php and then use Memcache to cache database data and computations, however that is in a vacuum, when you have other caching like nginx/litespeed/server side caching, local page caching, cdn’s like cloudflare, i kinda have a sense that both opcache and memcache give you just a small boost, so the more important point i guess it’s that it depends a lot on your site and application needs.

Let’s say if you have a normal well cached wordpress site (cache plugin and maybe cloudflare), thats updated daily im not sure you really need opcache and memcache, at all, but if i had to choose i would go with opcache since it seems the more light of the two and also not all requests are to the database (ie there are always way more php requests than database requests), but if i have a site or app that cant be cached often, then yes having both running seems like the best choice, even if i still caching locally or with a cdn, hope this made sense hahaha 🙂

Why use a 3 Tier Backup System?

We all know backups are important, if shit can happen, shit will happen, they are important both online and offline, but if you are hosting a site or several sites, its important to have a backup strategy, that’s why S2R created the 3 Tier Backup System (sounds way more exciting than what it is):

1) Hosting Provider Backup System

  • Choose a hosting provider that makes backups, having RAID and high availability and failover hardware, that’s all cool for performance and redundancy, but backups should be expected and not on the same hardware as the server (offsite or high end backup software is a plus), having backups from your host eases most problems and makes most disasters easier to handle, as such this is the first backup tier.

2) Offsite Backup System

  • Have a cheap vps or backup account from another hosting provider (if he also provides backups that’s a plus), then use your hosting panel or rsync or whatever backup system you prefer to use to make and transfer backups to this box, we normally choose a weekly schedule for this (running on weekends when traffic is low), there is no need for daily copies, cause the goal is to have a weekly clean backup, of course we store 3 backups, so 3 weekly backups are always available on the server, the idea is to use this encase your hosting provider goes bankrupt or closes your account for some reason (nowadays its more likely than you think), and you get cut off from your first tier backups, so therefore this is the second tier backups.

3) Local Backup System

  • This one is also easy to understand its a local backup of the accounts, in my case its to my custom made backup system (2TB mirrored to another 2TB, way more than enough for my sites and personal files + Mozy Backup of all of this), similar to RAID, this is done also weekly (could be done only monthly), this is done for the simple reason of peace of mind and safety, i never needed it, but there is no such thing as too many backups and having one locally guarantees that whatever happens to your sites they will always be able to comeback from any disaster, so this is the final third backup tier.

With a three tier backup system, it might look a little paranoid, and you might take some time and money to build it, but now that its done, its easy to add new sites and the peace of mind it gives is priceless, and now i can eat right in front of the computer hahahah ^_^

Choosing the right Apache? Apache 2.0 vs Apache 2.2

Well i ordered a new box and found out that it was running Apache 2.0.63, a very stable version of Apache (still used by lots of webhosts), but since like a year ago, i’ve moved to the 2.2 branch, so to decide what was the best choice i decided to do some testing between both version to choose, humm performance wise?, and yes i know 2.2 is much better regarding speed, but performance is not just about speed, so i just installed one and then the other, did some tests and let it run for a full 24hours midweek (cause weekends the traffic drops a bit)

So what are the results, interestingly enough… im gonna make some charts ^_^

Average 24h CPU Load (Restricted to 1CPU)

Average 24h Memory (Restricted to a total of 1GB)

Average Requests of File Types

Ok charts are cute but were are the numbers? well there isnt a point or need really, since the site hosted (and test files) on the box are not a perfect benchmark of Apache’s abilities, this should be considered above all a real world test, than a well measured test, but we can take a conclusion out of this, just looking at the charts, Apache 2.2 branch does seem to perform faster than the Apache 2.0 branch, although that performance increase is traded by a slightly higher cpu and memory consumption (about 0.3% memory increase and about a 6% CPU load increase ), hummm i can live with that,  2.2.15 WIN! hehehe, besides newer software has a tendency to bring better performance and security, and in the long run thats always smart thinking.

How to Perform a Server Move Without Downtime

Moving data between two servers without downtime requires some careful planning and execution. I’ve done this a thousand times, its also a good benchmark on the quality of your backups, so lets check my guidelines to a smooth server move!

Backup your old server – First, you need to make a fresh backup of your old server, this will guarantee that if something goes wrong you will still have a way to go back, you will have some downtime but nothing is loss, so start with a new backup.

Set up the new server – You need to prepare the new server to ensure it is fully configured and ready to receive the data. This includes installing the necessary software, configuring the server environment, and optimizing performance. Think of it as setting up a cozy new home for your data, complete with all the essential amenities.

Synchronise the data – To minimize downtime, you’ll want to synchronise the data between the old and new servers. This can be achieved through various methods, such as database replication or file synchronisation. i tend to ssh into the new server and rsync everything. It’s like making sure all your belongings are safely transported from your old house to the new one, ensuring nothing gets left behind.

Important Note Here, normally before starting the sync i put the old site in maintenance so there is no change or updates while the data is syncing, especially if the site is big or popular.

Test the migration – Before fully transitioning to the new server, it’s crucial to thoroughly test the migration process. This involves verifying that all data has been successfully transferred and that the new server functions correctly. Think of it as a dress rehearsal, where you ensure that everything runs smoothly before the big performance. I tend to use ssh with the diff command to achieve this.

Switch the DNS – Once you’re confident that the new server is ready to take over, you can update the DNS settings to point to the new server’s IP address. This step ensures that when users access your website or application, they are directed to the new server seamlessly. It’s like updating the address in your contact information so that people can find your new location without any hiccups.

Monitor and verify – After the DNS switch, closely monitor the traffic and performance on both servers. Keep an eye on any potential issues and ensure that the new server is handling requests correctly. Also make sure that other services dependent on that old server are transferred over like e-mail.

By following these steps, you can migrate data between servers with minimal to no downtime. However, it’s important to note that each migration scenario is unique, and careful planning and testing are crucial to ensure a smooth transition and always ALWAYS ALWAYS!!!!!! Have plenty of backups!

Shared Hosting VS Cloud Share VS Virtual Private Server

Shared hosting, including cloud shared hosting, and virtual private server (VPS) are some of the most popular options for hosting websites and applications. While they both serve the purpose of making your content accessible on the internet, there are significant differences in terms of performance, control, and scalability. We here on Hostcult use all 3, so i think its a nice write up to compare each with pros and cons, so lets check this out.

Shared Hosting

Shared hosting is a hosting environment where multiple websites are hosted on a single server. It is a cost-effective solution, making it suitable for small businesses, personal websites, and entry-level projects. In this setup, server resources such as CPU, RAM, and storage are shared among the websites hosted on the server. This sharing of resources allows hosting providers to offer affordable plans to a large number of customers. It also shares the hosting software so it makes it super easy to run anything.

Pros of Shared Hosting

  • Cost-effective: Shared hosting plans are generally one of the most affordable options, making them ideal for individuals and small businesses with limited budgets.
  • Easy to manage: The hosting provider handles server maintenance, security updates, and technical support, relieving users of the burden of server management.
  • User-friendly: Shared hosting often comes with a user-friendly control panel that simplifies website management, domain setup, and email configuration.

Cons of Shared Hosting

  • Limited resources: Since resources are shared among multiple websites, the performance of your website can be affected by the activities of other users on the server. If one website experiences a sudden surge in traffic, it can impact the overall server performance, potentially slowing down your site.
  • Limited customisation: Shared hosting environments typically have limitations on software installations and configurations since they aim to provide a standardised setup for all users.
  • Security concerns: As multiple websites share the same server, if one site is compromised, there is a potential risk of other sites on the server being affected as well.

Cloud Shared Hosting

Cloud shared hosting builds upon the shared hosting model by utilising cloud infrastructure. Instead of relying on a single physical server, cloud hosting distributes resources across multiple servers in a network. This offers improved scalability and reliability compared to traditional shared hosting.

Pros of Cloud Shared Hosting

  • Scalability: Cloud hosting allows for easy scaling of resources, ensuring that your website can handle sudden traffic spikes without performance degradation.
  • Reliability: With multiple servers in a network, if one server fails, your website can be instantly migrated to another server, minimising downtime.
  • Flexibility: Cloud hosting often provides more advanced features, such as load balancing and automatic backups, to enhance website performance and data protection.

Cons of Cloud Shared Hosting

  • Cost variation: While cloud shared hosting can be cost-effective for moderate traffic, the usage-based pricing model can result in higher costs if your website experiences significant traffic or resource usage.
  • Technical complexity: Cloud hosting may require more technical knowledge and expertise to set up and manage compared to traditional shared hosting.
  • Unique infrastructures – By default a cloud infrastructure can be setup from pretty simple with a couple of servers or incredibly complex with thousands, that makes it hard to compare the benefits or each cloud provider, since one can have better performance and another reality and another connections and another replication.

Virtual Private Server (VPS)

A VPS is a hosting environment where a physical server is divided into multiple virtual servers, each acting as an independent server environment. Each VPS has dedicated resources allocated to it, providing more control and performance compared to shared hosting.

Pros of VPS Hosting

  • Dedicated resources: With a VPS, you have guaranteed resources that are not shared with other users, ensuring consistent performance for your website and application.
  • Customisation and control: VPS hosting grants you root access, allowing you to install and configure software as per your requirements. You have more control over server settings and can tailor the environment to suit your specific needs.
  • Scalability: VPS hosting offers scalability options, allowing you to easily adjust your resource allocation as your website’s traffic and demands grow.

Cons of VPS Hosting

  • Cost: VPS hosting tends to be more expensive than shared hosting due to the dedicated resources and increased control it provides. It may not be the most cost-effective option for websites with low traffic or limited budgets.
  • Server management: While VPS hosting grants more control, it also requires a higher level of technical expertise to manage the server effectively. Users are responsible for tasks like server maintenance, security updates, and software installations.
  • Performance limitations: Although VPS hosting provides dedicated resources, the overall performance can still be affected by the physical server’s hardware limitations. If the physical server is overloaded, it can impact the performance of all VPS instances hosted on it.

So shared hosting, including cloud shared hosting, is suitable for entry-level websites and projects with budget constraints. It offers cost-effective pricing and user-friendly management, but resource limitations and potential complexity concerns should be considered. Cloud shared hosting provides enhanced scalability and reliability compared to traditional shared hosting but can be costlier and requires more technical expertise to run.

On the other hand, VPS hosting offers dedicated resources, increased customisation, and scalability, making it a preferable option for websites with higher traffic and specific requirements. It provides more control and performance, but at a higher cost and with additional server management responsibilities.

To sum it up here on Hostcult we use shared hosting for small sites, placeholders and testbeds, we use cloud shared hosting for bigger sites and production and we use VPS for specific services or files/image/video hosting that need specific software/performance to run.