Como escalar aplicações PHP

4,050 views

Published on

Oficina de escalabilidade para aplicações web dada na Campus Party 5 (2012)

Published in: Technology
0 Comments
16 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,050
On SlideShare
0
From Embeds
0
Number of Embeds
59
Actions
Shares
0
Downloads
0
Comments
0
Likes
16
Embeds 0
No embeds

No notes for slide

Como escalar aplicações PHP

  1. 1. Escalar  aplicações  PHP Augusto PascuttiWednesday, February 8, 2012
  2. 2. @augustohpWednesday, February 8, 2012
  3. 3. HTTP  =  Stateless   (Share  Nothing)Wednesday, February 8, 2012
  4. 4. Escalar?Wednesday, February 8, 2012
  5. 5. !=  VelocidadeWednesday, February 8, 2012
  6. 6. ~=  quanBdadeWednesday, February 8, 2012
  7. 7. Escalabilidade  =  ArquiteturaWednesday, February 8, 2012
  8. 8. Nosso  ambienteWednesday, February 8, 2012
  9. 9. Wednesday, February 8, 2012
  10. 10. Level  1Wednesday, February 8, 2012
  11. 11. InternetWednesday, February 8, 2012
  12. 12. ÍndicesWednesday, February 8, 2012
  13. 13. Um  índice  muito  grande  é  INÚTIL. ÍndicesWednesday, February 8, 2012
  14. 14. CREATE TABLE compras ( id INT AUTO_INCREMENT, data DATE NOT NULL, valor FLOAT NOT NULL, PRIMARY KEY (id) INDEX data_compra(data) ) ÍndicesWednesday, February 8, 2012
  15. 15. SELECT * FROM compras WHERE TO_DAYS(data)-TO_DAYS(data) <= 7 ÍndicesWednesday, February 8, 2012
  16. 16. SELECT * FROM compras WHERE data <= CURRENT_DATE() - INTERVAL 7 DAY ÍndicesWednesday, February 8, 2012
  17. 17. SELECT * FROM compras WHERE data <= ‘2012-01-07’ - INTERVAL 7 DAY ÍndicesWednesday, February 8, 2012
  18. 18. ParBcionamento  VerBcalWednesday, February 8, 2012
  19. 19. CREATE TABLE usuarios ( id INT AUTO_INCREMENT, login VARCHAR(50) NOT NULL, nascimento DATE NOT NULL ) ENGINE=InnoDB PARTITION BY RANGE (id) ( PARTITION a VALUES LESS THAN (1000), PARTITION b VALUES LESS THAN (2000), PARTITION z VALUES LESS THAN MAXVALUE ); ParBcionamento  VerBcalWednesday, February 8, 2012
  20. 20. CREATE TABLE usuarios ( id INT AUTO_INCREMENT, login VARCHAR(50) NOT NULL, nascimento DATE NOT NULL, pais INT NOT NULL ) ENGINE=InnoDB PARTITION BY LIST (pais) ( PARTITION america VALUES IN (1,2,3), PARTITION europa VALUES IN (4,5,6), ... ); ParBcionamento  VerBcalWednesday, February 8, 2012
  21. 21. CREATE TABLE usuarios ( id INT AUTO_INCREMENT, login VARCHAR(50) NOT NULL, nascimento DATE NOT NULL, grupo INT NOT NULL ) ENGINE=InnoDB PARTITION BY HASH (grupo) PARTITIONS 4; ParBcionamento  VerBcalWednesday, February 8, 2012
  22. 22. CREATE TABLE usuarios ( id INT AUTO_INCREMENT, login VARCHAR(50) NOT NULL, nascimento DATE NOT NULL, grupo INT NOT NULL ) ENGINE=InnoDB PARTITION BY HASH (grupo) INT PARTITIONS 4; ParBcionamento  VerBcalWednesday, February 8, 2012
  23. 23. CREATE TABLE usuarios ( id INT AUTO_INCREMENT, login VARCHAR(50) NOT NULL, nascimento DATE NOT NULL, grupo INT NOT NULL ) ENGINE=InnoDB PARTITION BY HASH (MONTH(nascimento)) PARTITIONS 12; ParBcionamento  VerBcalWednesday, February 8, 2012
  24. 24. CREATE TABLE usuarios ( id INT AUTO_INCREMENT, login VARCHAR(50) NOT NULL, nascimento DATE NOT NULL, grupo INT NOT NULL ) ENGINE=InnoDB PARTITION BY KEY (login) PARTITIONS 4; ParBcionamento  VerBcalWednesday, February 8, 2012
  25. 25. CREATE TABLE usuarios ( id INT AUTO_INCREMENT, login VARCHAR(50) NOT NULL, nascimento DATE NOT NULL, grupo INT NOT NULL ) ENGINE=InnoDB PARTITION BY KEY (login) =D PARTITIONS 4; ParBcionamento  VerBcalWednesday, February 8, 2012
  26. 26. Level  2Wednesday, February 8, 2012
  27. 27. Gravação Leitura ReplicaçãoWednesday, February 8, 2012
  28. 28. Level  3Wednesday, February 8, 2012
  29. 29. Gravação Leitura ReplicaçãoWednesday, February 8, 2012
  30. 30. Gravação Leitura Replicação MySql  ProxyWednesday, February 8, 2012
  31. 31. Wednesday, February 8, 2012
  32. 32. Level  1Wednesday, February 8, 2012
  33. 33. InternetWednesday, February 8, 2012
  34. 34. MulB  Processing  ModulesWednesday, February 8, 2012
  35. 35. InternetWednesday, February 8, 2012
  36. 36. Level  2Wednesday, February 8, 2012
  37. 37. Wednesday, February 8, 2012
  38. 38. •mod_proxy •mod_proxy_hWp •mod_proxy_balancerWednesday, February 8, 2012
  39. 39. •mod_proxy •mod_proxy_hWp •mod_proxy_balancer ProxyPass / balancer://vila-chaves <Proxy balancer://vila-chaves> BalancerMember http://chaves.test.org BalancerMember http://kiko.test.org BalancerMember http://nhonho.test.org </Proxy>Wednesday, February 8, 2012
  40. 40. SESSIONWednesday, February 8, 2012
  41. 41. ProxyPass / balancer://vila-chaves stickysession=PHPSESSIONID <Proxy balancer://vila-chaves> BalancerMember http://chaves.test.org BalancerMember http://kiko.test.org BalancerMember http://nhonho.test.org </Proxy> SESSIONWednesday, February 8, 2012
  42. 42. Level  3Wednesday, February 8, 2012
  43. 43. Gravação LeituraWednesday, February 8, 2012
  44. 44. •mod_rewrite Gravação LeituraWednesday, February 8, 2012
  45. 45. •mod_rewrite RewriteEngine On RewriteCond ${REQUEST_METHOD} ^(POST|PUT|DELETE)$ RewriteRule ^/(.*)$ escrita.test.org$1 [P] Gravação Leitura RewriteCond ${REQUEST_METHOD} ^(GET|HEAD|OPTIONS)$ RewriteRule ^/(.*)$ leitura.test.org$1 [P]Wednesday, February 8, 2012
  46. 46. •mod_rewrite RewriteEngine On RewriteCond ${REQUEST_METHOD} ^(POST|PUT|DELETE)$ RewriteRule ^/(.*)$ balancer://escrita$1 [P] Gravação Leitura RewriteCond ${REQUEST_METHOD} ^(GET|HEAD|OPTIONS)$ RewriteRule ^/(.*)$ balancer://leitura$1 [P]Wednesday, February 8, 2012
  47. 47. Wednesday, February 8, 2012
  48. 48. Banco  de  DadosWednesday, February 8, 2012
  49. 49. Front  ControllerWednesday, February 8, 2012
  50. 50. SESSIONWednesday, February 8, 2012
  51. 51. CREATE TABLE `session` ( `id` char(32), `data` text, PRIMARY KEY (`id`) ); SESSIONWednesday, February 8, 2012
  52. 52. session_set_save_handler ("open","close","read", "write","destroy","gc"); SESSIONWednesday, February 8, 2012
  53. 53. function open($path,$name) { return true; } function close() { return true; } SESSIONWednesday, February 8, 2012
  54. 54. function read($id) { $sql = "SELECT data FROM session WHERE id = {$id}"; $data = array(); // query, fetchAll return $data; } SESSIONWednesday, February 8, 2012
  55. 55. function write($id, $data) { $data = serialize($data); $sql = "INSERT INTO session (id, data) VALUES ({$id}, {$data})"; // Insert return true; } SESSIONWednesday, February 8, 2012
  56. 56. function destroy($id) { $sql = "DELETE FROM session WHERE id = {$id}"; // delete return $sql; } SESSIONWednesday, February 8, 2012
  57. 57. function gc($maxlifetime) { // =D return true; } SESSIONWednesday, February 8, 2012
  58. 58. @alganetWednesday, February 8, 2012
  59. 59. slideshare.net/augustopascuttiWednesday, February 8, 2012

×