Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Oficina: Como escalar aplicações PHP

Oficina: Como escalar aplicações PHP

Palestra dada na Campus Party 2012 com participação especial do Alexandre Gaigalas.

Augusto Pascutti

March 13, 2012
Tweet

More Decks by Augusto Pascutti

Other Decks in Programming

Transcript

  1. Índices CREATE TABLE compras ( id INT AUTO_INCREMENT, data DATE

    NOT NULL, valor FLOAT NOT NULL, PRIMARY KEY (id) INDEX data_compra(data) ) Wednesday, February 8, 2012
  2. Índices SELECT * FROM compras WHERE data <= CURRENT_DATE() -

    INTERVAL 7 DAY Wednesday, February 8, 2012
  3. Índices SELECT * FROM compras WHERE data <= ‘2012-01-07’ -

    INTERVAL 7 DAY Wednesday, February 8, 2012
  4. ParBcionamento  VerBcal 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 ); Wednesday, February 8, 2012
  5. ParBcionamento  VerBcal 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), ... ); Wednesday, February 8, 2012
  6. ParBcionamento  VerBcal 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; Wednesday, February 8, 2012
  7. ParBcionamento  VerBcal 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; INT Wednesday, February 8, 2012
  8. ParBcionamento  VerBcal 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; Wednesday, February 8, 2012
  9. ParBcionamento  VerBcal 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; Wednesday, February 8, 2012
  10. ParBcionamento  VerBcal 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; =D Wednesday, February 8, 2012
  11. •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
  12. SESSION 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> Wednesday, February 8, 2012
  13. Gravação Leitura RewriteEngine On RewriteCond ${REQUEST_METHOD} ^(POST|PUT|DELETE)$ RewriteRule ^/(.*)$ escrita.test.org$1

    [P] RewriteCond ${REQUEST_METHOD} ^(GET|HEAD|OPTIONS)$ RewriteRule ^/(.*)$ leitura.test.org$1 [P] •mod_rewrite Wednesday, February 8, 2012
  14. Gravação Leitura RewriteEngine On RewriteCond ${REQUEST_METHOD} ^(POST|PUT|DELETE)$ RewriteRule ^/(.*)$ balancer://escrita$1

    [P] RewriteCond ${REQUEST_METHOD} ^(GET|HEAD|OPTIONS)$ RewriteRule ^/(.*)$ balancer://leitura$1 [P] •mod_rewrite Wednesday, February 8, 2012
  15. SESSION function read($id) { $sql = "SELECT data FROM session

    WHERE id = '{$id}'"; $data = array(); // query, fetchAll return $data; } Wednesday, February 8, 2012
  16. SESSION function write($id, $data) { $data = serialize($data); $sql =

    "INSERT INTO session (id, data) VALUES ('{$id}', '{$data}')"; // Insert return true; } Wednesday, February 8, 2012
  17. SESSION function destroy($id) { $sql = "DELETE FROM session WHERE

    id = '{$id}'"; // delete return $sql; } Wednesday, February 8, 2012