mongodb, rabbitmq y applicaciones en nube
DESCRIPTION
Review de las principales tecnologías que estamos usando en cloudTRANSCRIPT
MongoDB, RabbitMQ y aplicaciones en nube
Gustavo Arjones [email protected] | @arjones
Arquitectura orientada a msjs
h8p://railsdog.com/blog/2009/12/generaAng-‐pdfs-‐on-‐ec2-‐with-‐ruby/
RabbitMQ
• Message Queue (AMQP compliance) • Arquitectura orientada a mensajes
• Desacoplado, Aislado • Facil escalabilidad horizontal
• “AlternaAva”: Kestrel / Twi8er (NO AMQP!)
Direct Message
Cerveza Vino
Cerveza
Cerveza
Matching exact key
Fanout Exchange
Bebida Bebida
Cerveza
Cerveza Cerveza
Copy to all
Topic Exchange
#.Vino Comida.*
Bebida.Vino
Route by Key with Key Globbing
Bebida.#
Bebida.Vino Bebida.Vino
Nanite
• Nanite is a new way of thinking about building cloud ready web applicaAons. Having a scalable message queueing back-‐end with all the discovery and dynamic load based dispatch that Nanite has is a very scalable way to construct web applicaAon back-‐ends.
MongoDB es …
• DB Orientado a documentos (schemaless) • “Facil” escalar horizontal (shard) • Para mantener estructuras complejas (jerarquicas)
• Para estadísAcas “simples”
• Para mantener archivos (GridFS)
MongoDB NO es …
• Para transaciones • Para OLAP • RDBMS (AcAveRecord?)
Select SELECT first_name, last_name
FROM authors WHERE zipcode = 1234
ORDER BY last_name DESC LIMIT 2, 1;
> db.authors.find({"zipcode" : 1234}, {"first_name" : 1, "last_name" : 1 }).sort({"last_name" : -‐1 })
.skip(2).limit(1);
Select SELECT *
FROM authors WHERE dob BETWEEN ‘1970-‐1-‐1’ AND ‘1990-‐1-‐1’
AND address IS NULL;
> db.authors.find({"dbo" : { $gte : new Date(“1970-‐1-‐1”), $lte : new Date(“1990-‐1-‐1”)}, “address” : { $exists : false } } );
Upsert (Update + Insert)
> db.tweets.update( query, modify, upsert?, mul2ple? );
> db.setup.update({}, { $set : { "in_progress" : false } }, false, true);
> db.setup.update({}, { "opAons.last_status" : -‐1}, false, true);
Indexes > db. tweets.ensureIndex(
{"user.Ame_zone" : 1}, {background:true});
> db.tweets.ensureIndex( {"created_at" : 1, "user.Ame_zone" : 1, "tokens" : 1}, {background:true});
background:true no lock para crear indices
> db.tweets.getIndexes()
Prós • Schemaless
• Rápida instalación • Muchos Drivers disponibles
• Map-‐Reduce MUY lento
• Sharding es BETA • Nuevo set de commandos
Contras
Tips • Pensar BIEN el schema antes de empezar • Guardar calculaAon • Evitar map-‐reduce (unAl r. 1.8) • Indexes TIENEN que entrar en RAM
> db. tweets.totalIndexSize(); 1187423168 (~1.1Gb)
> db. tweets.storageSize(); 16670199040 (~15.5 Gb)
Referencias
• h8p://www.rabbitmq.com/
• h8p://www.mongodb.org/
• h8p://github.com/ezmobius/nanite
• h8p://github.com/robey/kestrel
• h8p://www.slideshare.net/somic/introducAon-‐to-‐amqp-‐messaging-‐with-‐rabbitmq
• h8p://www.slideshare.net/ma8ma8/rabbitmq-‐and-‐nanite
Muchas gracias
Gustavo Arjones [email protected] | @arjones