Do you need to boost the performance of your web applications? In most cases, programs access the same data in applications over and over, so a caching system can be the best option to reduce the time needed. Memcached is an open source distributed memory object caching system. It is designed to cache large amounts of data. It lightens database workloads and speeds up your applications while its simplicity also facilitates quick and easy deployment.
Bitnami has packaged a three-node (default) Memcached cluster which helps developers quickly launch a set of Memcached servers. That way, you can focus on coding instead of wasting time installing and configuring complex caching systems for your external applications.
Search for Bitnami Memcached with Multiple Instances in the cloud platform of your choice, and give it a try! It is available at no additional cost in both the Google Cloud Platform and the Microsoft Azure Marketplace.
Using a cache to avoid slow databases is the optimal way to ensure the efficiency of your applications. For heavy application workloads that demand a lot of requests per minute -such as social networking, gaming, or media sharing- an in-memory key value store such as Memcached is a complete solution to manage excessive data loads.
However, if you have a single Memcached server running, it is almost mandatory to increase its memory to avoid slowing down the application server. This may be a solution for improving the velocity of the application, but it is not a good idea for reducing costs.
The most cost-effective approach has a simple solution: more instances with less memory instead of one instance with a lot of GB. For example, having in total a 6GB RAM cluster comprised of three nodes, with 2GB each, is cheaper than launching a single instance with 6GB.
In addition to this, running a Memcached cluster with multiple instances alleviates the load in the web server and improves its performance. While Memcached nodes are running on the same network as the application server, small chunks of arbitrary data (results of database calls, API calls, or page rendering) are stored in multiple instances across the network, relieving disk space in the server where the application is running.
Bitnami's three-node Memcached Multiple Instances solution helps launch a production ready cluster in just one click.
Its configuration is adapted to the size of the machine, and it applies 75% of RAM to cache.
Scaling out the Bitnami Multi-Tier solution for Memcached is as easy as adding new nodes to the cluster. It can be done at deployment or even when the solution is already running. Check the Bitnami Memcached Multiple Instances documentation to learn how to add new nodes to the cluster on the Google Cloud Platform or on the Microsoft Azure.
By default, each node is provided with 3.75 GB of RAM (Google Cloud Platform) or 3.5 GB of RAM (Microsoft Azure). The default disk space of each instance is 10 GB. These values are also customizable as it is shown below:
Once you have added a new node, you can check to make sure it is running smoothly by executing the telnet and stats commands:
$ telnet NEW_NODE_IP_ADDRESS 11211
You should see an output similar to this:
More nodes mean higher failure-resistant distributed cache for your application. If a server goes down, the data is re-cached in a different Memcached node so that the speed of your application is the same as before the failure.
Bitnami recommends installing a client such as php-memcached-sasl to test your installation's efficiency. You can find further information in the Bitnami documentation for the Google Cloud Platform or in the Bitnami documentation for Microsoft Azure.
Memcached is perfect to reduce the number of times that the database or API needs to be read while performing operations. It caches the data in the RAM of the different nodes in the cluster, reducing the load in the web server.
A good way to see how an application would use Bitnami Memcached with Multiple Instances is, for example, having a PHP application and distributing the sessions across the Memcached servers. These are the steps you’ll follow:
|NOTE: Remember that you need to perform these steps in each node of your cluster and that the parameters must be exact on all servers.|
In your php.ini file, configure Memcached to allow distributed PHP sessions by setting the following parameters:
extension=memcache.so memcache.maxreclevel=0 memcache.maxfiles=0 memcache.archivememlim=0 memcache.maxfilesize=0 memcache.maxratio=0 memcache.hash_strategy = consistent memcache.allow_failover = 1 memcache.session_redundancy = 4
The main parameters to configure are:
Once the Memcached configuration is completed, it is time to indicate to PHP that Memcached servers are in charge of storing its sessions. In the php.ini file, replace the default values with the following:
session.save_handler = memcache session.save_path = "tcp://MEMCACHED_NODE1_IP_ADDRESS:11211, tcp://MEMCACHED_NODE2_IP_ADDRESS:11211, MEMCACHED_NODE3_IP_ADDRESS:11211"
Remember to replace the MEMCACHED_NODE_IP_ADDRESS placeholder with the corresponding private IP addresses of each node of your cluster. That’s all! With this configuration, the sessions of your PHP application are stored in the Memcached servers instead of in your web server.
Start enjoying faster and optimized applications from now on!