rendiment en drupal .cat

35
Rendiment en DRUPAL.cat @flametes @xmorueco www.seavtec.com

Upload: javier-morueco

Post on 29-Nov-2014

131 views

Category:

Software


8 download

DESCRIPTION

Com millorar l'STACK Drupal a nivell de Infraestructura

TRANSCRIPT

Page 1: Rendiment en Drupal .Cat

Rendiment en DRUPAL.cat

@flametes@xmorueco www.seavtec.com

Page 2: Rendiment en Drupal .Cat

CTO en SEAVTEC, Consultor, Senior System AdministratorArquitectura y Administració de sistemes, Virtualització, Cloud Computing

Monitorització i Anàlisis de Rendiment

Experiència: 17 anys com sysadmin, Sysigsa, Grupo Conzentra,

eDreams, Wtransnet, Seavtec

Apache, Nginx, Tomcat, JBOSS, Jetty, Varnish, Solr, CISCO ASA, Sonicwall, Load Balancers F5, Zeus,

Postfix, MYSQL, PostGre, DNS Bind, DNSCache, NFS, OCFS2, EHCache, SAN/NAS storage Devices,

JAVA, Xen / XenServer, VMWare, Amazon Cloud Services

Javier Morueco

Page 3: Rendiment en Drupal .Cat

Senior Sysadmin a ACKStormApassionat del linux i software lliure en general.Especialitzat en rendiment i desplegament web.

Si tingués temps lliure hauria editat aquest apartat per vacilar una mica però sóc així d’humil!

Marc Navarro

Page 4: Rendiment en Drupal .Cat
Page 5: Rendiment en Drupal .Cat

PageLoad LifeTime

Source: @drupaleroDRUPALCAMP 2014

Page 6: Rendiment en Drupal .Cat

Mesurar el rendiment● Apache BenchMarkab -n 10 -c 10 http://www.corredrupalcorre.com/ab -n 100 -c 10 http://www.corredrupalcorre.com/

● JMeterhttp://www.metaltoad.com/blog/jmeter-test-plan-drupalhttps://github.com/erikwebb/drupal-jmeter-tricks

● Develhttps://drupal.org/project/devel

Page 7: Rendiment en Drupal .Cat

Mesures ExternesGoogle PageSpeed (Usar Google Chrome para test)https://developers.google.com/speed/pagespeed/insights

Pingdom Toolshttp://tools.pingdom.com

GTMetrixhttp://gtmetrix.com

ŴebPageTest (!)http://www.webpagetest.org/

IMPORTANT !Total RequestsTotal SizeTotal Time

Page 8: Rendiment en Drupal .Cat

Mesures amb Browser

@xmoruecowww.seavtec.com

● Mozilla Firefox Firebug (F12)https://getfirebug.com/

● Google Chrome Tools (F12)

Page 9: Rendiment en Drupal .Cat

Va lent !! Què faig ?

Ja tinc mètriques !!

Page 10: Rendiment en Drupal .Cat

● CPUDB Queries no optimitzades, codi no optimitzat, molts processos en execució

● MemòriaMolts processos o sistemes de Cache, consum de memòria limitat. SUMA !

● I/O DiskMolts processos en execució o en espera d’executar-se. SWAP = D.E.P

● XarxaLimitació hardware, atacs DoS, Robots, Latència x NºRequests

Va lent !! Què pot ser ?

Page 11: Rendiment en Drupal .Cat

Va lent !! Comandes! Comandestopps -auxnetstat -anp | sort -ufreepmap / iostat / sar

Calcular la memòria utilitzada per Apache/Nginx/…ps -ylC apache2 | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}'

Page 12: Rendiment en Drupal .Cat

Va lent !! Comandes! Conèixer connexions port 80 i ordenar-lesnetstat -an | grep :80 | awk '{ print $5 }' | awk -F: '{ print $1 }' | sort | uniq -c | sort -n

Processos escoltant en un port IPv4lsof -Pnl +M -i4

vmstat - http://linux.die.net/man/8/vmstatvmstat 3 / vmstat -m / vmstat -aiotop, glances (python), nmon, atop, ...

Page 13: Rendiment en Drupal .Cat
Page 14: Rendiment en Drupal .Cat

Què podem millorar I● Optimitzacions a la part de client/navegador

○ Elimina contingut innecesari○ Com menys objectes tingui la web, menys connexions per

descarregar el contingut○ Optimitza Imatges / fes servir CSS Sprites (PNG-8, PNG instead

GIF, progressive JPEG)○ Minificar i comprimir HTML,CSS,JS

