March 2019
M T W T F S S
« Jan    
 123
45678910
11121314151617
18192021222324
25262728293031

Categories

WordPress Quotes

Whatever the mind of man can conceive and believe, it can achieve.
W. Clement Stone

Recent Comments

March 2019
M T W T F S S
« Jan    
 123
45678910
11121314151617
18192021222324
25262728293031

Short Cuts

2012 SERVER (64)
2016 windows (9)
AIX (13)
Amazon (34)
Ansibile (19)
Apache (133)
Asterisk (2)
cassandra (2)
Centos (209)
Centos RHEL 7 (261)
chef (3)
cloud (2)
cluster (3)
Coherence (1)
DB2 (5)
DISK (25)
DNS (9)
Docker (28)
Eassy (11)
ELKS (1)
EXCHANGE (3)
Fedora (6)
ftp (5)
GIT (3)
GOD (2)
Grub (1)
Hacking (10)
Hadoop (6)
horoscope (23)
Hyper-V (10)
IIS (15)
IPTABLES (15)
JAVA (7)
JBOSS (32)
jenkins (1)
Kubernetes (2)
Ldap (5)
Linux (188)
Linux Commands (166)
Load balancer (5)
mariadb (14)
Mongodb (4)
MQ Server (24)
MYSQL (84)
Nagios (5)
NaturalOil (13)
Nginx (31)
Ngix (1)
openldap (1)
Openstack (6)
Oracle (34)
Perl (3)
Postfix (19)
Postgresql (1)
PowerShell (2)
Python (3)
qmail (36)
Redis (12)
RHCE (28)
SCALEIO (1)
Security on Centos (29)
SFTP (1)
Shell (64)
Solaris (58)
Sql Server 2012 (4)
squid (3)
SSH (10)
SSL (14)
Storage (1)
swap (3)
TIPS on Linux (28)
tomcat (60)
Uncategorized (29)
Veritas (2)
vfabric (1)
VMware (28)
Weblogic (38)
Websphere (71)
Windows (19)
Windows Software (2)
wordpress (1)
ZIMBRA (17)

WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.

Who's Online

24 visitors online now
2 guests, 22 bots, 0 members

Hit Counter provided by dental implants orange county

Installing Memcached to Improve Database Performance

SQL databases are very good at storing and retrieving data, and they can do so quickly. However, no matter how well you tune your database servers there will come a time during periods of high traffic that your database server becomes a large bottleneck. By utilizing technologies like Memcache, we can keep results of frequently used database queries in a cache stored in RAM. Using the cached results significantly decreases that amount of time and effort to retrieve data and present in our application.

Memcache is what’s known as an in-memory key-value store. The key is a unique identifier that is used to quickly search for cached strings or objects. The value is the data that has been cached. For the purpose of storing database query results, the key will typically be the query used on your database.

 

Key-value Pairs

A key-value pair is essential an array of data. If you have any experience in programming, you will have a good understanding of how data is stored in Memcache. If were to present a key-value for a database query in an easily read form, it would look similar to the example below.

Searching for long text strings isn’t very efficient, so storing your keys as such is a bad idea. The example above is used just to illustrate how data is stored in cache. In a typical environment you would convert your key (the SQL query) into a MD5 hashed value, for example, before storing or retrieving data from Memcache.

Typical Infrastructure

The diagram below illustrates how your infrastructure will typically look when you deploy Memcache in your environment. You will notice that the Memcache server doesn’t communicate directly with your database servers. Instead, they sit in their own pool and your application does all of the work.

 

 

Your application will first query the Memcached server(s) for cached database results. If nothing is found, the application will then query your database server(s). Any cached results from the database server will then be written to the Memcache server(s) by your application.

Of course, you can’t just simply drop a Memcached server in and expect your application to be able to use. Your application will have to be modified to utilize the Memcache server. This is outside of the scope of this tutorial, but it is important that you know.

 

Hardware Requirements

The hardware requirements for Memcache servers is low. There is very little CPU processing involved and virtually no disk storage needed in addition to the operating system. The only resource you need is RAM. How much will depend on what is being cached and the duration of the caches.

Installing Memcached

Memcached can be install anywhere in your infrastructure. For small environments, you may install it on the web application server itself. However, it’s recommended that you create a separate server instance for Memcached. This allows your web application server to focus on just being a application server.

Ubuntu

Memcached is available in the default repositories. To install it, you can run the following command.

sudo apt-get install memcached

CentOS

Memcached is available in the default repositories. To install it, you can run the following command.

yum install memcached

 

Configuring Memcached

The default configuration should work fine for testing. However, you may want to fine tune it to better fit your server’s hardware in production.

Ubuntu

  1. Open the configuration file into a text editor.
    sudo nano /etc/memcached.conf
  2. To increase the memory cap, look for the following line. The default value is 64MB.
    -m 64
  3. Change the IP address Memcached will listen on. The address should be accessible to your application server.
    -l 192.168.1.40
  4. Limit how many concurrent connections the server will accept. The default is 1024. Limiting connections is important to ensure the server isn’t overwhelmed with requests.
    -c 1024
  5. Save your changes and exit the text editor.
  6. Reload the configuration into Memcached to apply your changes.
    sudo service memcached reload

 

CentOS

  1. Open the configuration file into a text editor.
    vi /etc/memcached.conf
  2. Modify the MAXCONN value to increase or decrease the maximum amount of connections the server can handle. This will be based on your hardware. To determine the appropriate value, you will need to stress test the server.
    MAXCONN="1024"
  3. Modify the CACHESIZE value to increase or decrease the memory cap. This value will depend on how much RAM is available in your server.
    CACHESIZE="64"
  4. Exit the text editor.
  5. Reload the configuration to apply your changes.
    service memcached reload

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Blue Captcha Image
Refresh

*

Protected by WP Anti Spam