65
NoSQL e Python @fmasanori

NoSQL e Python RuPy 2012

Embed Size (px)

DESCRIPTION

http://www.youtube.com/watch?v=EGDv8jctVqw Introdução ao MongoDB, Redis e Cassandra através de Python. Quais as características principais de um banco orientado a documentos, chave-valor e colunar. Que vantagens esses bancos possuem em relação a um banco relacional tradicional. No final farei uma aplicação que persiste dados do Twitter e Facebook nos três bancos mencionados.

Citation preview

Page 1: NoSQL e Python RuPy 2012

NoSQL e Python @fmasanori

Page 2: NoSQL e Python RuPy 2012

• Graduado IME-USP e Mestrado ITA

• ed e lint Cobra Tecnologia

• Software Express

• Credicard Mastercard

• PriceWaterhouseCoopers

• ITAU BankBoston

• Docente FATEC SJC (amo dar aulas): – Business Intelligence/Data Warehouse

– NoSQL databases

• Interesses: Python, NoSQL, Google Technology, Facebook

@fmasanori

Page 3: NoSQL e Python RuPy 2012
Page 4: NoSQL e Python RuPy 2012

• Python?

• NoSQL?

• pymongo?

• redis-py?

• pycassa?

Conhecendo os assistentes

Page 5: NoSQL e Python RuPy 2012

• Como comecei com NoSQL

• LucidDB: my first NoSQL experiment

• Flexible Schema

• Horizontal Scalability

• MongoDB (document)

• Redis (key-value)

• Cassandra (columnar)

• Demo

Agenda

Page 6: NoSQL e Python RuPy 2012

Como comecei com NoSQL

Page 7: NoSQL e Python RuPy 2012

• Me ensinaram que tudo deveria ser normalizado...

• E que o mundo era SQL

• Mas um dia tive problemas:

– Analytics

– Twitter and Facebook data persistence

One Simple Idea

Page 9: NoSQL e Python RuPy 2012

Queries

• Which movie genres generate the most revenue? (Q1)

• How is our revenue evolving over time? (Q2)

• At which time of day do costumers place the most orders? (Q3)

• How effective are the promotions we launch? (Q4)

Queries

Page 10: NoSQL e Python RuPy 2012

Average time (ms)

0

5000

10000

15000

20000

25000

30000

35000

Q1 Q2 Q3 Q4

LucidDB

MySQL

Page 11: NoSQL e Python RuPy 2012

JSON persistence

Page 12: NoSQL e Python RuPy 2012

menina: aaaaaaaaaaaaaa eu NAO GOSTO DELE

amiga: e vc ficará rica , e irá dividir sua riqueza cm sua amg aq

*u*

menina: kkkkkk como assim eu fikar rica pq?

amiga: pq ele é inteligente , e vai arranjar um ótimo emprego , e

ganhar mt dinheiro rs

menina: kkkkk ele é inteligente como assim ??

amiga: AQUELE VIADO PASSOU NO CASDINHO, E EU NÃO !

Sentiment Analysis (Twitter)

Page 13: NoSQL e Python RuPy 2012

• Sabe o que é ter vontade de acordar cedo no domingo para estudar?!?

• Bom, eu também não sei explicar, mas é o que estou sentindo no momento .-.

• Bora Casdinho!

Sentiment Analysis (Facebook)

Page 14: NoSQL e Python RuPy 2012

Social Data Change Fast

Page 16: NoSQL e Python RuPy 2012

“It’s better to think of NoSQL as a

movement rather

than a technology” Martin Fowler

Page 17: NoSQL e Python RuPy 2012

NoSQL vale a pena

Page 18: NoSQL e Python RuPy 2012

Empregabilidade

Page 19: NoSQL e Python RuPy 2012

Empregabilidade

Page 20: NoSQL e Python RuPy 2012

Empregabilidade

Page 21: NoSQL e Python RuPy 2012

Dynamic Schema

O que as empresas esperam de um NoSQL?

Page 22: NoSQL e Python RuPy 2012

Flexible Schema

O que as empresas esperam de um NoSQL?

Page 23: NoSQL e Python RuPy 2012

Relational DB

Page 24: NoSQL e Python RuPy 2012

Martin Fowler

Relational DB

Page 25: NoSQL e Python RuPy 2012

• The difference between the relational model and the in-memory data structures (Fowler)

• Limitations of relational DB: values only in tuples

• We need a more complex structure than a set of tuples as a data unit

Impedance mismatch

