A B L E … ⇒ Lock ⇒ Downtime :- ( Lösung: pt-online-schema-change $ p t - o n l i n e - s c h e m a - c h a n g e - - a l t e r = " A D D l o g o i d I N T " D = c b , t = c b _ n e w s A l t e r i n g ` c b ` . ` c b _ n e w s ` . . . C r e a t i n g n e w t a b l e . . . C r e a t e d n e w t a b l e c b . _ c b _ n e w s _ n e w O K . A l t e r i n g n e w t a b l e . . . A l t e r e d ` c b ` . ` _ c b _ n e w s _ n e w ` O K . C r e a t i n g t r i g g e r s . . . C r e a t e d t r i g g e r s O K . C o p y i n g a p p r o x i m a t e l y 1 1 1 9 r o w s . . . C o p i e d r o w s O K . S w a p p i n g t a b l e s . . . S w a p p e d o r i g i n a l a n d n e w t a b l e s O K . D r o p p i n g o l d t a b l e . . . D r o p p e d o l d t a b l e ` c b ` . ` _ c b _ n e w s _ o l d ` O K . D r o p p i n g t r i g g e r s . . . D r o p p e d t r i g g e r s O K . S u c c e s s f u l l y a l t e r e d ` c b ` . ` c b _ n e w s ` .
- c o p y . p h p 1. Struktur der Datenbank klonen 2. Selektiv Daten in geklonte DB kopieren 3. m y s q l d u m p der geklonten DB an s t d o u t senden Entwicklungsumgebung: m y s q l - s y n c - d e v . s h # ! / b i n / s h s s h - C d b 2 . c o m p u t e r b a s e . d e ' d b - d e v - c o p y . p h p ' | \ m y s q l - u c o m p u t e r b a s e c o m p u t e r b a s e $ t i m e m y s q l - s y n c - d e v . s h r e a l 0 m 5 7 . 6 5 1 s
SSH-Tunnel Server: phpMyAdmin erreichbar auf Port 1443, der in nginx und iptables nur für 127.0.0.1 / ::1 freigegeben ist Client-Terminal: s s h - N - L 1 4 4 3 : l o c a l h o s t : 1 4 4 3 < s e r v e r > Client-Browser: h t t p s : / / l o c a l h o s t : 1 4 4 3 /
l i s t e n = 1 2 7 . 0 . 0 . 1 : 9 0 0 0 p m = s t a t i c p m . m a x _ c h i l d r e n = 1 6 [ p r e i s v e r g l e i c h ] l i s t e n = 1 2 7 . 0 . 0 . 1 : 9 0 0 1 p m = s t a t i c p m . m a x _ c h i l d r e n = 2 l o c a t i o n / p r e i s v e r g l e i c h { f a s t c g i _ p a s s 1 2 7 . 0 . 0 . 1 : 9 0 0 1 ; . . . }
iptables-Modul h a s h l i m i t 2. Beschränken der Anzahl gleichzeitiger Verbindungen → iptables-Modul c o n n l i m i t 3. Connection-Tracking-Timeouts herabsetzen → Datei / e t c / s y s c t l . c o n f n e t . n e t f i l t e r . n f _ c o n n t r a c k _ t c p _ t i m e o u t _ c l o s e _ w a i t = 1 0 n e t . n e t f i l t e r . n f _ c o n n t r a c k _ t c p _ t i m e o u t _ e s t a b l i s h e d = 3 6 0 0 . . .
viel teurer als HTTP-Requests nach statischen Dateien h t t p { . . . l i m i t _ r e q _ z o n e $ b i n a r y _ r e m o t e _ a d d r z o n e = f l o o d : 1 0 m r a t e = 2 r / s ; s e r v e r { . . . l o c a t i o n ~ \ . p h p $ { l i m i t _ r e q z o n e = f l o o d b u r s t = 8 ; . . . } } }
m a i n . c s s antwortet nginx mit m a i n . c s s . g z 2. Deployment: Erstellen der . g z -Dateien mit Größe [Byte] Zeit [ms] main.css 72.865 - gzip 14.471 10 gzip -9 14.366 13 zop i 13.618 355 gzip_static Zop i
Konzentration auf die Datenbank! 1. Während der Entwicklung: jede neue SQL-Query mit E X P L A I N S E L E C T . . . analysieren 2. Im Live-Betrieb: Einen Blick werfen in … MySQL Slow Query Log PHP-FPM Slow Log 3. Caching: nächste Folie
Memcached $ c o d e = $ t h i s - > m e m c a c h e - > g e t ( ' i n d e x - n e w s ' , f u n c t i o n ( ) { $ h t m l = . . . ; / / G e n e r a t e H T M L r e t u r n $ h t m l ; } ) ; $ t h i s - > m e m c a c h e - > d e l e t e ( ' i n d e x - n e w s ' ) ;
Bei News-Veröffentlichung $ t h i s - > g e a r m a n - > d o B a c k g r o u n d ( ' f e e d - u p d a t e ' , ' n e w s ' ) ; Hintergrund-Prozess $ w o r k e r = n e w L i b \ G e a r m a n W o r k e r ( ) ; . . . $ w o r k e r - > a d d F u n c t i o n ( ' f e e d - u p d a t e ' , [ L i b \ F e e d s : : c l a s s , ' u p d a t e F e e d ' ] ) ; . . . w h i l e ( $ w o r k e r - > w o r k ( ) ) ; Weitere Beispiele: Bild-Upload, Twitter-Status, …
u l l in temporärem Verzeichnis 2. CSS und JS komprimieren (wenn geändert) 3. Kopieren der Dateien ins Ziel-Verzeichnis via r s y n c mit dem Parameter - - d e l a y - u p d a t e s