Mittwoch, 16. November 2011

Day 2: Goodbye to SQL??

There is a new hype out there... a scary one called NoSQL.
I've read a bit about NoSQL and definitely wanted to attend at least one session about this theme.

Building Web Applications with MongoDB
(Brendan McAdams)

- MongoDB is schema-less
- For some problems "SQL sucks" and ORM becomes complicated.
- Joins are great but potencially messy
- instead of a "table", MongoDB has a "collection"
_id - primary key. if you don't specify one, driver will generate an unique ObjectId
- JSON Data
- $set -> update

>> NoSQL
- nonrelational
- horizontal scalibility
- no joins, no transactions
- best use-cases: caching, "scaling out"
- less suited for ad hoc BI, highly transactional applications, problems which require SQL

MongoDB revolves around memory mapped files
- operating swstem maps files on the file system to virtual memory
- 200GB MongoDB files creates 200GB of virtual memory
- when a fault occurs, it goes to the disk, hence slowing it down!
- deployment trick: "prewarm" your DB

>> OS Choice
- For production: use a 64bit OS for a 64bit MongoDB Build!
- 32 bit has a 2GB limit imposed by the OS for memory mapped files

>> Filesystem
-MongoDB is filesystem neutral BUT look out for posix_fallocate() because allocation of 2GB takes tile otherwise!

-BSON encoding
- Extent allocation
- Record allocation: padding because of document growth

>>Modeling Schemas
- think documents not rows
- docs arranged in collections
- favor embedding oer refrencing (FK consistency NOT checked)
- no datasource enforced FK relationships
- documents can be 16Mb

-There is a kind of query language that uses $operators
-Commands: drop, count, copydb, findAndModify
- Cursors
- Indexing and query optimization: you can specify hint to force a specific index

MongoDB and Java
- DBObject (like Map interface)
- ObjectId
- BasicDBList - toString() returns well defined JSON representation

>> ODM - Object Document Mappers
relationship: embed or reference
- in Java: Morphia, Spring Data Document
- in Scala: Lift MongoDB Record; Salat

>> Scaling
- read scaling: add replicas
- write scaling: add shards

- data model affects performance
- embedding vs. linking
- partial vs. full document writes
- partial vs. full document reads
Schema and schema usage critical for scaling and performance

-index common queries
-not over index: more indexes mean less data!

- consistent hashing
- range based partitioning

MongoDB Sharding _ automatic partitioning and management
_ fully consistent
_ convert top sharded system with no downtime
_ automatically balanced

MongoDB Backup: dump; restore; or journaling (snapshot)
Regular expressions can be used in searches, but are limited due to the indexes

Very interesting stuff!! And no, it's not goodbye to SQL :)
NoSQL is interesting and there are places where it fits, but it can never replace SQL.
Cooool session :))))

Keine Kommentare:

Kommentar veröffentlichen