Page 26: NoSQL e Python RuPy 2012

Costumers Orders

Martin Fowler

Aggregate Model

Page 27: NoSQL e Python RuPy 2012

Costumers

Martin Fowler

Aggregate Model

Page 28: NoSQL e Python RuPy 2012

Scalability

Page 29: NoSQL e Python RuPy 2012

If I had asked people what they wanted, they would have said faster

horses. Henry Ford.

Page 30: NoSQL e Python RuPy 2012

• Escalabilidade para leituras num banco relacional: trabalhoso

• Escalabilidade para escritas num banco relacional: MUITO, MUITO, trabalhoso

• (se conseguir seu BD deixou de ser relacional...)

Escalabilidade vertical

Page 31: NoSQL e Python RuPy 2012

Escalabilidade vertical

Page 32: NoSQL e Python RuPy 2012

Escalabilidade horizontal

Page 33: NoSQL e Python RuPy 2012

Escalabilidade horizontal

Page 34: NoSQL e Python RuPy 2012

• Bigtable: A distributed storage system for structured data, 2006

• Dynamo: Amazon’s highly available key-value store, 2007

Dois artigos famosos

Page 35: NoSQL e Python RuPy 2012

Apache Hadoop

Page 36: NoSQL e Python RuPy 2012

Not Only SQL

Page 37: NoSQL e Python RuPy 2012

There is no best NoSQL

Page 38: NoSQL e Python RuPy 2012

• JSON oriented • Autosharding • Full featured indexes • Great community

Page 39: NoSQL e Python RuPy 2012

Dowload and install:

http://www.mongodb.org/downloads

Criar c:/data/db

Servidor:

bin/mongod

Cliente:

bin/mongo

Cliente pymongo:

http://api.mongodb.org/python/current/

import pymongo

Curso completo MongoDB com Python:

http://education.10gen.com/

Page 40: NoSQL e Python RuPy 2012

• Data Structure Server • In-memory dataset • Persistence options

Page 41: NoSQL e Python RuPy 2012

• CPU performance 175X (96) • Os discos continuam iguais • Memory 1M faster • 1M = $1 (2000) x 1 cent (2010)

Page 42: NoSQL e Python RuPy 2012

http://redis.io/download

https://github.com/MSOpenTech/redis

(for Windows)

Servidor:

redis-server

Cliente:

redis-cli

Cliente redis-py:

https://github.com/andymccurdy/redis-py

import redis

Page 43: NoSQL e Python RuPy 2012

Cassandra: • Linearly Scalable • Column based • CQL

Page 44: NoSQL e Python RuPy 2012

Martin Fowler

Page 45: NoSQL e Python RuPy 2012

MySQL:

~300ms write

~350ms read

Cassandra:

~0.12ms write

~15ms read

Cassandra vs MySQL (50GB)

Page 46: NoSQL e Python RuPy 2012
Page 47: NoSQL e Python RuPy 2012

(Timo Elliott, SAP)

Relational DB

Page 48: NoSQL e Python RuPy 2012

Columnar DB

(Timo Elliott, SAP)

Page 49: NoSQL e Python RuPy 2012

Download DataStax Community Edition

Servidor:

cassandra

Cliente:

cassandra-cli –h localhost –p 9160

Conflitos:

cassandra.bat (windows)

/etc/cassandra/cassandra-env.sh (ubuntu)

Cliente pycassa:

https://github.com/pycassa/pycassa/downloads

import pycassa

Page 50: NoSQL e Python RuPy 2012

Talk is cheap.

Show me the code. Linus Torvalds

Page 51: NoSQL e Python RuPy 2012

MongoDB Server

Page 52: NoSQL e Python RuPy 2012

Cassandra Server

Page 53: NoSQL e Python RuPy 2012

Cassandra Server

Page 54: NoSQL e Python RuPy 2012

Redis Server

Page 55: NoSQL e Python RuPy 2012

Obs.: não aparece o token de autenticação

Twitter and Facebook data

Page 56: NoSQL e Python RuPy 2012

Pymongo

Page 57: NoSQL e Python RuPy 2012

Redis-py

Page 58: NoSQL e Python RuPy 2012

Pycassa

Page 59: NoSQL e Python RuPy 2012

Pymongo response

Page 60: NoSQL e Python RuPy 2012

Redis-py response

Page 61: NoSQL e Python RuPy 2012

Pycassa response

Page 62: NoSQL e Python RuPy 2012

Bigliografia

Page 63: NoSQL e Python RuPy 2012

Bigliografia