sábado, 2 de junio de 2012


PRINCIPOS FUNDAMENTALES DE OPTIMIZACION DE UN SITIO WEB
------------------------------------------------------------------------------------------------------

Procedimientos:
1. Instalar los paquetes:
>sudo apt-get install

kcachegrind
php5-xdebug-> analizar php5, sobrecarga al servidor el doble
iotop
iftop

2. Editar xdebug
>sudo vim /etc/php5/apache2/conf.d/xdebug.ini
agregar:

zend_extension=/usr/lib/php5/20090626/xdebug.so
xdebug.default_enable = 1
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = /tmp/

3. reiniciar apache
>sudo service apache2 restart

4. Iniciar la pagina www.sitioweb.com
5. Listar los archivos generados por xdebug
>ls /tpm
 lista archivos: cachegrind.out-14691

6. Ejecutar y usar kcachegrind para ver los resultados de xdebug
 >sudo kcachegrid
 se ejecuta el programa, ->open se abre el archivo /tmp/cachegrind.out-14691
se evalua los resultados x tiempo y % de uso, se distingue cual es el que mas demora en cargar

7. Ver en detalle los procesos que se ejecutan en el servidor
>sudo top
cpu
mem (RAM)
Swap(disco duro, cuando se sobre pasa la memoria RAM)
used (si empieza a aumentar se esta usando el HDD, para apache se reload y se libera la RAM)
>sudo iotop
  de forma similar
 >sudo iftop -i eth0
TX Lectura
RX Escritura

8. Habilitar devel
permite ver los query de las vistas del sitio web
http://www.misitioweb.com/admin/config/development/devel
display query log =1

Referencias:
http://www.xdebug.org/docs/profiler
http://pensandoenred.com/tag/php5-xdebug/

Puertos
------
:8080 varnish
.8090 nginx

/***********Instalacion y Configuracion ap y Boost**********/
Refs:
http://www.drupalmexico.com/optimizando-tu-sitio-drupal
http://www.howtoforge.com/how-to-speed-up-drupal-7.7-with-boost-and-nginx-debian-squeeze

/    (home)

>ab -n 1000 -c 20 http://www.misitioweb.com/ > /home/pruebas/home
n->numero de peticiones c->num concurrencias

Confg. Boots:

1. >sudo apt-get install apache2-utils
2. descargar http://drupal.org/project/boost
3. instalar: >a2enmod rewrite, a2enmod headers, a2enmod expires
                 >sudo service apache2 restart
4. permisos carpeta: >chmod 777 /var/www/miweb/cache
5. habilitar modulo boost en drupal, settings x defecto
6. copyt rules boost in .htaccess
    >sudo vim /var/www/miweb/.htaccess
    agrega en la linea:
     # RewriteBase /
       INSERT BOOST CODE HERE
     #Rewrite URLs of the form ‘x’ to the form ‘index.php?q=x’
7. reinicia apache >sudo service apache2 restart
8. cargar pagina, anonimo: www.misitioweb.com/
9. comprobar errores    http://www.sitioweb.com/admin/reports/status

Optimizar: calls funciones PHP: xhprof
--------------------------------------------------------------
http://drupal.org/node/946182


http://develcuy.com/en/howto-install-xhprof-ubuntu-howto-use-drupal-6x-7x

instalar: http://www.e-capy.com/instalar-y-configurar-xhprof-para-que-funcione-en-drupal/
funcionamiento: http://techportal.inviqa.com/2009/12/01/profiling-with-xhprof/



Cargar tablas BD en memoria cache
-----------------------------------------------------------------
/etc/mysql/my.cnf
//create
/etc/mysql/conf.d/local.cnf
[mysqld]
key_buffer_size = 200M
warm_cache.key_buffer_size = 200M
init_file = /etc/mysql/conf.d/cache.sql

//create
/etc/mysql/conf.d/cache.sql
CACHE INDEX upcdev.cache_menu, upcdev.menu_links, upcdev.menu_router, upcdev.menu_custom, upcdev.admin_menu IN warm_cache;

//reiniciar mysql
>sudo /etc/init.d/mysql restart

cargando en cache funciones php
function mi_funcion($menu, $mlid, $nid){
if ($menucache = cache_get('micache_hml__'.str_replace('-','_',$menu).'__'.$mlid.'_'.$nid_current, 'default')) {
    error_log('Reusing '.$menu.'-'.$mlid.'-'.$nid_current);
    $menu_links = unserialize($menucache->data);
    return $menu_links;
  }
//mi codigo....
[...]

  cache_set('micache_hml__'.str_replace('-','_',$menu).'__'.$mlid.'_'.$nid_current, serialize($output), 'default', CACHE_TEMPORARY);

return $output;

}