Bobcares

How does Memcached work? – A quick guide

by | Mar 22, 2020

Do you want to know how does the Memcached work? Here is a quick guide.

Memcached is a caching system that speeds up your web applications by storing frequently accessed data in super-fast RAM, instead of the super slow hard disk.

Today, we’ll cover how Memcached makes this happen, and how our System Engineers set it up.

Read on.

 

The mechanics of Memcached

You see, all the data that we need are stored in server hard disks.

But hard disks, or HDDs for short, are notoriously slow because it is a mechanical device.

Memcached sits between your application and your HDD and keeps track of what the commonly asked bits of data are.

It’ll then store this data in the super-fast server memory so that the next time your application asks for it, it can be served right up! No-fuss.

 

Memcached – Under the hood

So how does Memcached serve the frequently requested data within fractions of seconds? The logic behind this is really simple.

Memcached stores every single piece of data with an ID. The Memcached calls it data as value and its ID as the key.

So when a user requests the ID again it can serve it in a glimpse.

But how does it store and fetch the data? The image says it all.

How does Memcached work.

Let’s get a little deeper into the details.

When a client requests a data, Memcached checks for it in the cache. It returns the data if it is available in the cache. Otherwise, it queries the hard disk and then retrieves it.

If there is any change in the data stored, the Memcached updates its cache to serve the latest data to the clients.

 

How does Memcached work? – The technical stuff

Really keen to know how it actually works, then first have a look at the components involved. It includes Client software, a Hashing algorithm, Server software, and an LRU algorithm.

The client software is the available Memcached servers. It stores the data based on a hashing algorithm. That is it chooses a server to stores the data.

The server software stores the key and corresponding value in a hash table. While the fetching of the data relies on the LRU algorithm. In simple words, the least recently used data get loaded fast.

Now let’s see how our Support Engineers install Memcached.

 

How to install Memcached?

There are two ways to install Memcached. That is, either using the package manager provided by the OS or directly from the source.

 

Using a package manager

We can simply install Memcached from the package provided by the OS.

For instance, in a Ubuntu/Debian system, we use the command,

apt install memcached

Whereas in a RedHat/CentOS system we use the command,

yum install memcached

Here the OS will take care of the dependencies installation and security updates.

But if users run older OS version, it installs an older version of Memcached. In such cases, we recommend the customer to upgrade the OS.

 

Installation from the source

We can also install Memcached from the source. So first, we install its dependency named libevent-dev.

In an Ubuntu system, we use the command,

apt install libevent-dev

Whereas, in a CentOS system we use the command,

yum install libevent-dev

Then we install Memcached using the commands,

wget https://memcached.org/latest

tar -zxf <package name>

cd package name

./configure --prefix=/usr/local/memcached

make && make test && sudo make install

 

Both the methods successfully install the Memcached. One way to connect to a Memcached server is through a telnet session,

telnet <HOST> <PORT>

 

Where and where not to use Memcached?

Memcached is best suited for larger websites with heavy traffic. That is servers that get frequent queries. If the most frequent queries are cached, then the website load is considerably reduced. And this speed up the website.

Even though, caching speed up websites, there are certain situations where it is not preferred to use Memcached.

For instance, if a website has more frequent updates, then caching will not speed it up. Because the cache needs to refresh itself always. Memcached has some limitations too. It cannot store objects larger than 1MB and keys longer than 250 characters.

 

[Need assistance in setting up Memcached? – We can help you.]

 

Conclusion

So far, we saw how does Memcached work. Memcached helps in improving server speed that gets frequent queries. We also saw how our Support Engineers install Memcached on various platforms.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF