Upload
mysql-brasil
View
238
Download
0
Tags:
Embed Size (px)
Citation preview
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 1
Airton Lastori [email protected]
jun-2015
Desenvolvendo Serviços Escaláveis e de Alta Performance com MySQL e Java
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 3
Alta Performance Por que há demanda?
Suporte à “Big Data” e IoT
Velocidade de escrita
Escalabilidade horizontal
Disponível 24x7
Facilidade de uso
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 4
MySQL Central @ Oracle Open World 2014 Alguns cases apresentados...
[slides] oracle.com/openworld/mysql
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 5 Fonte: http://db-engines.com/en/ranking_trend (junho/15)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 6
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 7
Resposta tecnológica: NoSQL
Fonte: 451 Group, 2012
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 8
Requisitos NoSQL O que a solução deve cumprir?
Alta Performance alto throughput leitura/escrita
Escalabilidade massiva auto-sharding
Facilidade de uso acesso simples (APIs)
manutenção simples
modelo de dados flexível, fácil de
evoluir
Alta Disponibilidade tolerância a falhas
Performance
Escalabilidade
Facilidade de Uso
Disponibilidade ~24x7
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 9
Scale Out
• Adicionar mais servidores para
aumentar performance
• MySQL adota esta abordagem
em sistemas altamente
escaláveis em hardware
commodity (Intel / AMD)
Scale Up
• Trocar por hardware mais
poderoso, adicionar memória,
CPU
• Outras soluções normalmente
usam hardware proprietário
(SMP)
Escalabilidade: horizontal vs vertical
É possível combinar as duas abordagens
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 10
Escalabilidade vertical com MySQL
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 11
2008
até 4 CPU
MySQL 5.0
MySQL AB
até 16 CPU
MySQL 5.1
Sun
até 32 CPU
MySQL 5.5
Oracle
até 48 CPU
MySQL 5.6
Evolução da escalabilidade do MySQL
2009 2010 2013
Use InnoDB para usufruir melhor de hardwares modernos.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 12
MySQL 5.5.28
MySQL 5.6.7
MySQL 5.6 SysBench Benchmarks
234% Ganho de Performance
0
2,000
4,000
6,000
8,000
10,000
12,000
14,000
16,000
18,000
32 64 128 256 512
Tra
nsacti
on
s p
er
Seco
nd
Connections
MySQL 5.6 vs. 5.5 - Read Only (Linux)
Oracle Linux 6
Intel(R) Xeon(R) E7540 x86_64
MySQL leveraging:
- 48 of 96 available CPU threads
- 2 GHz, 512GB RAM
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 13
MySQL 5.5.28
MySQL 5.6.7
MySQL 5.6 SysBench Benchmarks
151% Ganho Performance
0
2,000
4,000
6,000
8,000
10,000
12,000
32 64 128 256 512
Tra
nsacti
on
s p
er
Seco
nd
Connections
MySQL 5.6 vs. 5.5 - Read Write (Linux)
Oracle Linux 6
Intel(R) Xeon(R) E7540 x86_64
MySQL leveraging:
- 48 of 96 available CPU threads
- 2 GHz, 512GB RAM
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 14
60x Melhor Escalabilidade comThread Pool
MySQL 5.6.11
Oracle Linux 6.3, Unbreakable Kernel 2.6.32
4 sockets, 24 cores, 48 Threads
Intel(R) Xeon(R) E7540 2GHz CPUs
512GB DDR3 RAM
Thread Pool habilitado/desabilitado
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 15
18x Melhor Escalabilidade com Thread Pool
Thread Pool habilitado/desabilitado
MySQL 5.6.11
Oracle Linux 6.3, Unbreakable Kernel 2.6.32
4 sockets, 24 cores, 48 Threads
Intel(R) Xeon(R) E7540 2GHz CPUs
512GB DDR3 RAM
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 16
0
100,000
200,000
300,000
400,000
500,000
600,000
700,000
8 16 32 64 128 256 512 1,024
Qu
eri
es p
er
Seco
nd
Connections
MySQL 5.7: Sysbench Read Only (Point Select)
MySQL 5.7
MySQL 5.6
MySQL 5.5
MySQL 5.7: Sysbench: Read Only
1
Intel(R) Xeon(R) CPU E7-4860 x86_64
4 sockets x 10 cores-HT (80 CPU threads)
2.3 GHz, 512 GB RAM
Oracle Linux 6.5
2x Faster than MySQL 5.6
3x Faster than MySQL 5.5 645,000 QPS
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 17
MySQL 5.7: Connections per Second
1
1.7x Faster than MySQL 5.6 2.5x Faster than MySQL 5.5
67,000 Connections/Sec
0
10,000
20,000
30,000
40,000
50,000
60,000
70,000
80,000
MySQL 5.5 MySQL 5.6 MySQL 5.7
Co
nn
ecti
on
s/S
ec
on
d
Connections Per Second
MySQL 5.5
MySQL 5.6
MySQL 5.7
Intel(R) Xeon(R) CPU E7-4860 x86_64
4 sockets x 10 cores-HT (80 CPU threads)
2.3 GHz, 512 GB RAM
Oracle Linux 6.5
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 18
Atualize!
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 19
No Windows: MySQL Installer Next, Next... Finish!
dev.mysql.com/downloads/windows/installer
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 20
No Linux: repositórios YUM e APT para MySQL
Suporta as distribuições Enterprise Linux
– RedHat Enterprise/Oracle Linux
– Fedora
– Debian/Ubuntu
Inclui os pacotes mais atuais
– MySQL Database
– MySQL Workbench
– MySQL Connectors
– MySQL Utilities
Maneira simples e conveniente de instalar e atualizar produtos MySQL
Mais de 50% dos downloads para
Fedora/RedHat já são feitos do repositório
www.alastori.com.br/2014/05/tutorial-de-
instalacao-do-mysql-56-e.html
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 21
…ou manualmente via binários pré-compilados
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 22
Escalabilidade horizontal com
MySQL?
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 23
Escalabilidade horizontal
Réplicas de Leitura
Serviços Especializados
Data Sharding
3 Abordagens para
escalar o MySQL
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 24
Escalabilidade horizontal
• método mais simples e mais comum
• indicado para aplicações de LEITURA intensiva
• problemas com cache duplicado em aplicações com datasets grandes
Réplicas de Leitura
• dividir a carga em múltiplos nós, com responsabilidades distintas
• os nós podem ter redundância via replicação para alta-disponibilidade
• normalmente não é transparente para a aplicação e também recorre ao scale up para cada database funcional, o que impõe limites
Serviços Especializados
• método de maior sucesso para escalar aplicações MySQL de grande porte hoje
• dados compartilhados em tabelas/caches globais, SOA
• difícil de adaptar aplicações legadas
Data Sharding
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 25
Aplicação
Replicação MySQL: como escalar 1/2
Master Slave
• Divisão de leituras e escritas (R/W Split)
• Modelo assíncrono (padrão)
• Modelo semi-síncrono (a partir da versão 5.5)
Escritas & Leituras Leituras
Exemplo clássico:
divida carga OLTP
e OLAP
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 26
Replicação MySQL: como escalar 2/2
Leituras Leituras
• Escreva para 1 Master
• Leia de vários Slaves, adicione mais quando necessário
• Perfeito para aplicações de leitura intensiva
Aplicação
Replicação MySQL
Load Balancer
Master Slave Slave
Escritas & Leituras
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 27
Saiba mais... Tutorial “Replicação MySQL em 5 minutos”
[blog post] http://www.alastori.com.br/2015/02/
tutorial-replicacao-mysql-em-5-
minutos.html
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 28
Failover
jdbc:mysql://[primary host][:port],[secondary host
1][:port][,[secondary host 2][:port]]...[/[database]]»
[?propertyName1=propertyValue1[&propertyName2=propertyValue2]...]
Load Balancing
jdbc:mysql:loadbalance://[host1][:port],[host2][:port][,[host3][:por
t]]...[/[database]] »
[?propertyName1=propertyValue1[&propertyName2=propertyValue2]...]
Em Java, use os recursos do Connector/J
http://dev.mysql.com/doc/connector-j/en/connector-j-multi-host-connections.html
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 29
Escalabilidade horizontal
• método mais simples e mais comum
• indicado para aplicações de LEITURA intensiva
• problemas com cache duplicado em aplicações com datasets grandes
Réplicas de Leitura
• dividir a carga em múltiplos nós, com responsabilidades distintas
• os nós podem ter redundância via replicação para alta-disponibilidade
• normalmente não é transparente para a aplicação e também recorre ao scale up para cada database funcional, o que impõe limites
Serviços Especializados
• método de maior sucesso para escalar aplicações MySQL de grande porte hoje
• dados compartilhados em tabelas/caches globais, SOA
• difícil de adaptar aplicações legadas
Data Sharding
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 30
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 31
Escalabilidade horizontal
• método mais simples e mais comum
• indicado para aplicações de LEITURA intensiva
• problemas com cache duplicado em aplicações com datasets grandes
Réplicas de Leitura
• dividir a carga em múltiplos nós, com responsabilidades distintas
• os nós podem ter redundância via replicação para alta-disponibilidade
• normalmente não é transparente para a aplicação e também recorre ao scale up para cada database funcional, o que impõe limites
Serviços Especializados
• método de maior sucesso para escalar aplicações MySQL de grande porte hoje
• dados compartilhados em tabelas/caches globais, SOA
• difícil de adaptar aplicações legadas
Data Sharding
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 32
Data Node 1
Data Node 2
Data Node 3
Data Node 4
Table T1
P2
P3
P4
P1
Escalabilidade horizontal: Data Sharding
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 33
Data Node 1
Data Node 2
F1
Data Node 3
Data Node 4
Table T1
P2
P3
P4
P1
Escalabilidade horizontal: Data Sharding
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 34
Data Node 1
Data Node 2
F1
F1
Data Node 3
Data Node 4
Table T1
P2
P3
P4
P1
Escalabilidade horizontal: Data Sharding
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 35
Data Node 1
Data Node 2
F1
F3 F1
Data Node 3
Data Node 4
Table T1
P2
P3
P4
P1
Escalabilidade horizontal: Data Sharding
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 36
Data Node 1
Data Node 2
F1 F3
F3 F1
Data Node 3
Data Node 4
Table T1
P2
P3
P4
P1
Escalabilidade horizontal: Data Sharding
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 37
Data Node 1
Data Node 2
F1 F3
F3 F1
Data Node 3
Data Node 4
F2
Table T1
P2
P3
P4
P1
Escalabilidade horizontal: Data Sharding
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 38
Data Node 1
Data Node 2
F1 F3
F3 F1
Data Node 3
Data Node 4
F2
F2
Table T1
P2
P3
P4
P1
Escalabilidade horizontal: Data Sharding
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 39
Data Node 1
Data Node 2
F1 F3
F3 F1
Data Node 3
Data Node 4
F2
F4 F2
Table T1
P2
P3
P4
P1
Escalabilidade horizontal: Data Sharding
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 40
Data Node 1
Data Node 2
F1 F3
F3 F1
Data Node 3
Data Node 4
F2 F4
F4 F2
Table T1
P2
P3
P4
P1
Escalabilidade horizontal: Data Sharding
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 41
Data Node 1
Data Node 2
F3
F1
Data Node 3
Data Node 4
F2 F4
F4 F2
Group 1
Table T1
P2
P3
P4
P1
F1
F3
Escalabilidade horizontal: Data Sharding
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 42
Data Node 1
Data Node 2
F1 F3
F3 F1
Data Node 3
Data Node 4
F2 F4
F4 F2
Group 2
Table T1
P2
P3
P4
P1
Escalabilidade horizontal: Data Sharding
Group 1
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 43
Data Node 1
Data Node 2
F1 F3
F3 F1
Data Node 3
Data Node 4
F2 F4
F4 F2
Table T1
P2
P3
P4
P1
Escalabilidade horizontal: Data Sharding
Group 2
Group 1
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 44
Data Node 1
Data Node 2
F1 F3
F3 F1
Data Node 3
Data Node 4
F2 F4
F4 F2
Table T1
P2
P3
P4
P1
Escalabilidade horizontal: Data Sharding
Group 2
Group 1
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 45
Sharding com MySQL?
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 46
Sharding com MySQL
• construindo componontes com ferramentas de DevOps
• não subestime a complexidade Na unha
• MySQL Fabric
• Google Youtube Vitess, Twitter Gizzard, Tumblr Jetpants, etc
• não é totalmente transparente para aplicação Frameworks
• transparente para aplicação, facilidade na administração
• implementado como um Storage Engine no MySQL (NDB)
MySQL Cluster
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 47
HA group
MySQL Fabric 1.5 (MySQL Utilities)
Alta disponibilidade:
– Monitoramento do Server com failover
automático e transparente para aplicação
Sem Proxy, sem latência extra e SPoF
Alta-disponibilidade + escalabilidade de escrita com sharding
Connector
Application
SQL
Read-slaves Read-slaves
HA group
MySQL Fabric
• Escalabilidade de escrita com sharding: – Aplicação define a shard key (Range ou Hash)
– Ferramentas para re-sharding
– Tabelas globais & global updates
• Conectores devem ser “Fabric-aware”: – Java, Python, PHP
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 48
Versão inicial, foco na simplicidade e robustez
– Alta-disponibilidade OK, escalabilidade de escrita em andamento
Sharding não é completamente transparente para aplicação
– Necessário fornecer a sharding key
Colunas Auto-increment não podem ser usadas como sharding key
Joins envolvendo múltiplos shards não são suportados
MySQL Connector (driver) deve suportar Fabric
– atualmente disponível para Java, Python e PHP
O nó Fabric por si só não é tolerante a falhas
– O connector tem seu cache local e continua operando quando o processo Fabric
não está disponível
Limitações da versão atual
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 49
Tutorial disponível no white paper
Whitepaper:
MySQL Fabric
September 2014
mysql.com/why-mysql/white-papers
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 50
NewSQL
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 51
Requisitos NewSQL Relacional + NoSQL
Combine as duas
abordagens! Performance
Escalabilidade
Facilidade de Uso
Disponibilidade ~24x7
SQL/Joins
Transações ACID
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 52
MySQL Cluster
• Arquitetura shared-nothing in-memory parallel
• Modelo relacional ACID, SQL + APIs NoSQL
In-Memory ACID Database
• 99.999% de disponibilidade
• Self-healing, failover abaixo de 1 segundo Alta Disponibilidade
• Performance em tempo real para altas cargas
• Latência baixa e preditiva Alta Performance
• Elasticidade, crescimento incremental
• Escalabilidade linear, distribuition aware Escalabilidade
• Open Source (GPL), hardware commodity
• Suporte comercial da Oracle opcional Open Source
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 53
Alguns usuários MySQL Cluster
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 54
Performance do MySQL Cluster
8 Servidores Intel Commodity
– 2 x 6-core processors 2.93GHz
– x5670 processors (24 threads)
– 48GB RAM
Rede Infiniband
flexAsynch benchmark (NDB API)
0
200
400
600
800
1,000
1,200
2 4 8
Millio
ns
Number of Data Nodes
SELECT Queries per Minute
0
50
100
150
4 8
Millio
ns
Number of Data Nodes
UPDATE Queries per Minute
Performance a
Escalabilidade
Facilidade de Uso
Disponibilidade ~24x7
SQL/Joins
Transações ACID
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 55
MySQL Cluster 7.2: 1.2 Billion UPDATEs por Minuto
NoSQL C++ API, flexaSynch benchmark
30 x Intel E5-2600 Intel Servers, 2 socket, 64GB
ACID Transactions, with Synchronous Replication
http://www.mysql.com/why-mysql/white-papers/mysql-cluster-benchmarks-1-billion-writes-per-minute/
0
5
10
15
20
25
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
Mil
lio
ns o
f U
PD
AT
Es p
er
Seco
nd
MySQL Cluster Data Nodes
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 56
MySQL Cluster Data Nodes
Data Layer
Clients
Management
Arquitetura MySQL Cluster Performance a
Escalabilidade
Facilidade de Uso ?
Disponibilidade ~24x7
SQL/Joins ?
Transações ACID ? Application Layer
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 57
MySQL Cluster Data Nodes
Data Layer
Clients
Application Layer
Management
Arquitetura MySQL Cluster Performance a
Escalabilidade
Facilidade de Uso a
Disponibilidade ~24x7
SQL/Joins a
Transações ACID a
NDB
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 58
Os mesmos dados
acessados
simultaneamente
através de interfaces
SQL e NoSQL
APIs de Acesso aos Dados
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 59
MySQL Cluster Data Nodes
Data Layer
Clients
Application Layer
Management
Arquitetura MySQL Cluster Performance a
Escalabilidade ?
Facilidade de Uso a
Disponibilidade ~24x7
SQL/Joins a
Transações ACID a
Table T1
P2
P3
P4
P1 P1
P3
P2
P4
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 60
MySQL Cluster Data Nodes
Data Layer
Clients
Application Layer
Management
Arquitetura MySQL Cluster Performance a
Escalabilidade a
Facilidade de Uso a
Disponibilidade ~24x7 ?
SQL/Joins a
Transações ACID a
P1
P3
P2
P4 Management
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 61
MySQL Cluster Data Nodes
Data Layer
Clients
Application Layer
Management
Arquitetura MySQL Cluster Performance a
Escalabilidade a
Facilidade de Uso a
Disponibilidade ~24x7 a
SQL/Joins a
Transações ACID a
P1
P3
P2
P4
Management
P3
P1
P4
P2
E mais:
• Permite mudanças no
schema sem interrupção de
leituras ou escritas
• Permite adicionar colunas
e índices online
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 62
Qual API devo usar?
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 63
APIs Java: ClusterJ e JPA
ClusterJ API de persistência Domain
Object Model (DataMapper)
JPA API de persistência padronizada
pelo OpenJPA
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 64
ClusterJ ou JPA?
ClusterJ Fácil de usar, parecida com Hibernate /
JPA / JDO
– Domain Object Model DataMapper pattern
– Dados são representados por Objetos de Domínio
– Objetos de Domínio não contém lógica de negócio (camada
separada)
– Objetos de Domínio são mapeados para tabelas no MySQL
Altíssima Performance
Construído sobre interface nativa Java
– JNI adapter (ndbjtie)
– Parte integral do MySQL Cluster
– Mapeamento direto do MySQL Cluster API (NDB API) para
Java
Limitação: não suporta relacionamentos
– Olhe na API JPA / JDO para estes padrões de modelagem
JPA A interface JPA interface é compatível
com o padrão Java Persistent API
– Implementada como um plugin OpenJPA
Performance mais alta que o JDBC puro
Construída sobre ClusterJ e JDBC
– Usa ClusterJ onde possível e reverte para JDBC para
algumas operações
Adoção mais natural para profissionais
Java
Facilita adoção do Cluster em aplicações
web e aplicações legadas
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 65
Opção 1: Auto-Installer MySQL Cluster 7.3 e 7.4
Rápida configuração
Auto-discovery
Otimização de acordo com a
carga prevista
Melhores práticas de
implantação
MySQL Cluster 7.3 e 7.4
Especifique a carga
Auto-Discover
Defina a Topologia Deploy
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 66
MySQL Cluster Auto-Install
Simples de instalar e provisionar clusters multi-node
Complementa MySQL Cluster Manager no gerenciamento de cliclo de vida
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 67
1. Download MCM/Cluster package: edelivery.oracle.com:
2. Unzip
3. Execute o agent (usuário diferente de root), defina, crie e inicialize o Cluster com um comando!
$> bin\mcmd --bootstrap
Opção 2: MySQL Cluster Manager Para testes em uma única máquina
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 68
ClusterJ: como usar
• Defina Table para Java Mapping
• Defina Connection para o Cluster
• Crie Session
• Comandos: Create, Update, Delete, Find by primary
key
• Query (SELECT)
• O que achou da PERFORMANCE?
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 69
ClusterJ Gera Classes @PersistenceCapable(table="employee")
public interface Employee {
long getId();
void setId(int id);
@Column(name="full_name")
String getName();
void setName(String value);
int getSalary();
void setSalary(int value);
Integer getAge();
void setAge(Integer value);
}
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 70
ClusterJ Base Class public class Employee
extends DynamicObject {
public String table() {
return "employee";
long getId() {
return (Long)get(0);
}
void setId(long value) {
set(0, value);
}
...
// other fields and behavior
}
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 71
Exemplo: ClusterJ 1/3 Session session;
void getSession() {
session = sessionFactory.getSession();
}
Employee createEmployee(long id, String name,
int salary, int age) {
Employee employee =
session.newInstance(Employee.class);
employee.setId(id);
employee.setName(name);
employee.setSalary(salary);
employee.setAge(age);
session.persist(employee);
return employee;
}
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 72
Exemplo: ClusterJ 2/3
Employee findEmployee(long id) {
Employee employee =
session.find(Employee.class, id);
return employee;
}
void updateSalary(long id, int salary) {
Employee employee = findEmployee(id);
employee.setSalary(salary);
session.updatePersistent(employee);
}
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 73
Exemplo: ClusterJ 3/3 Query
QueryDomainType qemp =
builder.createQueryDefinition(Employee.class) ;
Predicate geAge = qemp.get("age")
.greaterEqual(qemp.param("ageFloor"));
Predicate leSalary = qemp.get("salary")
.lessEqual(qemp.param("salaryCap"));
qemp.where(geAge.and(leSalary));
Query query = session.createQuery(qemp) ;
query.setOrdering(Query.DESCENDING, "age");
query.setParameter("ageFloor",33);
query.setParameter("salaryCap", 44000);
List<Employee> results = query.getResultList() ;
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 74
Mais Exemplos ClusterJ e ClusterJPA
Whitepaper:
MySQL Cluster NoSQL APIs for Java
August 2015
mysql.com/why-mysql/white-papers
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 75
Teste e nos diga o que achou da
Performance!
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 76
Exemplos Memcached API
Ondemand Webinar:
NoSQL Memcached API for MySQL Cluster
22 August 2012
mysql.com/news-and-events/on-demand-webinars/display-od-723.html
Slides:
https://www.mysql.com/why-mysql/presentations/mysql-cluster-nosql-
memcached-api
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 77
Algumas limitações MySQL Cluster no white paper
Whitepaper:
MySQL Cluster Evaluation Guide
February 2015
mysql.com/why-mysql/white-papers
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 78
Sumário
As aplicações Web demandam mais dos bancos de dados
nos dias de hoje.
O MySQL pode escalar horizontalmente e ainda oferecer a
tranquilidade de uma solução madura, usada em larga
escala e com suporte (opcional) da Oracle.
Teste e nos dê feedback!
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 79
@MySQLBR meetup.com/MySQL-BR facebook.com/MySQLBR
pt.planet.mysql.com
Estes slides e mais novidades…
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 80
@MySQLBR
meetup.com/MySQL-BR
facebook.com/MySQLBR
Obrigado!
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 81
Perguntas?
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 82
Enterprise Management
Services and Utilities
Backup & Recovery
Monitor
Workbench
Utilities
Connection Pool, SQL Interface, Parser, Optimizer, Caches
Clients & Connectors Native C API, JDBC, ODBC, .Net, PHP, Ruby, Python, VB, Perl mysqld
Clients and Apps
Arquitetura plugável do MySQL
Storage Engines
InnoDB, MyISAM, Memory, Archive, Cluster (NDB API), etc…
Filesystems, Files & Logs
Data, Index, Logs…
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 83
Cluster Data Nodes
NDB NDB
Connection Pool, SQL Interface, Parser, Optimizer, Caches
Enterprise Management
Services and Utilities
Backup & Recovery
Monitor
Workbench
Utilities
Clients & Connectors Native C API, JDBC, ODBC, .Net, PHP, Ruby, Python, VB, Perl
Arquitetura MySQL com NDB Cluster
Storage Engines
InnoDB, MyISAM, Memory, Archive, Cluster (NDB API), etc…
Filesystems, Files & Logs
Data, Index, Logs…
mysqld
Clients and Apps
ndbd
mgm_ndbd
Management