You are on page 1of 29

Drupal and MySQL

Mike Benshoof
November 13, 2013
www.percona.com
Agenda

Overview

Version Differences

Database Confi!ration

"ca#in$%&

'!nin$(erformance
www.percona.com
What is Drupal?

Open "o!rce CM"

)&M( "tack Base*

Oriina##+ (%($M+",)

Now, inc#!*es an+ DB s!pporte* b+ (DO

http-$$www.*r!pa#.or
www.percona.com
Version Differences

)imitin Disc!ssion to M+",) Differences

(er Dr!pa#.s /Convertin 0.1 to 2.13 Doc-

/Dr!pa# 2 intro*!ces a comp#ete#+ new *atabase &(43

"ome of the biest *ifferences inc#!*e-

D+namic ,!er+ B!i#*ers

5orma# (repare* "tatements

"pecific 4N"67'$8(D&'6$D6)6'6 f!nctions

(DO is now 76,8476D 9ma:or chane;


www.percona.com
Sample Differences

"tan*ar* "6)6C' < note the bo!n* variab#es 9i.e. -!i*,


-t+pe;

8p*ate < !ses *b=!p*ate with bo!n* variab#es


www.percona.com
Conceptual Differences

Dr!pa# 0

*atabase.inc > *atabase.m+s?#.inc are more proce*!ra#

Native M+",) interaction 9m+s?#$m+s?#i;

m+s?#i=connect, m+s?#i=?!er+, etc

Dr!pa# 2

*atabase.inc is ob:ect oriente* an* *river base*