AddOutputFilterByType DEFLATE text/css application/x-javascript○ Put CSS at top, JavaScript at bottom

Page 15: Rendiment en Drupal .Cat

Què podem millorar II● Optimitzacions a la part de client/navegador

○ Redueix el número de recursos externs (CSS,JS,Imatges)MAI AL HEADER !!Google Analytics: Cache tracking code file locally

○ Redueix el número de resolucions DNS, mínim número de dominis, subdominis

○ Add Expires Headers. Cache del Navegador ! (Compte amb ETags i multiservers)

○ Cookie free domains per contingut estàtic○ CDN (Content Delivery Network)

Page 16: Rendiment en Drupal .Cat

Què podem millorar III● Optimitzacions a la part de Servidor

○ Reverse Proxy / Cache (Varnish, Nginx, Memcache, …)○ Servidor Web (Apache, Nginx, Lighttpd, Tux, thttpd,...)○ PHP i OpCode Cache (APC, OpCache, …)○ MYSQL○ Drupal System Caché○ Drupal Modules

Page 17: Rendiment en Drupal .Cat
Page 18: Rendiment en Drupal .Cat

Reverse Proxy / Cache IVARNISH - 4.0Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. Varnish Cache is really, really fast. It typically speeds up delivery with a factor of 300 - 1000x, depending on your architecture.http://www.varnish-cache.org/docshttp://en.wikipedia.org/wiki/Varnish_%28software%29https://github.com/varnish/Varnish-Book/

Reverse Proxy + Cache, Backends i Load Balancing, Està fet i compilat en C, Llenguatge propi VCL - Varnish Configuration Language

Page 19: Rendiment en Drupal .Cat

Reverse Proxy / Cache IINGINXCom Varnish però afegint funcions HTTPS i Mail proxy.http://wiki.nginx.org/Main

La configuració és més complicada que Apache, però és potent quan es té per la mà.

Si vols NGINX per Drupal, la millor opció es tirar de GitHub de @perusiohttps://github.com/perusio/drupal-with-nginx

Page 20: Rendiment en Drupal .Cat

Servidor Web IAPACHE

Desactivar mòduls no necessarisa2dismod autoindex cgi dbd env negotiation reqtimeout setenvifa2dismod authz_user authz_groupfile authz_default authn_file auth_basic

Configuració bàsicaServerTokens Prod, HostnameLookups Off, ServerSignature Off, TraceEnable Off, FileETag NoneApache MPM Worker o Event sempre que sigui possible (Apache >=2.4)

Page 21: Rendiment en Drupal .Cat

Servidor Web IIMÉS APACHEConfigurar AllowOverride to None - Include .htaccess al VirtualHostMaxSpareServers, ServerLimit, MaxClientsUn process sempre creix, mai decreix fins la destrucció. MaxRequestsPerChildMai SymLinksIfOwnerMatch use FollowSymLinks

Page 22: Rendiment en Drupal .Cat

Servidor Web IIIApache MPM mod_phpUtilitza processos, cost elevat de creació, processos amb gran consum de memòria

Apache MPM workerUtilitza threads, molt més ràpid al servir peticions combinat amb FastCGI (PHP-FPM)http://wiki.apache.org/httpd/PHP-FPM

Apache MPM Event (>=Apache 2.4)Utilitza threads, el thread està dedicat a la petició, no a la connexió, no és necessari esperar KeepAliveTimeout per aprofitar threads.

Page 23: Rendiment en Drupal .Cat

Servidor Web IVMILLORANT APACHE

Aprofita KeepAlive On i KeepAliveTimeout 1-2 segons

Limitar el màxim de processos amb MaxClients. MaxClients ≈ (RAM - size_all_other_processes)/(size_apache_process)Use 'ps -ylC apache2 --sort:rss' to find process size. Divide number by 1024 to get megabytes.

Page 24: Rendiment en Drupal .Cat

Servidor Web VPROCESSOS PER CONTINGUT ESTÀTIC / DINÀMICmod_proxy and mod_rewriteProxyPassReverse / http://%{HTTP_HOST}:8088/RewriteEngine on RewriteCond %{REQUEST_URI} !.*\.(gif|png|jpg)$RewriteRule ^/(.*) http://%{HTTP_HOST}:8088/$1 [P]

Page 25: Rendiment en Drupal .Cat

Servidor Web VIALTERNATIVES A APACHE

Contingut DinàmicNGINX

Contingut EstàticLighttpdCherokeeTUXxHTTPdthttpd

Page 26: Rendiment en Drupal .Cat

