Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Otimização e Escalabilidade

3 272 vues

Publié le

Publié dans : Technologie
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici
  • accessibility Books Library allowing access to top content, including thousands of title from favorite author, plus the ability to read or download a huge selection of books for your pc or smartphone within minutes.........ACCESS WEBSITE Over for All Ebooks ..... (Unlimited) ......................................................................................................................... Download FULL PDF EBOOK here { http://bit.ly/2m6jJ5M } .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

Otimização e Escalabilidade

  1. 1. OTIMIZAÇÃO EESCALABILIDADE<br />
  2. 2. Para quem não me conhece<br />Graduando em ciência da computação pela UFES;<br />Trabalho com internet há 9 anos;<br />Gerente de Tecnologia do iMasters desde 2003;<br />Obtive o ZendCertifiedEngineer para PHP5 em 2008;<br />
  3. 3. Otimização é..<br />obter o máximo de resultados com a mesma quantidade de recursos.<br />
  4. 4. Escalabilidade é..<br />habilidade de manipular uma porção crescente de trabalho de forma uniforme, ou estar preparado para crescer.<br />
  5. 5. Demanda de processamento<br />Volume de dados<br />
  6. 6. Casos famosos<br />Twitter – instabilidade devido a falha na estratégia de escalabilidade<br />Digg – teve de mudar toda a arquitetura da aplicação para manter-se online<br />World ofWarcraft – durante o lançamento, foi sobrecarregado e ficou fora do ar<br />Youtube, LiveJournal, Facebook....<br />
  7. 7. Como otimizar e ser escalável?<br />
  8. 8. Não existe receita de bolo.<br />
  9. 9. Código-fonte<br />Dicas<br />Profiling<br />Infra-estrutura<br />Usando cache<br />opcode<br />memcache<br />Banco de dados<br />Otimização de consultas<br />Distribuindo banco de dados<br />Distribuindo tarefas<br />Arquiteturas escaláveis<br />Computação em nuvem<br />
  10. 10. Código-fonte<br />
  11. 11. Dicas<br />echoé mais rápido que print();<br />utilize aspas simples ao invés de aspas duplas quando possível;<br />evite métodos mágicos como __get, __set, __call e etc..<br />prefira require() ao require_once() quando possível;<br />utilize caminhos absolutos sempre que possível;<br />$array['foo'] é até 7x mais rápido do que que$array[foo];<br />evite o operador @ para ocultar erros;<br />...<br />
  12. 12. 1%<br />
  13. 13. Dicas<br />Evite funções pesadas nas condições dos loops<br />for($i=0; $i < count($obj->metodoLento()); $i++)<br />{<br /> // faça alguma coisa<br />}<br />
  14. 14. Dicas<br />Evite funções pesadas nas condições dos loops<br />$total = count($obj->metodoLento());<br />for($i=0; $i < $total; $i++)<br />{<br /> // faça alguma coisa<br />}<br />
  15. 15. Dicas<br />Lembre-se de executar exit() depois dos redirecionamentos <br />if($redirect)<br />{<br /> header("Location: index.php");<br />}<br />// algum código aqui<br />
  16. 16. Dicas<br />Lembre-se de executar exit() depois dos redirecionamentos <br />if($redirect)<br />{<br /> header("Location: index.php");<br />exit();<br />}<br />// algum código aqui<br />
  17. 17. Dicas<br />Evite SQLs dentro de loops<br />foreach($usuarios as $u)<br />{<br />mysql_query("<br /> INSERT INTO usuario (nome, email)<br /> VALUES('".$u->nome."','".$u->email."')<br /> ", $conn);<br />}<br />
  18. 18. Dicas<br />Evite SQLs dentro de loops <br />$sql = "INSERT INTO usuario (nome, email) VALUES";<br />$values = array()<br />foreach($usuarios as $u)<br />{<br /> $values[] = "('".$u->nome."','".$u->email."')";<br />}<br />mysql_query($sql.implode("," , $values), $conn);<br />
  19. 19. Dicas<br />Evite SQLs dentro de loops <br />INSERT INTO usuario (nome, email) VALUES<br /> ('Leo Hackin','leo@hackin.com'),<br /> ('Almir Mendes','almir@mendes.com'),<br /> ('Reinaldo Junior','reinaldo@junior.com')<br />
  20. 20. Dicas<br />Utilize páginas estáticas<br />Requisições a páginas estáticas não precisam carregar o engine PHP, economizando memória e diminuindo o tempo de resposta.<br />Preste atenção aos índices do banco de dados<br />A ausência de índices nas colunas que aparecem em cláusulas WHERE ou JOIN pode 'destruir' a performance da sua aplicação.<br />
  21. 21. Dicas<br />Utilize curto-circuito nas consultas SQL<br />
  22. 22. Profiling<br />É a investigação do comportamento do script, através dos dados recolhidos durante a sua execução, com o objetivo de determinar quais partes podem ser otimizadas melhorando a velocidade e reduzindo o consumo de memória<br />
  23. 23. Profiling<br />Encontrar os gargalos<br />Como analisar seu código?<br />XDebug<br />XHProf<br />
  24. 24. Profiling - XDebug<br />Instalação<br />$peclinstallxdebug<br />Configuração php.ini<br />zend_extension=/path/to/extensions/xdebug.so<br />xdebug.profiler_enable = 1<br />xdebug.profiler_output_dir = /var/log/xdebug/<br />xdebug.trace_format = 1<br />Ferramentas para analisar os dados<br />KCacheGrind (Linux)<br />WinCacheGrind (Windows)<br />
  25. 25.
  26. 26. Infra-estrutura<br />
  27. 27. Caches<br />Banco de dados<br />Computação em nuvem<br />
  28. 28. Opcodecache<br />PHP compila o script<br />O opcode é executado<br />HTML enviado ao navegador<br />
  29. 29. Opcodecache<br />CacheOpcode<br />PHP compila o script<br />O opcode é executado<br />HTML enviado ao navegador<br />
  30. 30. Opcodecache<br />Opções disponíveis<br />APC<br />eAccelerator<br />ZendOptimizer<br />ionCubeEncoder<br />...<br />
  31. 31. Cliente<br />Apache + MySQL<br />
  32. 32. Cliente<br />Apache<br />MySQL<br />
  33. 33. Cliente<br />?<br />Apache<br />Apache<br />Apache<br />MySQL<br />
  34. 34. Cliente<br />Apache<br />Apache<br />Apache<br />MySQL<br />Sessionserver<br />
  35. 35. Memcache<br />O que é?<br />Como funciona?<br />Como utilizar em sua aplicação?<br />
  36. 36. Memcache - Session<br />$host = “memcache.exemple.com”;<br />$port = 11211;<br />$session_path = "tcp://$host:$port";<br />ini_set('session.save_handler', 'memcache');<br />ini_set('session.save_path', $session_path);<br />
  37. 37. Memcache - Session<br />$sess_serv = array(<br />array('host' => 'memcache1.exemple.com',<br /> 'port' => 11211),<br />array('host' => 'memcache2.exemple.com',<br /> 'port' => 11211),<br />);<br />$path = array();<br />foreach($sess_serv as $s)<br /> $path[] = 'tcp://'.$s['host'].':'.$s['port']<br />ini_set('session.save_handler', 'memcache');<br />ini_set('session.save_path', implode(',', $path));<br />
  38. 38. Memcache - Dados<br />$memcache = new Memcache;<br />$memcache->connect('localhost', 11211);<br />$object = new stdClass;<br />$object->str_attr = 'test';<br />$object->int_attr = 123;<br />$memcache->set('key', $object, false, 10);<br />$result = $memcache->get('key');<br />
  39. 39. Memcache - SQL<br />functionquery_with_cache($sql, $timeout = 1800)<br />{<br /> global $memcache;<br /> $key = md5($sql);<br />if (($result = $memcache->get($key)) === false)<br /> {<br /> $result = query_and_fetch($sql);<br /> $memcache->set($key, $result , false, $timeout);<br /> }<br />return $result;<br />}<br />
  40. 40. Banco de dados<br />Master-slave<br />Um (e apenas um) master<br />Um ou mais slaves<br />Todas as escritas são enviadas ao master<br />Leituras são distribuídas entre todos os nós<br />Falhas<br />Único ponto de falha<br />Gargalo<br />
  41. 41. Banco de dados<br />Servidores<br />de Aplicação<br />Master<br />Slave<br />Slave<br />Slave<br />Escrita<br />Leitura<br />
  42. 42. Banco de dados<br />Master-master<br />Um ou mais masters<br />Escritas e leituras vão para todos os masters<br />Escritas são replicadas entre si<br />Falhas<br />Alta complexidade<br />Introduz altas latências de comunicação<br />
  43. 43. Banco de dados<br />Servidores <br />de Aplicação<br />Master<br />Master<br />Master<br />Escrita<br />Leitura<br />
  44. 44. Banco de dados<br />Particionamento vertical<br />Colocar as tabelas em servidores diferentes agrupadas por área funcional<br />Escalona seus dados por funcionalidade<br />Joins são realizados na aplicação<br />Falhas<br />Perde os relacionamentos reais do banco de dados<br />Escalabilidade limitada<br />
  45. 45. Banco de dados<br />Servidores <br />de Aplicação<br />Clients<br />Comments<br />Products<br />
  46. 46. Banco de dados<br />Particionamento horizontal<br />Separe os dados por chaves e coloque em servidores diferentes (sharding)<br />Escalona seus dados por chave<br />Joins são realizados na aplicação<br />Necessita de um “roteamento” das consultas na aplicação<br />Falha<br />Perde os relacionamentos reais do banco de dados<br />
  47. 47. Banco de dados<br />Servidores <br />de Aplicação<br />Clients (i – q)<br />Clients (r – z)<br />Clients (a – h)<br />
  48. 48. CloudHosting<br />O que é?<br />Flexibilidade<br />Baixo custo?<br />
  49. 49. CloudHosting<br />
  50. 50. CloudHosting<br />
  51. 51. ?<br />
  52. 52. Obrigado!<br />Andre Metzen<br />metzen@imasters.com.br<br />@metzen<br />

×