Académique Documents
Professionnel Documents
Culture Documents
May, 2010
Germán Villacreces
Performance Tuning Drupal
Table of C ontents
Introduction 3
Tes t environment 4
The Tes t S ite 4
The Virtual S erver 5
Tes ting tools 5
S ingle P age Load Tes ting Tools 5
Load Tes ting Tools 6
E valuating the current performanc e 7
S ingle P age Load R es ults 7
Load Tes ting R es ults 12
Optimizing Drupal 12
Front-end Optimization 12
Us e a C DN 13
Make Fewer R eques ts 13
Add E xpires Headers 13
C onfigure E ntity Tags (E -Tags ) 14
Us e C ookie-Free Domains 14
B ack-end Optimization 15
P age & B lock C aching 15
B oos t 15
Optimizing your s erver 16
Tuning Apache 17
Tuning MyS QL 17
Tuning P HP 19
AP C 19
Memcac he 21
E valuating the performance after optimization 22
S ingle P age Load R es ults 22
Load Tes t R es ults 24
C onclus ion 25
Drupal S ucc es s S tory 26
Additional Drupal R es ourc es from Os hyn 28
About G erman Villacreces 29
About Os hyn 29
Introduction
This paper evaluates the performanc e of a s mall s ite built with Drupal on a
s tandard virtual s erver running Ubuntu S erver E dition 9. 10. T he evaluation will
focus on the res ults of tes ting the res pons e time and amount of reques ts per
s econd (R P S ) that the s erver c an hold before the average load time is
unac ceptable. The firs t evaluation will be done with the default c onfiguration of
Drupal and the s erver. The s econd evaluation will take plac e after optimizing
both. The res ults from the evaluations will be compared to get to a good idea
of how fas t c an Drupal run on a virtual s erver with the minimum s pecs . K eep in
mind that this public ation is to evaluate the performanc e of Drupal for s mall
s ites with low traffic. T he s erver will have the minimum s pecs . After reading
this paper, you will know whether a s imple virtual s erver is more than enough
for a low traffic s mall webs ite and you will learn how much the performance of
Drupal can be improved by jus t tuning the s ettings and the s erver.
Tes t environment
The Tes t S ite
The s ite us ed for this benchmark was built with the lates t Drupal 6 releas e at
the time of this writing (Drupal 6. 16). The s ite makes us e of the following
modules in addition to the required core modules :
The s ite was built us ing the features from all the above modules . The
homepage will be the target for all the tes ting. This is what it looks like:
This page is built with the P anels module, 5 different views are us ed.
The page has numerous elements :
1 HTML page reques t (4. 5 kb)
1 XML as ynchronous page reques t (510 b)
16 s tyles heet reques ts (10. 9 kb)
5 J avaS c ript reques ts (29. 6 kb)
9 image reques ts (102. 5 kb)
1 intial Flas h reques t (45 kb)
4 additional fFas h reques ts (712. 6 kb)
Lazy loading is us ed for the Flas h additional reques ts and the XML s o the total
initial page reques t s ize is 19 0. 6 kb and the additional reques t s ize is 713. 1
kb
The average total page s ize ac cording to a res earch made is 130kb. S o the
homepage is a little over the above bec aus e of the main Flas h element. We
s hould keep that in mind.
10
8
Seconds
6
4
Initial Load
Total Load 2
0
1 2 3 4
5 6 7 8
9 10 11 Initial Load
12 13 14 15
16 17 18
19 20
Number of Request
The average initial load takes 3. 78 s econds ; the average total load takes 10. 55
s econds . The initial load is within the ac ceptanc e limits , but we can improve
this and we als o want to get a good grade to leave the s ite as optimized as
pos s ible in the front- end.
The meas urements dis played by Y S low are pretty good, but you are probably
thinking that they c an' t really be cons idered as clos e to reality as pos s ible
bec aus e we are trying from a s ingle loc ation. This is why we are going to us e
the s econd tool we talked about before, webpagetes t. org. Us ing this tool will
give us more ac curate meas urements bec aus e the tes ts are conducted from
different locations around the world. We will again make an average of all the
res ults , this time cons idering meas urements from different loc ations in the
world:
Virginia, US A
C alifornia, US A
G louc es ter, UK
J iangs u, C hina
Wellington
As you c an s ee, the average initial load of the page takes 7. 06 s econds ; the
total load time is 15. 207 s econds . This is a little higher than the res ults we
made from
Here are the res ults for all the locations .
40
35
30
25
Seconds
20
15
Initial Load 10
Total Load 5
Initial Load
0
Location
Jiangsu, China
Virginia, USA
Gloucester,UK
Average (seconds)
Wellington, New
Zealand
California, USA
The res ults s how that the average initial load value is 1 3. 7 1 s ec onds , and the
average total load is 2 0. 3 7 s ec onds . This is above the ac ceptanc e limit (8s ).
E vidently, we do need to make a few adjus tments to the front- end
optimization.
Load Tes ting R esults
To tes t the amount of load the s ite c an handle, we mentioned we were going
to us e jMeter. T his is a great tool and it’ s all we need for the purpos es of this
public ation. The res ults after increas ing the amount of R P S are the following:
16.000
14.000
12.000
10.000
Seconds
8.000
6.000
4.000
Average Load Time 2.000
0.000
10 RPS 20 RPS Average Load Time
30 RPS 40 RPS
50 RPS
The average load time when making 30 R P S is 9. 943 s econds , this is above
our ac c eptanc e value. W e c an s afely s ay that the virtual machine, with the
current configuration c an only ac cept 20 reques ts per s econd. This value is
low, but do keep in mind the s erver s pec ifications and that no optimization
changes have been done to the s erver or the s ite.
Optimizing Drupal
Front-end Optimization
Let’ s s ee how we c an optimize the s ite to get a better load time. We are going
to bas e our actions on the recommendations that Y S low gives us s o we c an
get a better grade. R emember, our current overall grade is D, s o lets apply all
the recommendations pos s ible and get A' s on all pos s ible c riteria.
Use a C DN
Integrating a C DN is not s omething we are going to do for now s ince it
requires a cons iderate ec onomic inves tment. It does help front- end
performanc e enormous ly, but in this paper we are going to try to inc reas e the
performanc e of Drupal with what we have at hand.
K eep in mind that the exac t path of this line will vary on the different type of
Linux dis tributions . In mos t c as es , this module will be loaded by default, s o
you will not need to do anything.
In this Ubuntu s erver edition, module enabling is done a little differently; all we
have to do is create a s ymbolic link of /etc /apac he2/mods -
available/expires . load in /etc /apache2/mods - enabled. W e do this running the
following command in the s erver:
sudo ln -s /etc/apache2/mods-available/expires.load
/etc/apache2/mods-enabled/.
The next s tep is to s et the expires value. If you are us ing a Linux dis tribution
other than the one we are us ing here you might have to s et this value by
adding the following line at the end of the httpd. c onf file:
<IfModule expires_module>
ExpiresActive On
ExpiresDefault "access plus 6 months"
</IfModule>
In our dis tribution, ins tead of adding thes e lines to the httpd. conf file, we add
thos e likes to an empty file we c reate c alled expires . conf. This file needs to be
place in the /etc/apache2/mods -available directory and we c reate a s ymbolic
link to it on /etc/apac he2/mods -enabled:
sudo ln -s /etc/apache2/mods-available/expires.conf
/etc/apache2/mods-enabled/.
Note: T he directive value "ac ces s plus 6 months " means we s et the expire to
be added to the eac h file s o that it caches the file for the next 6 months s inc e
the firs t time it was acc es s ed.
You c an res tart Apac he to tes t if this works . You s hould now get an A grade
on the E xpires Headers c riteria.
The third and final s tep is to make Drupal point all s tatic files to your s eparate
domain. We do this by ins talling the C DN Integration module
(http: //drupal. c om/projec t/cdn) which is us ed to pull s tatic c ontent from
another domain or s ubdomain. Ins tall the module, go to the bas ic mode
s ettings in S ite C onfiguration > C DN Integration > B as ic mode. In this s c reen
input your s tatic domain to the one you jus t created in this s ection' s firs t s tep.
In our c as e, the value we input is http://os hyn-s tatic.com. S ave the form, go to
the tab called S ettings and click on the E nable radio button under S tatus .
S ave the form and flus h your s ite' s cache.
We have made all the adjus tments in the front-end, we will evaluate the res ults
later on after c ompleting all optimizations .
B ac k-end Optimization
There are many ways we c an improve the performanc e of Drupal without
touching the s erver yet. The native optimization features help a great deal
s inc e they are c ac hing s ys tems within the core Drupal code.
B oos t
This is a very helpful module for s ites that have mos tly anonymous traffic. It
caches all s tatic pages . This way when anonymous us ers open a content
page, Drupal does n’ t have to pull data from the databas e to render the page,
it literally turns a Drupal page to a s tatic HT ML file. Download
(http: //drupal. org/project/boos t) and ins tall this module on your s ite, and we
need to configure it.
To configure B oos t properly and quickly, go to the admin/reports /s tatus page
in your s ite and you will s ee all the things that need to be done to make this
module work. Firs t we need to prevent web c rawlers from indexing the output
of the module in c ertain files . S o we add the following line at the end of the
robots . txt file, located in the root folder of your s ite:
Disallow: /boost_stats.php
Next we need to c reate the following nes ted folders in your root folder:
cache/perm/[yours ite.c om]
And give them writing acc es s to Apac he, run the "chmod" command from the
root folder.
There is an additional s tep we' ll need to do but we can' t yet. W e' ll do it when
we tune Apache in the next s ec tion, s o remember that. For now if you get a
"file_get_contents . . " warning in the admin s ec tion, then jus t go to S ite S ettings
> P erformanc e > B oos t S ettings and at the bottom of the form, find the Ignore
.htac ces s warning c heckbox, s elec ted and s ave the form. We don’ t need to
change anything els e here now. We can move on to our las t s tep of B oos t
configuration, c ron.
S etting up cron is really eas y, we log in to the s erver us ing the admin ac count
(not root). And we edit c rontab with the following command:
sudo crontab -e
0 * * * * wget -O - -q -t 1 http://yoursite.com/cron.php
What we are doing here is telling cron to exec ute a command every hour,
thats all we need in our c as e. The c ommand is to make an http reques t to the
cron. php file in our s ite. You will need of c ours e to replac e the yours ite. com
value for your real domain. For additional help on s etting up c ron, go to
http: //drupal. org/cron.
R emember, the las t s tep to make B oos t work is done in the Apache tuning
s ec tion.
AllowOverride None
Order allow,deny
allow from all
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
This code is the exis ting code in the . htacc es s file. The directive AllowOverride
None tells Apache not to look for the . htac ces s files . Now, here is when we
add the mis s ing piece from the B oos t module. Login as the admin in your s ite
and go to S ite configuration > P erformance > B oos t htacc es s rule generation.
C opy that c ode and pas te it under the rewrite rules you jus t added to your
<Directory> direc tive. S ave the file, res tart Apac he and tes t your s ite s o that
friendly urls are s till working. Als o, check the cac he/perm/[yours ite. com] folder
you c reated for B oos t before, if there are files there it means boos t is working
fine. If not, s omething is wrong, go back to make s ure all s teps were
completed, us e the doc umentation that B oos t provides in their projec t page
(http: //drupal. org/project/boos t).
This is all we need to do for Apache.
Tuning MyS QL
MyS QL is probably one of the mos t complic ated components to tune. T he
reas on for this is bec aus e the optimal configuration is different depending on
the s ite you have. In our cas e, our traffic is mos tly anonymous , and us ers do
more reads from the databas e than writes . To optimize our s ite we c an do
three things :
1. Hardware upgrade
2. Tune the mys ql s ettings
3. Optimize your queries
In our c as e, hardwa re upgrade is not an option as we are trying to keep this
performanc e with minimum expens es . T here are a few s ettings we c a n
c hange to inc reas e the performa nc e of M yS Q L for our s ite, s ince we have a
lot of reads , its good to have a good amount of query c ache s ize. G o to the
MyS QL s ettings file c alled my. cnf. It is us ually located in /etc/my. c nf or
/etc/mys ql/my. cnf. Y ou c an type the following command anywhere to find the
loc ation of yours :
locate my.cnf
E dit the file with s udo us ing any editor, find the query_cac he_s ize and change
it to 32M, it s hould look like this :
query_cache_size = 32M
This value s hould be c hanged depending on the traffic on your s ite, you c an
s ee if the value you input is the bes t by monitoring the query c ache, you do
this in the MyS Ql cons ole. L ogin as the root us er in the MyS QL cons ole and
type:
You c an monitor thes e values while tes ting your s ite, to s ee how MyS QL
res ponds .
The s econd c hange we need to make helps limit the s erver res ources us e in
the MyS QL proc es s . We unc omment and c hange the following line in the
my. c nf file:
max-connections=500
This s ets the maximum number of allowed connections , its default value is
100, while tes ting your s erver, if you find that MyS QL does not take a lot of
your memory up and C P U, you c an inc reas e this value to allow more
connections at the s ame time. B e careful though, if you allow too many
connections MyS QL may take all of your s erver res ourc es and eventually
cras h. We s et this value to 500 to s ee how it works .
You c an s ee the maximum number of connec tions your databas e has handled
us ing the following MyS QL command:
The third and final change we are going to make in the MyS QL s ettings is in
the c ac hes . T ables are s tored as files in MyS QL, this means that each table file
needs to be opened for read. MyS QL c an leave thes e files open s o that next
time it reads them it won’ t need to reopen them. MyS QL c an leave a c ertain
number of tables open, we c an s ee if with this value MyS QL has had the need
of reopening tables . G o to the MyS QL cons ole and type:
log_slow_queries = /var/log/mysql/mysql-slow.log
long_query_time = 5
log-queries-not-using-indexes
While navigating through your s ite, you will need to monitor the mys ql-s low. log
file. To do this run:
tail -f /var/log/mysql/mysql-slow.log
You will then s ee what queries are running s low and you c an optimize them.
Optimizing MyS QL is probably the hardes t s inc e you have to us e trial and error
to get to the bes t s ettings for your s ite and bec aus e there are s o many
s ettings you c an change. T o c hange more advanc ed s ettings pleas e refer to
the following guide http: //www. ibm. com/developerworks /linux/library/l- tune-
lamp-3. HT ML
Tuning P HP
There are two ways to optimize P HP and both work great. One is to ins tall
AP C (Alternative P H P C ac he). This s ys tem c aches the opcode generated
when P H P is interpreted. The s econd way is to ins tall Memcache, this c aching
s ys tem s tores data objec ts in memory, us ually res ults from the databas e.
R eading from memory is much fas ter than reading from dis k s o it’ s a great
way of optimizing the s ite.
AP C
The following ins truc tions explain how to ins tall AP C on the Ubuntu s erver we
have s etup for our s ite. T o get AP C up and running, we need P E C L s o we c an
ins tall AP C from the lates t repos itories .
Ins tall all required libraries from aptitude firs t:
sudo aptitude install php-pear
sudo aptitude install php5-dev
sudo aptitude install apache2-dev
To make s ure AP C is working great we can us e the apc. php s c ript that comes
in the package. Download and untar the lates t built. At the moment of this
public ation AP C ' s lates t build is 3. 1. 3:
wget http://pecl.php.net/get/APC-3.1.3p1.tgz
tar xvzf APC-3.1.3p1.tgz
Now we will copy the apc. php file to our s ite folder:
cp APC-3.1.3p1/apc.php /var/www/.
After brows ing through the s ite for the firs t time after AP C is ins talled, the
opcode is being generated and kept on cache. If you s urf through the s ite
again various times the opcode will be already created and the s ite will be
fas ter. Here are the s tats generated by the apc. php s cript:
The green bar dis plays the hits on c ac he.
Memcache
The las t optimization we are going to implement is memc ache, it is a very
s imple c aching s ys tem that us es memory to s tore objec ts . As you may already
know, memory is fas ter to read than hard drive. A s ite will take a lot les s time
to read a databas e res ult cached in memory. To make the bes t us e of
memcache on Drupal, it’ s better to ins tall the memc ache module
(http: //drupal. org/project/memc ac he). Firs t lets ins tall the memc ache binaries
on Ubuntu. Doing this is as eas y as executing the apt and pecl commands :
Now pleas e follow the ins tallation ins tructions in the memcache module page
provided before to make memcac he work with Drupal. Y ou can s tart from s tep
3.
Once you are done we c an now perform new tes ts to s ee how much the s ite' s
performanc e has improved.
E valuating the performance after optimization
We have s uc ces s fully completed all the optimizations on our Drupal s ite.
S tarting with the front-end, then to the Drupal back-end and even s erver
tuning. There are more ways to optimize even more a Drupal s ite. On our
cas e, a s mall webs ite with mos tly s tatic content, we have done a lot. Lets
know s ee how helpful this was . Firs t we are going to evaluate the s ingle page
load res ults and then the load tes ting res ults .
G oing back to Y S low, you c an s ee that our new grade is A! The total s core we
got was 92. W e didn’ t get 100 bec aus e we are not us ing a c ontent delivery
network. Like we s aid before, us ing a C DN involves an inves tment, and we are
trying to optimize our s mall s ite without s pending.
The res ults are very good. E verything went well as planned. Next we are going
to look into the webpagetes t. org res ults . W e make the exact s ame tes t from
the different locations .
Here are the res ults from the webpagetes t. org s ite:
2.5
2
Seconds
1.5
1
Initial Load
0.5
Total Load
Initial Load
0
Location
Jiangsu, China
Virginia, USA
Gloucester,UK
Average (seconds)
Wellington, New
Zealand
California, USA
Looking at thes e res ults , the s ingle page load tes t value demons trates how we
have s uc c es s fully dec reas ed the average page load time globally. The average
initial load takes 1. 3 1 s ec onds and the total load time takes 1. 8 5 s ec onds .
10.000
8.000
Seconds
6.000
4.000
2.000
Average Load Time
0.000
10 20 Average Load Time
30 40
RPS RPS 50 60
RPS RPS 70 80
RPS RPS
RPS RPS
The total number of reques ts per s econd that our s erver can take after all the
optimizations is 60 R P S . W ith 70 R P S the average load time is above 8
s econds .
C onclus ion
We have s uc ces s fully optimized our Drupal s ite, but how helpful were all the
changes we made? W e get the ans wer by looking at the numbers . B efore our
changes , loading our s ite took an average of 1 3. 71 s ec onds from different
parts of the world. After the optimization c hanges , the average load time is
1. 31 s ec onds . We have decreas ed the initial page load time by 9 0% . T he
s erver load could take up to 20 R P S before. Now the s erver c an take 60 R P S ,
whic h means that all the optimizations we did increas ed three times the
amount of load that this virtual s erver can take.
After reviewing the res ults , we can s ee that without adding new hardware, we
can s peed up our s ite and the s erver can proc es s more reques ts per s econd.
B efore expanding on infras truc ture, a s ite s hould be c ompletely optimized. In
s ome cas es , that may be enough to meet the traffic demand.
T he C hallenge
Mallika C hopra, the daughter of Deepak C hopra and S al Taylor K ydd a former
Yahoo! exec utive, wanted to launch Intent. com with the aim of it bec oming the
mos t trus ted wellnes s des tination for capturing and s haring people’ s pers onal,
s ocial, s piritual, and environmental intentions .
T he S olution
Armed with an outline of a preliminary vis ual des ign and required functionality,
Intent. com s elec ted Os hyn to des ign and build out the res t of the plan and
execute the launch of the webs ite.
In addition to the c ons umer fac ing webs ite, the bus ines s development team at
Intent als o needed a pre-launch demo of the webs ite to as s is t them in s igning
deals with c ontent s yndic ation partners , s pons ors , and advertis ers . Os hyn
“The customized CMS allows us rapidly built a beta vers ion of Intent. c om to give the bus ines s development
to constantly deliver great team the opportunity to s howc as e the webs ite’ s func tionality from any loc ation
content that is increasing while they purs ued revenue and content opportunities .
registered members.”
C ollaboration was at the heart of the Intent. com webs ite. T herefore, Os hyn
built a webs ite that offered vis itors with many ways to contribute, collaborate,
and c onnect: us er ac counts , s oc ial networking platform, blog, quizzes and
polls , news letters , invitation-only feature, content s yndic ation, podc as t, and
video. Intent. com needed to have the capabilities to handle many regis tered
us er bloggers and gues t bloggers , mos t of whom were not tec hnic ally s avvy.
Intent. com planned to aggregate c ontent from various online s ourc es , and to
s yndicate original c ontent to many other webs ites . Os hyn s elec ted the Drupal
open s ource framework for building a C ontent Management S ys tem (C MS )
that would allow non-technical editors to eas ily manage all content and
s yndication
T he R es ults
The cus tomized C MS allows us to c ons tantly deliver great content that is
increas ing regis tered members .
Os hyn delivered Intent. com, a highly engaging webs ite des igned for s oc ial
networking. S ince the launc h, Intent. com has rapidly expanded its
members hip bas e and has rec eived much public ity. Intent. com has continued
to s ign new content s yndic ation partners , s pons ors , and advertis ers .
Intent. com is well on its way to bec oming the mos t trus ted wellnes s
des tination.
T he T ec hnology
Drupal C ontent Management S ys tem (C MS )
P HP 5
MyS QL 5
Apache 2. 0
R ed Hat E nterpris e 4 L inux
R ic h content s yndic ation model through;
R S S badges
AddThis
S end to a Friend
About Os hyn
Os hyn, Inc. is an E nterpris e T echnology Agency that has earned a reputation
for delivering innovative bus ines s s olutions for the web, mobile devices and
enterpris e technology platforms . Headquartered in L os Angeles , Os hyn' s
growing c lient lis t includes B es t B uy/G eek S quad, C oc a-C ola, E lectronic
Arts , E ps on, G raduate P ros pec ts , Fordham Univers ity, J DS Uniphas e, Harbor
C apital, L exus , Mars , Miramax, National E duc ation As s ociation, Oliver W yman,
S apient, S cripps , S outhern C alifornia E dis on and Volks wagen. Os hyn, Inc. is
partnered with the s ome of the mos t res pec ted agencies and tec hnology
providers s uch as 72andS unny, As c entium, C ris pin P orter + B ogus ky, Ogilvy &
Mather, S aatc hi & S aatchi, S pringbox, T he G roop and T eam One. Os hyn, Inc.
partners and maintains c ertific ations with leading technology providers s uc h as
E P iS erver, Micros oft, J ahia, Micros oft, OpenT ext, Oracle and S itecore. For
more information pleas e vis it us at www. os hyn. com. Follow us on T witter
@Os hyn_Inc.