Apache / Nginx + FPM - Magento

moneygascityInternet και Εφαρμογές Web

8 Δεκ 2013 (πριν από 3 χρόνια και 6 μήνες)

284 εμφανίσεις

Chris
W
ells

CEO
-

N
excess

Laying the Foundation

Magento
Performance

f
or

a
nd Optimization


The Ambassador Bridge


USA/Canada

The Ambassador Bridge


USA/Canada

Today’s Topics


A
no
t
e on
perm
i
ss
i
ons


Common pitfalls


L
A
MP
L
A
MP
L
A
MP


P
H
P
bas
i
cs
&
t
he P
H
P
hando
f
f


A
p
ache
vs.
N
g
i
nx


MyS
Q
L
vs.
P
e
rcona


C
ach
i
ng be
st

pra
ct
i
ces


U
s
i
ng
V
arn
i
sh
wi
t
h
Magen
t
o


F
i
nalno
t
es


Q
ue
st
i
ons
e
tc


Permissions
Matter


chmod 666
/ 777
=
“make
i
t
w
ork good”


F
i
x
i
t

(re
l
a
t
i
ve
t
o your
w
eb
roo
t
)

1.
O
w
n
your
f
il
es
/
d
i
re
ct
or
i
es


f
i
nd
\
-
exec
cho
w
nmagen
t
o
.
magen
t
o
{}
\
;

2.
Make sure bro
w
s
i
ng d
i
re
ct
or
i
es
f
or o
t
hers
i
sn
'tt
r
i
v
i
a
l
.


f
i
nd
-
t
ype d
\
-
exec
chmod

7
1
1
{}
\
;

3.
Make sure
t
he
w
ebserver can read
i
t
a
l
l


f
i
nd
-
t
ype
f
\
-
exec
chmod

644
{}
\
;


Permissions
Matter
(cont.)

1.
P
H
P
scr
i
ps are
f
or your eyes
on
l
y


f
i
nd
-
t
ype
f

-
name “
*.
php

\
-
exec
chmod

600
{}
\
;

2.
Soare
con
f
i
g
f
il
e
s
!


chmod

