Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Symfony 1, mi viejo amigo

4,745 views

Published on

Algunas ideas y experiencias tratando de optimizar Symfony 1.4 Doctrine 1.2 para una web de alto rendimiento.

Published in: Technology, Business
  • Be the first to comment

Symfony 1, mi viejo amigo

  1. 1.
  2. 2.
  3. 3. Miviejo amigo<br />
  4. 4. Un pocosobre mi<br />Estoytrabajando con webs desde 2001<br />Me encantainvestigar y meterme en problemas<br />era solo un poco!<br />
  5. 5. 青玉男<br />ao tama o<br />
  6. 6. ao<br />
  7. 7. Y porquéhablar de 1.4?<br />
  8. 8. Preguntas<br />Las hagoyo!<br />
  9. 9. Quepodemosoptimizar?<br />
  10. 10. Carga de proceso<br />Tiempoquepasa el servidorprocesando la web<br />
  11. 11. Proveedor de Internet<br />Desarrolladores Backend<br />Desarrolladores Frontend<br />
  12. 12. Tiempo de Espera<br />
  13. 13. Miexperiencia<br />
  14. 14. La optimizaciónduele<br />Vale la pena el esfuerzo?<br />
  15. 15. Quepodemosmejorar<br />
  16. 16. Hechos<br />
  17. 17. + Hechos<br />
  18. 18. Herramientas<br />
  19. 19. Debug Tool Bar<br />Todos la conocemos ya!<br />
  20. 20. sfTimerManager<br />$timer = sfTimerManager::getTimer("test");<br />.<br />.<br />.<br />var_export( $timer->addTime() );<br />
  21. 21. sfTimerManager<br />
  22. 22. sfTimer<br />$timer = new sfTimer ("test");<br />$timer->startTimer();<br />.<br />.<br />.<br />var_export( $timer->addTime() );<br />
  23. 23. Doctrine<br />Quepodemosoptimizar<br />
  24. 24. Optimizando Doctrine<br />
  25. 25. Cantidad de Consultas<br />Optimizando Doctrine<br />
  26. 26. Tiempo de Consulta<br />Optimizando Doctrine<br />Tiempoquenos cuesta buscarinformación en la DB<br />
  27. 27. Tiempo de Hidratación<br />Optimizando Doctrine<br />Quees?<br />http://www.doctrine-project.org/documentation/manual/1_2/en/data-hydrators<br />constHYDRATE_RECORD = 2;<br />constHYDRATE_ARRAY = 3;<br />constHYDRATE_NONE = 4;<br />constHYDRATE_SCALAR = 5;<br />constHYDRATE_SINGLE_SCALAR = 6;<br />constHYDRATE_ON_DEMAND = 7;<br />constHYDRATE_ARRAY_HIERARCHY = 8;<br />constHYDRATE_RECORD_HIERARCHY = 9;<br />
  28. 28. Tiempo de Hidratación<br />Optimizando Doctrine<br />Quées lo mínimoqueestamosbuscando?<br />
  29. 29. Tiempo de Hidratación<br />Optimizando Doctrine<br />$clist = Doctrine::getTable("Country")<br />->createQuery()<br />->select({fields})<br />->execute({strategy});<br />
  30. 30. Tiempo de Hidratación<br />Optimizando Doctrine<br />$conn = Doctrine_Manager::connection();<br />$data = $conn->execute("select * from countries")->fetchAll();<br />
  31. 31. Tiempo de Hidratación<br />Optimizando Doctrine<br />Para que<br />quiero el ORM?<br />$conn= Doctrine_Manager::connection();<br />Para manejarlasconexiones!<br />
  32. 32. Doctrine?<br />Unainteresanteparadoja!<br />
  33. 33. Tiempo de Hidratación<br />Optimizando Doctrine<br />Ejemplo!<br />
  34. 34. Tiempo de Hidratación<br />Optimizando Doctrine<br />UserTable::getInstance()<br /> ->createQuery()<br /> ->select ("id, name, surname, age")<br /> ->where("is_deleted = ?", false)<br /> ->andWhere("is_closed = ? ", false)<br /> ->andWhere(”age > ? ", 50 )<br />->execute( array(), <br />Doctrine_Core::HYDRATE_ARRAY);<br />UserTable::getInstance()<br /> ->createQuery()<br /> ->select ("id, name, surname, age")<br /> ->where("is_deleted = ?", false)<br /> ->andWhere("is_closed = ? ", false)<br /> ->andWhere(”age > ? ", 50 )<br />->execute( );<br />Estrategia<br />
  35. 35. Tiempo de Hidratación<br />Optimizando Doctrine<br />Compatibilidad entre estrategias en la vista<br /><td> <?phpecho$user->get("name") ?></td><br /><td> <?phpecho$user->name ?></td><br /><?php$user= $user->getRawValue() ?><br /><td> <?phpecho$user["name"] ?></td><br />
  36. 36. T. Conversión de Consulta<br />Optimizando Doctrine<br />$q = Doctrine::getTable("Country")->createQuery();<br />$q->getSqlQuery().<br />0.006 seg<br />Gallery1..n GalleryImagesn..1 Image<br />$q= Doctrine::getTable("Gallery")->createQuery("g")->leftJoin("g.images");<br />$q->getSqlQuery();<br />0.1 seg<br />
  37. 37. Conteo de Registros<br />Optimizando Doctrine<br />$clist = Doctrine::getTable("Country”)<br />->findAll()->count();<br />->createQuery()->count();<br />->createQuery()->select("count(id)")->execute( array (), Doctrine::HYDRATE_NONE );<br />$conn->execute("select count(id) as count from countries")->fetchAll();<br />0.2 seg<br />0.0056 seg<br />0.01 seg<br />0.00087 seg<br />
  38. 38. PDO<br />http://es2.php.net/manual/en/book.pdo.php<br />
  39. 39. Select, Joins e Indices<br />Optimizando Doctrine<br />$articles = Doctrine::getTable("Article")->createQuery("a")->leftJoin("a.pages p")<br />->limit(100)->execute();<br />->limit(1000)->execute();<br />->limit(100)->execute( array(), Doctrine::HYDRATE_ARRAY );<br />->limit(1000)->execute( array(), Doctrine::HYDRATE_ARRAY );<br />2.93 seg<br />30.80 seg<br />0.20 seg<br />1.37 seg<br />
  40. 40. Select, Joins e Indices<br />Optimizando Doctrine<br />SELECT c.id, c.name , c.resume, c.disclaimer, c.product , c.description, <br />UNIX_TIMESTAMP(c.valid_start_at) as valid_start, UNIX_TIMESTAMP(c.valid_end_at) as valid_end, UNIX_TIMESTAMP(c.promotion_start_at) as promotion_start, UNIX_TIMESTAMP(c.promotion_end_at) as promotion_end, UNIX_TIMESTAMP(c.publish_at) as publish, <br />c.tracking_click, c.tracking_save_count, c.visibility_status_id, c.print_coupon, c.mobile_coupon, c.online_coupon, c.company_id, cp.comercial_name as company_name, c.redemption_price as redemption_price, <br />CONCAT_WS(',', GROUP_CONCAT(DISTINCT ca.attributes_id SEPARATOR ",") ) as attributes, <br />CONCAT_WS(',', GROUP_CONCAT(DISTINCT ca.root_id SEPARATOR ",") ) as roots, <br />CONCAT_WS(',', GROUP_CONCAT(DISTINCT ca.level SEPARATOR ",") ) as levels, <br />CONCAT_WS(',', GROUP_CONCAT(DISTINCT cs.store_id SEPARATOR ",") ) as stores, <br />CONCAT_WS(',', GROUP_CONCAT(DISTINCT uc.user_id SEPARATOR ",") ) as users, <br />CONCAT_WS(',', GROUP_CONCAT(DISTINCT cs.state_id SEPARATOR ","), IF(online_coupon = 1, 0, null) ) as states, <br />CONCAT_WS(',', IF( print_coupon = 1, 1,null), IF( mobile_coupon = 1, 2,null), IF( online_coupon = 1, 3,null) ) as types, <br />CONCAT_WS(',', GROUP_CONCAT(DISTINCT cs.postal_code SEPARATOR ",") ) as postal_codes_ids, <br />CONCAT_WS(' ', GROUP_CONCAT(DISTINCT cs.city_name SEPARATOR " ") ) as cities, <br />CONCAT_WS(' ', GROUP_CONCAT(DISTINCT s.road_name SEPARATOR " ") ) as roads, <br />CONCAT_WS(' ', GROUP_CONCAT(DISTINCT s.comercial_name SEPARATOR " ") ) as names, <br />CONCAT_WS(' ', GROUP_CONCAT(DISTINCT s.postal_code SEPARATOR " ") ) as postal_codes, <br />CONCAT_WS(' ', GROUP_CONCAT(DISTINCT sa.name SEPARATOR " ") ) as state_names <br />FROM ( ( ( (coupons c LEFT JOIN coupon_attributes ca ON c.id = ca.coupons_id ) LEFT JOIN coupon_stores cs ON c.id = cs.coupon_id) LEFT JOIN sf_guard_user_coupons uc ON c.id = uc.coupon_id ) LEFT JOIN stores s ON cs.store_id = s.id ) LEFT JOIN states sa ON cs.state_id = sa.id LEFT JOIN companies cp ON cp.id=c.company_id <br />WHERE ( c.administrative_status_id = 1 AND c.publish_at < NOW() AND DATE(c.valid_end_at) + INTERVAL 1439 HOUR_MINUTE > NOW() ) <br />GROUP BY c.id<br />
  41. 41. Select, Joins e Indices<br />Optimizando Doctrine<br />✔<br />
  42. 42.
  43. 43. Vistas<br />Quepodemosoptimizar<br />
  44. 44. Optimizando Vistas<br />
  45. 45. Inclusión de Partials<br />Optimizando Vistas<br />
  46. 46. Listados y consultasanidadas<br />Optimizando Vistas<br /><?phpforeach($results as $plan): ?><br /> <li><br /> <?php echo $plan->get(“title”) ?> <br /> (<?php echo $plan->countAssistants()?> )<br /></li><br /><?phpendforeach; ?><br />Consultasanidadas<br />
  47. 47. La Cache<br />Guardemos en Cache parasalvaralgunos (muchos) milisegundos<br />
  48. 48. La Cache <br />
  49. 49. Cómofuncionan<br />La Cache<br />
  50. 50. Cómofuncionan<br />La Cache<br />la cache de de vistas<br />factories.yml<br />view_cache_manager:<br />class: sfViewCacheManager<br /> param:<br />cache_key_use_vary_headers: true<br />cache_key_use_host_name: true<br />view_cache:<br />class: sfFileCache<br /> param:<br />automatic_cleaning_factor: 0<br />cache_dir: %SF_TEMPLATE_CACHE_DIR%<br /> lifetime: 86400<br /> prefix: %SF_APP_DIR%/template<br />
  51. 51. Cómofuncionan<br />La Cache<br />la cache de de Doctrine<br />$manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver);<br />$conn->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver);<br />$q = Doctrine_Query::create() ->useQueryCache(new Doctrine_Cache_Apc()); <br />$manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE, $cacheDriver);<br />$conn->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE, $cacheDriver);<br />$manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE_LIFESPAN, 3600);<br />->useResultCache(true);<br />
  52. 52. Cómomodificarla<br />La Cache<br />la cache de de vistas<br />
  53. 53. Cómomodificarla<br />La Cache<br />la cache de de vistas<br />class sfViewCacheManager<br />public function setPageCache($uri)<br />public function getPageCache($uri)<br />
  54. 54. Cómomodificarla<br />La Cache<br />la cache de de vistas<br />class xyzCache extendssfCache<br />abstract public function get ($key, $default = null);<br />abstract public function has ($key);<br />abstract public function set ($key, $data, $lifetime = null);<br />abstract public function remove ($key);<br />abstract public function removePattern($pattern);<br />abstract public function clean ($mode = self::ALL);<br />
  55. 55. Drivers<br />La Cache<br />
  56. 56. OptimizandoSymfony<br />Podemoshaceralgo?<br />
  57. 57. No mucho!<br />
  58. 58. Quepodemoshacer?<br />OptimizandoSymfony<br />Desabilitar TODO lo que no se USE<br />Helpers<br />Logs<br />Routing Cache<br />Plugins que no usen100%<br />
  59. 59. Una idea!<br />
  60. 60. Front Controller<br />OptimizandoSymfony<br />require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');<br />$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);<br />sfContext::createInstance($configuration)->dispatch();<br />
  61. 61. Front Controller<br />OptimizandoSymfony<br />require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');<br />$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);<br />$manager = new sfDatabaseManager($configuration);<br />$data = Doctrine::getTable(“Article”)->createQuery()->etc();<br />$view = CMSProcess::ProcessData( $data );<br />echo $view;<br />
  62. 62. Gracias!<br />
  63. 63. Preguntas<br />Ahora si las hacen Uds!<br />
  64. 64. Miviejo amigo<br />josetonyp@latizana.com<br />@josetonyp<br />aotamao@latizana.com<br />

×