PHPIMPRESCINDIBLE UN OPCODE CACHEAPC, XCache, Zend OpCache (>=5.5)

Basic PHP configurationexpose_php = Off / display_errors = Off / track_errors = Off html_errors = Off / error_reporting = E_ALL & ~E_DEPRECATED

http://www.reddit.com/r/drupal/comments/20kehz/adding_this_to_my_d7_sites_phpini_dramatically/http://haydenjames.io/set-monitor-phps-realpath_cache_size-correctly/http://www.php.net/manual/en/function.realpath-cache-size.php

realpath_cache_size = 256K / realpath_cache_ttl = 300var_dump(realpath_cache_size()); / var_dump(realpath_cache_get());

Page 27: Rendiment en Drupal .Cat

MYSQLEXEMPLE DE CONFIGURACIÓ (NOT COPY/PASTE!)[mysqld]key_buffer=256M / max_allowed_packet=16Mthread_cache_size=8 / table_cache=512 / sort_buffer_size=4M

; “70-80% of Memory available”innodb_buffer_pool_size=256M / query_cache_limit = 4Mquery_cache_size = 256M

TOOLStuning-primer.sh / mysqltuner.pl

Page 28: Rendiment en Drupal .Cat

MYSQL QUERIES IUna Query mal optimitzada, executada amb molta frecuència, pot fer arrossegar el site

Activar Slow Querieslog_slow_queries = /var/log/mysql/mysql-slow.loglong_query_time = 1log-queries-not-using-indexes

Revisar log queriesmysqladmin var | grep log_slowmysqldumpslow -t 10 /var/log/mysql/mysql-slow.log

Page 29: Rendiment en Drupal .Cat

pt-query-digest de PERCONAwget percona.com/get/percona-toolkit.tar.gz

http://www.percona.com/doc/percona-toolkit/2.2/pt-query-digest.htmlbin/pt-query-digest /var/log/mysql/mysql-slow.logbin/pt-query-digest /var/log/mysql/mysql-slow.log --limit 3bin/pt-query-digest --explain h=localhost /var/log/mysql/mysql-slow.log --limit 3

MSYQL TUNINGQuery_cache_size - Probablement la part més important a tunejarkey_buffer / innodb_buffer_pool_size / table_cachesort_buffer_size

Page 30: Rendiment en Drupal .Cat

DRUPAL MODULES ICaching: Modules that make Drupal scalehttps://groups.drupal.org/node/21897

Drupal 6- PressflowVarnish 3k-7k req/sec, Reverse proxy, No SSLMemCache - https://drupal.org/project/memcacheAPC / OpCacheCache Expiration - https://drupal.org/project/expireAuthcache - https://drupal.org/project/authcacheAjax Blocks

Page 31: Rendiment en Drupal .Cat

DRUPAL MODULES IIDrupal 7Varnish 3k-7k req/sec, Reverse proxy, No SSLAPC / OpCacheBoostMemcache - Replace _cache tables, key/value store, Fast, Memory Onlyhttps://drupal.org/project/memcacheBlock Cache AlterAuthCache - https://drupal.org/project/authcache

Page 32: Rendiment en Drupal .Cat

Varnish != Memcache != APCAPC Caché per a fitxers PHP compilats. Estalvia CPU y temps

Memcache - Object to RAM - Limit 1MbCaché key/value per enmagatzemar _cache drupal, sessions y lockshttps://drupal.org/project/memcache

Varnish - Web server ( HTTP ) Caché per enmagatzemar imatges o contingut estàtic, inclòs contingut dinàmic controlat. Pot cachejar amb compressió.

Page 33: Rendiment en Drupal .Cat

DEMORendiment !

Marc NavarroTwitter:@flametes

Page 34: Rendiment en Drupal .Cat

Resum i consells● Redueix al màxim objectes (png/gif/jpg,css,js), redueix tamany imatges● Treu dades de rendiment actual abans de fer res !● Utilitza Apache worker/event o Nginx “sempre que puguis”● Separa contingut estàtic del dinàmic per aprofitar recursos● Activa SLOW QUERIES a MYSQL per examinar● Drupal Modules: Varnish, Memcache, AuthCache, Cache Expiration● Cacheja !! Browser, Varnish, Memcache, APC - No totes són iguals ;)

● És difícil estar sempre al dia. Contracta un bon sysadmin !

Page 35: Rendiment en Drupal .Cat

Gràcies !!Preguntes ?

Javier [email protected]:@xmoruecohttp://www.linkedin.com/company/seavtec

Marc NavarroTwitter:@flametes