600 app
/
etc
/*.
xml

Common Pitfalls


Magento log management (or lack thereof)


Poorly written 3
rd

party extensions


CRON job configuration (simple, but often forgotten)


The CRON pile
-
up


Re
-
indexing


The re
-
index pile
-
up


What type of indexing to use


When/why to re
-
index


Changing core Magento files

PHPBasics


U
seAPC(as an opcode cache on
l
y
)


ap
c.shm_s
i
ze
=
256M (a
t
l
ea
st
)


ap
c.
num_
f
il
es_h
i
n
t
=
10000 (a
t
l
ea
st
)


apc_
st
a
t
=
0
(f
or produ
ct
i
on)


B
u
mp
memory_
li
m
i
t

(512M
w
orks
w
e
ll
)


T
urn
OFF
open_based
i
r


Leav
i
ng
i
t
O
Nk
ill
s
t
he
rea
l
pa
t
h

cache


U
se a recen
t

vers
i
on o
f
P
H
P


5
.
4
.
x
may be
t
oo recen
t


T
hePHPHand
-
o
f
f


A
p
ache
+
mod_php


R
uns
as
w
ebserver
user


U
n
i
f
i
ed mega
-
process


A
p
ache
+
suP
H
P
/
phpS
u
EXEC


R
uns
as
you


Ex
p
ens
i
ve
t
o crea
t
e


A
p
ache
/
N
g
i
nx
+
P
H
P
-
F
PM


R
uns
as
you


C
heap
t
o use (processes are
w
a
i
t
i
ng)


Sc
al
es
more e
f
f
i
c
i
en
t
l
y
t
han a
l
lo
ft
he above

Apache +
mod_php

(Big process, web user)

Apache +
suPHP

(Huge cost / script,

secure user)

Apache /
Nginx

+ FPM

(Efficient Separation,

Secure User)

One
-
to
-
One

Server/PHP Mapping

Many
-
to
-
Many

Server/PHP Mapping

e
xec()

e
xec()

e
xec()

c
onnect()

c
onnect()

c
onnect()

T
he
W
ebserverShowdown

VS.


T
he

an
s
w
e
r
i
s


YES!


A
p
ache comes b
l
oa
t
ed


remove need
l
ess modu
l
e
s!


Magen
t
o

suppo
rt
sA
p
ache
ou
t
-
o
f
-
t
he
-
box


R
e
w
r
i
t
es
w
ork as
expe
ct
ed


Ext
ens
i
ons
may assumeA
p
ache
-
li
ke
f
ea
t
ures ex
i
st


P
H
P
-
F
PM

l
eve
l
s
t
he pe
rf
ormance
/

sca
l
ab
ili
t
y
f
i
e
l
d


V
arn
i
sh he
l
ps as
w
e
l
l(
w
e

re ge
tt
i
ng ahead o
f

ourse
l
ves)


G
o
wi
t
h
w
ha
t

you kno
w
!!


So…Apache
vs.
Nginx
?

Transactions per Second
T
=
1
T
=10
T
=
20
T
=
30
T
=
40
T
=
50
T
=
60
T
=70
T
=80
T
=90
T
=
100
0
100
200
300
400
500
600
Apache + PHP-FPM vs. Nginx + PHP-FPM
Apache + PHP-FPM
Nginx + PHP-FPM
T
i
m
e
in
M
in
u
t
e
s
Transactions per Second
1
s
t m
i
nu
t
e
2
n
d
t
h
r
u
5
t
h
m
i
nu
te
6t
h
t
h
r
u
10t
h
mi
n
u
te
11h
t
h
r
u
20
t
h
m
i
n
u
te
2
1
s
t
t
h
r
u
3
0
t
h
mi
n
u
te
3
1
s
t
t
h
r
u
4
0
t
h
mi
n
u
te
4
1
s
t
t
h
r
u
6
0
t
h
min
u
te
A
v
e
ra
ge
T
ra
n
s
/s
96
.
3
4
1
1
5.
1
2
1
5
4.
5
3
274
.
87
482
.
03
542
.
34
546
.
8
7
+
- Ma
r
g
i
n
0
.
00
1
3
.63
2
1
.90
4
4
.48
3
1
.57
5.
3
9
1.
1
5
L
o
w
e
r
L
i
m
i
t
90
.
0
0
1
0
1.
4
9
1
3
2.
6
3
230
.
39
450
.
46
536
.
95
545
.
7
2
U
p
p
e
r
L
i
m
i
t
1
0
0.
0
0
1
2
8.
7
5
1
7
6.
4
3
319
.
35
513
.
60
547
.
72
548
.
0
2
0
1
0
0
2
0
0
3
0
0
4
0
0
5
0
0
6
0
0
Apache + PHP-FPM Performance
A
v
e
rag
e
T
ran
s
/s
+
- Ma
r
g
i
n
L
o
w
e
r
L
i
m
i
t
U
p
p
e
r
L
i
m
i
t
Transactions per Second
1
s
t m
i
nu
t
e
2
n
d
t
h
r
u
5t
h
m
i
nu
te
6
t
h
t
h
r
u
1
0
t
h
m
i
n
u
t
e
11
h
t
h
r
u
20
t
h
mi
n
u
te
21
s
t
t
h
r
u
30t
h
m
i
n
u
te
31
s
t
t
h
r
u
40t
h
mi
n
u
te
41
s
t
t
h
r
u
60t
h
m
i
n
u
te
A
v
e
ra
ge
T
ra
n
s
/s
95.08
114.43
152.46
273.23
485.08
547.84
555.11
+
-
M
ar
g
i
n
0.00
14.24
20.45
46.33
33
.34
1.94
1
.
6
1
L
o
w
e
r L
i
m
i
t
95.00
100.19
132.01
226.91
451.73
545.90
553.50
U
p
p
e
r L
i
m
i
t
100.00
128.67
172.91
319.56
518.42
549.79
556.72
0
100
200
300
400
500
600
Nginx + PHP-FPM Performance
A
v
e
ra
ge
T
ra
n
s
/s
+
-
M
ar
g
i
n
L
o
w
e
r
L
i
m
it
U
p
p
e
r L
i
m
i
t
VS.

T
heDBShowdown

P
erconawins
...
noneed
to
use
fa
de
-
ins
...

N
e
xt
S
lide

0
200
400
600
800
1000
1200
1400
1600
1800
2000
1
B
uy
e
r
100
B
r
o
w
s
e
r
s
10
B
uy
e
rs
1000
B
r
o
w
s
e
r
s
20
B
u
y
e
rs
2000
B
r
o
w
s
e
r
s
30
B
u
y
e
rs
3000
B
r
o
w
s
e
r
s
4
0
Bu
ye
rs
4
0
0
0
B
r
o
w
s
e
r
s
50
B
uy
e
rs
5000
B
r
o
w
s
e
r
s
My
S
Q
L
v
s
.
P
e
r
c
o
n
a
My
S
Q
L
P
e
r
c
o
n
a
d
n
o
c
e
S
r
e
P
s
n
o
i
t
c
a
s
n
a
r
T
P
e
r
c
o
n
a
0
2
4
6
8
10
12
14
16
18
20
750
1000
2000
3000
Ord
e
r
s
P
e
r S
e
c
o
n
d
N
u
m
b
e
r
o
f
Bu
y
e
rs
Orders per Second Using Percona

P
e
rcona

s
X
t
ra
D
B

i
s
f
a
st



espec
i
a
ll
y under
l
oad


P
e
rcona
i
s a s
i
mp
l
e rep
l
acemen
t


M
y
.
cn
f
t
w
ea
ks:


i
nnodb_
t
hread_concurrency
=
24 (1


2x # o
f
cores)


i
nnodb_bu
f
f
er_poo
l
_s
i
ze
=
16
G

(a
t
l
ea
st
)


i
nnodb_
f
l
ush_
l
og_a
t
_
t
rx_comm
i
t
=
1


i
nnodb_
i
o_capac
i
t
y
=
800


i
nnodb_
f
l
ush_me
t
hod
=
O
_
D
I
R
E
C
T

Percona's
Benefits
/
T
weaks

T
ime
to
Cachein


Memcache
:


P
R
O
:

mu
l
t
i
-
t
hreaded
,

socke
t/
t
cp
based


C
O
N
:

no
t
agg
i
ng


R
ed
i
s


PRO: TAGGING, fast, socket/
tcp

based


CON: single threaded


AP
C:


PRO: provides op
-
code cache


CON: no CLI usage, can’t share, no tagging,
restartcauses flush, we avoid for key/value pair
caching


U
s
i
ng
Magen
t
o
E
n
t
erpr
i
se?


T
urn
on
t
he
F
u
l
lP
a
ge
C
ache
(
F
P
C
)


H
uge
t
hroughpu
t
ga
i
ns


H
uge
response
t
i
me
ga
i
ns


U
se
a ded
i
ca
t
ed
R
ed
i
s
i
n
st
ance
!


Q
u
i
ck
,

easy and
i
t
w
orks


N
o
t
U
s
i
ng
E
n
t
erpr
i
se?


No simple “light
-
switch” solution


But … Varnish is a good option :)

Caching
Best
Practices

Part
1

T
ran
s
actio
n
s
P
e
r
S
e
cond
0
10
0
20
0
30
0
400
500
600
T
=
1
T
=
3
T
=
5
T
=
7
T
=
9
T
=
11
T
=
13
T
=
15
T
=
17
T
=
19
T
=
21
T
=
23
T
=
25
T
=
27
T
=
29
T
=
31
T
=
33
T
=
35
T
=
37
T
=
39
T
=
41
T
=
43
T
=
45
T
=
47
T
=
49
T
=
51
T
=
53
T
=
55
T
=
57
T
=
59
T
=
61
T
=
63
T
=
65
T
=
67
T
=
69
T
=
71
T
=
73
T
=
75
T
=
77
T
=
79
T
=
81
T
=
83
T
=
85
T
=
87
T
=
89
T
=
91
T
=
93
T
=
95
T
=
97
T
=
99
F
u
ll
P
a
g
e
C
a
ch
e E
n
a
b
le
d
vs
.
Disa
b
led
F
PC
D
i
s
a
b
l
e
d
F
P
C
E
n
a
b
l
e
d
Tim
e
I
n
Mi
nu
tes
0
0.5
1
1.5
2
2.5
3
3.5
T
=
1
T
=
3
T
=
5
T
=
7
T
=
9
T
=
11
T
=
13
T
=
15
T
=
17
T
=
19
T
=
21
T
=
23
T
=
25
T
=
27
T
=
29
T
=
31
T
=
33
T
=
35
T
=
37
T
=
39
T
=
41
T
=
43
T
=
45
T
=
47
T
=
49
T
=
51
T
=
53
T
=
55
T
=
57
T
=
59
T
=
61
T
=
63
T
=
65
T
=
67
T
=
69
T
=
71
T
=
73
T
=
75
T
=
77
T
=
79
T
=
81
T
=
83
T
=
85
T
=
87
T
=
89
T
=
91
T
=
93
T
=
95
T
=
97
T
=
99
R
e
spo
n
se
Time
W
i
t
h
o
u
t
F
PC
W
i
t
h
F
PC
Ti
m
e
I
n
Mi
n
u
tes
P
a
g
e
Lo
a
d
Ti
m
e
In
S
ec
o
nd
s
Caching
Best
Practices

Part
2


S
e
t
up
t
he Magen
t
o 2
-
l
evel
cache


Fast cache =
memcache


Mu
l
t
i
-
t
hreaded
,

responds be
tt
er under heavy
l
oad


R
un
mu
l
t
i
p
l
e
R
ed
i
s
i
f

you
li
ke


Slow cache =
Redis


S
i
ng
l
e
-
t
hreaded


S
l
ow
cache may no
t

be used


S
e
t
up a ded
i
ca
t
ed memcache
f
or sess
i
ons


S
i
ze
t
he caches corre
ct
l
y!
F
a
st

cache shou
l
d
f
i
t

a
l
lda
t
a
!

0
1
0
20
3
0
40
50
6
0
70
8
0
9
0
100
0
50
0
100
0
150
0
200
0
250
0
3000
3500
4000
4500
T
=
1
T
=
3
T
=
5
T
=
7
T
=
9
T
=11
T
=
1
3
T
=15
T
=17
T
=
1
9
T
=21
T
=23
T
=
2
5
T
=27
T
=
2
9
T
=
3
1
T
=33
T
=
3
5
T
=
3
7
T
=39
T
=
4
1
T
=
4
3
T
=45
T
=
4
7
T
=49
T
=51
T
=
5
3
T
=55
T
=57
T
=
5
9
T
=61
T
=63
T
=
6
5
T
=67
T
=
6
9
T
=
7
1
T
=73
T
=
7
5
T
=
7
7
T
=79
T
=
8
1
T
=
8
3
T
=85
T
=
8
7
T
=89
T
=91
T
=
9
3
T
=95
T
=97
T
=
9
9
Cac
h
e
Size
F
u
ll
P
a
g
e
C
a
c
h
e
F
a
s
t
Ca
c
h
e
S
l
o
w
Ca
c
h
e
Ti
m
e
I
n
Mi
nu
tes
MB used
0
1
0
20
3
0
40
50
6
0
70
8
0
9
0
100
0
50
0
100
0
150
0
200
0
250
0
3000
3500
4000
4500
T
=
1
T
=
3
T
=
5
T
=
7
T
=
9
T
=11
T
=
1
3
T
=15
T
=17
T
=
1
9
T
=21
T
=23
T
=
2
5
T
=27
T
=
2
9
T
=
3
1
T
=33
T
=
3
5
T
=
3
7
T
=39
T
=
4
1
T
=
4
3
T
=45
T
=
4
7
T
=49
T
=51
T
=
5
3
T
=55
T
=57
T
=
5
9
T
=61
T
=63
T
=
6
5
T
=67
T
=
6
9
T
=
7
1
T
=73
T
=
7
5
T
=
7
7
T
=79
T
=
8
1
T
=
8
3
T
=85
T
=
8
7
T
=89
T
=91
T
=
9
3
T
=95
T
=97
T
=
9
9
Cac
h
e
Ut
i
l
i
z
a
ti
o
n
F
u
ll
P
a
g
e
C
a
c
h
e
F
a
s
t
Ca
c
h
e
S
l
o
w
Ca
c
h
e
Ti
m
e
I
n
Mi
nu
tes
Cache Hit Percentage
CachingtheCachesWith
V
arnish


C
aches en
t
i
re pages (or pa
rt
s o
ft
hem
)


Use an extension to integrate with
Magento


Turpentine is ours


Free
/ open source for a
l
l
Magen
t
o
vers
i
ons


HU
GE
pe
rf
ormance ga
i
ns
f
or v
i
s
i
t
ors


R
equ
i
res more
t
hough
tt
han
F
PC


SSLrequ
i
res
f
u
rt
her hoop
-
j
ump
i
ng


ESI
requ
i
res ye
tf
u
rt
her
hoop
-
j
ump
i
ng

CachingtheCachesWith
V
arnish
(cont
.)

0
1000
2000
3000
4000
5000
6000
7000
8000
25
0
500
d
n
o
c
e
S
r
e
P
s
n
o
i
t
c
a
s
n
a
r
T
C
o
n
currency
Varnish / Turpentine vs. FPC
Apache / PHP-FPM + FPC
Apache / PHP-FPM + Varnish / Turpentine
1
1
0
10
0
1000
1000
0
T
=1
T
=
2
T
=
3
T
=4
T
=5
T
=6
T
=
7
T
=8
T
=9
T
=10
T
=11
T
=
12
T
=13
T
=14
T
=15
T
=
16
T
=
17
T
=18
T
=19
T
=20
T
=
21
T
=
22
T
=23
T
=24
T
=25
T
=
26
T
=27
T
=28
T
=29
T
=
30
T
=
31
T
=32
T
=33
T
=34
T
=
35
T
=
36
T
=37
T
=38
T
=39
T
=
40
T
=41
T
=42
T
=43
T
=44
T
=
45
T
=46
T
=47
T
=48
T
=
49
T
=
50
T
=51
T
=52
T
=53
T
=
54
T
=
55
T
=56
T
=57
T
=58
T
=
59
T
=60
T
ran
s
actio
n
s
P
e
r
S
e
cond
T
i
me
(m
in
u
t
e
s
)
Varnish / Turpentine vs. FPC
Apache / PHP-FPM + Varnish / Turpentine
Apache / PHP-FPM + FPC
0
0.5
1
1.5
2
2.5
3
R
esponse
Time
W
i
t
h
F
PC
Varnish / T
u
r
p
e
n
ti
n
e
P
age
L
oad
T
ime in
S
e
c
onds
T
ime in minu
t
es

777 and 666 are bo
t
h ev
i
l


P
H
P
-
F
PM

i
s
t
he
w
ay
t
o go


A
p
ache and
N
g
i
nx can be
f
r
i
ends


P
e
rcona


F
PC
wi
t
h
R
ed
i
s back
-
end


T
w
o
-
l
evel
cach
i
ng


Fast cache =
memcache


Slow cache =
Redis


T
urpen
t
i
ne
/
V
arn
i
sh
i
f

you
can

F
inal
T
houghts

T
urpen
t
i
ne
i
s ava
il
ab
l
e
a
t:

h
ttp
://
ww
w
.
nexce
ss.
ne
t/t
urpen
t
i
ne
or on
Magen
t
o
C
onne
ct


O
ur
newpe
rf
ormance
w
h
i
t
epaper
i
s ava
il
ab
l
e
a
t:

h
tt
p
:
/
/
ww
w
.
nexce
ss.
ne
t
/
magen
t
o
-
be
st
-
pra
ct
i
ces
-
w
h
i
t
epaper

MoreInformation:

T
hank
Y
ou!









Questions?