(DO M+",) interaction with bo!n* parameters an*


prepare* statements

Database--@etConnection9;ABprepare9;ABe1ec!te9;
www.percona.com
Database Configuration

Database confi!ration is broken *own into


ke+$taret pairs

Ce+ represents active *atabase /poo#3

'aret represents sin#e *atabase in poo#

Va#i* tarets are /*efa!#t3 or /s#ave3

Ce+s are !ser *efine*

5!## confi!ration #ocate* in


sites$*efa!#t$settins.php 9or specific site;
www.percona.com
Configuration (cont

Basic Confi!ration < "in#e server, a## traffic


sent to this host

Note, this is set !p b+ *efa!#t with the insta##er


www.percona.com
Configuration (cont

"econ*ar+ Database < Man!a##+ specif+ this


connection in a mo*!#e

Can be M+",) or other (DO *ata so!rce


www.percona.com
Configuration (cont

M!#tip#e 'arets < 'his is set !p for master$s#ave

Defa!#t$"#ave are the on#+ options

NO'6- if !sin m!#tip#e s#aves, one wi## be chosen at ran*om


for each re?!est
www.percona.com
!reat""" #o$ What??
%ow *o +o! !ti#iDe
*ifferent *atabases
from co*eE
www.percona.com
Scaling the Database

'his is where the Defa!#t$"#ave confi!ration


comes into p#a+

Drupal may try to connect to a slave server when


appropriate and if one is not available will simply fall
back to the single master server

"en* rea*s to the s#ave 9with rea*Aon#+ !ser;

"en* writes to the master 9with write !ser;

/"tick3 *e#a+Asensitive ?!eries to master

"!pport for this is #imite* in Dr!pa# Core


www.percona.com
%n code& por fa'or?

&s parts of the Core *on.t !ti#iDe b+ *efa!#t, it ma+ be


nee*e* to man!a##+ sen* rea*s to the s#ave

"imp#+ a** .taret. FB .s#ave. to the options

Note < this can impact rep#ication *e#a+Asensitive ?!eries


www.percona.com
Disabling Sla'e Ser'ers

4n #aAsensitive environments, +o! can e1p#icit#+


*isab#e the !se of s#ave servers-

db_ignore_slave()

Go! can a#so force to the master for specific b+


!sin the same #oic as s#ave-

array('target' => 'default')

H="6""4ONI.inore=s#ave=server.J

"kips s#ave for a set n!mber of secon*s

@oo* for write fo##owe* b+ rea*9s;


www.percona.com
And ()ternal Connections?

'his is where the *istinct


*atabase /ke+3 comes into
p#a+

Chane the active *atabase

Go! can a#so !ti#iDe


*efa!#t$s#ave *atabases here
as we##
www.percona.com
A'ailability

"p#ittin rea*s$writes can be comp#icate* an* in


some cases, re?!ire man!a# co*e chanes

5ort!nate#+, %& is simp#e 9from app#ication


stan*point;

8se base confi!ration 9*efa!#t, *efa!#t;

Defa!#t *b server is act!a##+ a V4(

5ai#over is hi**en from the app#ication

&#so, man!a# fai#over via the app#ication is an option


www.percona.com
A'ailability

Different options

"imp#e master$s#ave with man!a# fai#over


9reconfi!re app#ication confi;

Master$"#ave an* shift 4( on *atabase 9M%&;

Master$Master behin* V4( 9%&(ro1+, Bi4(, etc;

(KC behin* a V4(

(7M to manae fai#over an* V4(

4n most cases, the app#ication wi## :!st shift


traffic an* not nee* to be reconfi!re*
www.percona.com
Default %nstall *uning

8se MemcacheLL

"emaphore$)ockin &(4

(rofi#e ear#+ an* oftenL


www.percona.com
Cache +, -aster

B+ *efa!#t, cache is store* in M+",)

'his act!a##+ D./0L(S the n!mber of


*atabase ?!eries in norma# pae browsin

'his ass!mes pop!#ate* cache

Cache misses wi## act!a##+ increase the M+",)


traffic even more, a**in W1%*( traffic

6ven with no content bein create*, +o! have ma:or


write impact on the *atabase
www.percona.com
0enchmar2ing

"imp#e MMeter 'est (#an

Browse home pae no*es

7an*om#+ se#ect a few no*es$paes

Data pop!#ate* !sin the *eve#opment mo*!#e

10 iterations of pro1+Acapt!re* test p#an


www.percona.com
Default %nstall 3rofiling
# 1.3s user time, 10ms system time, 24.32M rss, 200.27M vsz
# Current date: Mon Sep 30 19:46:41 2013
# ostname: !entos6"#e$dev
# %i&es: 'var'&i$'mys(&'!entos6"#e$dev"s&o#.&o)
# Overall: 3.50k total, 29 unique, 17.84 QPS, 0.06 !on!urren!" ##########
# *ime ran)e: 2013"09"30 19:39:+4 to 19:43:10
# ,ro-i&e
# .an/ 0uery 12 .esponse time Ca&&s .'Ca&& 3'M 1tem
# 4444 444444444444444444 4444444444444 44444 444444 44444 444444444444444
# 1 05C61%%72+C718C%96 0.+009 3.9: +30 0.0009 0.04 S$%$&' !a!(e#)oot*tra+
# 2 05C9+468279190C72% 1.9323 14.4: 470 0.0039 0.43 S$%$&' !a!(e#,enu
# 3 05692336090967923% 4.7602 37.+: 403 0.0119 1.11 S$%$&' !a!(e#-iel.
# 4 0509630%76644707+0 0.3099 2.4: 342 0.0009 0.07 S$%$&' !a!(e
# + 05821783C8+6226%37 0.1692 1.3: 139 0.0012 0.03 S6;6C* ur&<a&ias

5!## ?!er+ capt!re 9#on=?!er+=timeF0;

7!nnin in VM, so sorte* b+ co!nt

ptA?!er+A*iest AA#imitF30 $var$#ib$m+s?#$s#ow.#o <or*erAb+F,!er+=time-cnt

#ote4 'his ass!mes a pop!#ate* cache


www.percona.com
Default %nstall 5 Continued

No in*e1in iss!es in top ?!eries

(rimar+ ke+ or CON"' in*e1 hits

'op N ?!eries are a## "6)6C' O cache=P

678 of a## ?!eries 912NQ o!t of 3.Qk;

9:8 of b+tes sent to the c#ient

;;8 of rows e1amine*

Rhen consi*erin ?!er+ optimiDation, the best


?!er+ is one that is never r!n...
www.percona.com
(nter memcached"""
# 900ms user time, 100ms system time, 22.31M rss, 199.79M vsz
# Current date: Mon Sep 30 20:14:26 2013
# ostname: !entos6"#e$dev
# %i&es: 'var'&i$'mys(&'!entos6"#e$dev"s&o#.&o)
# Overall: 1.74k total, 25 unique, 16.59 QPS, 0.05 !on!urren!" ##########
# *ime ran)e: 2013"09"30 20:12:09 to 20:13:+3
# ,ro-i&e
# .an/ 0uery 12 .esponse time Ca&&s .'Ca&& 3'M 1tem
# 4444 444444444444444444 4444444444444 44444 444444 44444 444444444444444
# 1 05821783C8+6226%37 0.0304 0.6: 139 0.0002 0.00 S6;6C* ur&<a&ias
# 2 05793099C864687829 0.1669 3.2: 90 0.0019 0.06 S6;6C* ur&<a&ias
# 3 0578226672%7C269%6 0.3140 6.0: 90 0.003+ 0.03 S6;6C* $&o!/ed<ips
# 4 05CC47742+11682222 0.246+ 4.7: 90 0.0027 0.21 S6*
# + 050962C664707+C+2+ 0.07+9 1.4: 99 0.0009 0.03 S6*

Note the h!e *rop in tota# ?!eries

<"=2 > ?"@62

&#so note the N ?!er+ *ifference in !ni?!e

;9 uniAue > ;= uniAue

On#+ ?!eries missin are the cache=P tab#es


www.percona.com
Loc2ing A3%

4mportant for preventin


cache stampe*es

Rrap e1pensive ca##s with


#ockin 9i.e. variab#e=initia#iDe;

Defa!#t !ses semaphore


tab#e in M+",) 94nnoDB;

Rrite overhea* to *atabase


9f#!shin, re*o #o, etc;

Does it nee* to be *!rab#eE


www.percona.com
Loc2ing A3% (cont

"amp#e DB ca##s for a sin#e pae #oa*-


=root>!entos6"#e$dev drupa&?# tai& "- 'var'&i$'mys(&'!entos6"#e$dev"s&o#.&o) @ )rep
"i semapAore
1BS6.* 1B*C semapAore Dname, va&ue, e5pireE 38;F6S ...
26;6*6 %.CM semapAore G6.6 name ...
1BS6.* 1B*C semapAore Dname, va&ue, e5pireE 38;F6S ...
26;6*6 %.CM semapAore G6.6 name ...
26;6*6 %.CM semapAore G6.6 name ...
1BS6.* 1B*C semapAore Dname, va&ue, e5pireE 38;F6S ...
26;6*6 %.CM semapAore G6.6 name ...
1BS6.* 1B*C semapAore Dname, va&ue, e5pireE 38;F6S ...
26;6*6 %.CM semapAore G6.6 name ...

S write ?!eries for sin#e pae #oa* Dredo &o), pa)e -&usAin), et!E

Depen*in on 4nnoDB confi!ration 9inno*b=f#!sh=#o=at=tr1=commit, etc;,


this can #ea* to severa# 4O(s 9e1pensive;
www.percona.com
Loc2ing Alternati'es

Memor+ enine for semaphore tab#e

7emoves 4nnoDB overhea*

No *isk access nee*e* < tab#e in 7&M

Native imp#ementation 9no p#!in or mo*!#es;

NonA*!rab#e

#egati'e < tab#eA#eve# #ockin can re*!ce conc!rrenc+, b!t this


tab#e is t+pica##+ sma## 9an* hopef!##+ not !se* often;

Memcache #ockin

"ince +o! are a#rea*+ !sin memcache... 9rihtE;

8ses the 9#oba#; Memcache--&** operation

NonA*!rab#e as we##
www.percona.com
3rofiling B (arly and .ften

5in*in prob#ems ear#+ is ke+

Missin in*e1es, etc

#on=?!er+=time F 0

5!## verbosit+ 9if !sin (ercona "erver;

(tA?!er+A*iest

7ows=e1amine* B 7ows=sent 9s!boptima# in*e1;

61ec!tion time

AAreview < track new ?!eries over time 9new


mo*!#es, etc;
www.percona.com
,!estionsE
michael"benshoofCpercona"com

You might also like