Académique Documents
Professionnel Documents
Culture Documents
com
#105
CONTENTS INCLUDE:
n
Introduction
Scalable Data Architecture
Is NoSQL For You?
mongoDB
GigaSpaces XAP
Google App Engine Datastore and more...
By Eugene Ciurana
Implementations of either often share characteristics from the
other.
INTRODUCTION
Data Grids
Consumer
www.dzone.com
Master
Load Balancer
Node
Hot
Tip
Node
Node
Node
Node
Node
Node
Load Balancer
Hot
Tip
Node
www.dzone.com
Areas of Application
Financial modeling
Data mining
Click stream analytics
Document clustering
Distributed sorting or grepping
Simulations
Inverted index construction
Protein folding
NoSQL
Preparation:
NoSQL
RDBMS
OO
Kind
Table
Class
Entity
Record
Object
Attribute
Column
Property
Consistency (all nodes see the same data at the same time)
Availability (node failures dont prevent survivors from
continuing to operate)
Partition tolerance (no failures less than total network
failures cause the system to fail)
Consumer
Node
Node
Node
Hot
Tip
Relational
Key-Value
Column-Oriented
Document-Oriented
Consistency
Availability
e
as
Hb
le, ris
tab cala
er
yp , S
, H DB
re he
sto cac
ata em
,D M
re B,
sto D
rra ley
Te rke
B, Be
oD s,
ng edi
R
mo
Areas of Application
Document storage
Object databases
Graph databases
Key/value stores
Eventually consistent key/value stores
This list is the implementation counterpart to the data grid
areas of application; the data store feeds the computational
network and, together, they form the NoSQL database.
DZone, Inc.
Partition tolerance
Figure 3 - CAP Selection Chart
(source: Nathan Hurst's Blog)
|
a,
FS 2
dr
FS 1
ss
an
FS 0
Vo
lde
Si mor
mp t,
leD Tok
B, yo
Co Ca
uc bin
hD et
B, , KA
Ri I,
ak C
a
Tablet
Server 1
o,
Tablet
Server 0
na
m
Node
Dy
Hot
Tip
www.dzone.com
mongoDB
mongoDB is a document-based NoSQL database that bridges
the gap between scalable key-value stores like Datastore
and Memcache DB, and RDBMSs querying and robustness
capabilities. Some of its main features include:
BSON Example
{
'name' : 'Tom',
'age' : 42
}
Python
{
'name' : 'Tom',
'age' : 42
{
"name" => "Tom",
"age" => 42
}
Java
BasicDBObject d;
d = new BasicObject();
d.put("name", "Tom");
d.put("age", 42);
PHP
mongoDB Programming
Programming in mongoDB requires an active server running
the mongod and the mongos database daemons (see Figure
5), and a client application that uses one of the languagespecific drivers.
fail-over
Data
Storage
mongos
Sharding
daemon
Hot
Tip
Data
Storage
Hot
Tip
Representation
Consumer
mongos
Sharding
daemon
Language
Ruby
mongod
Database
daemon
[servername:user] ./mongod
Caching
db = connection['people_database']
peopleList = db['people_list']
person = {
'name' : 'Tom',
'age' : 42 }
Document Format
mongoDB handles documents in BSON format, a binaryDZone, Inc.
www.dzone.com
peopleList.insert(person)
person = {
'name' : 'Nancy',
'age' : 69 }
peopleList.insert(person)
# find first entry:
person = peopleList.find_one()
# find a specific person:
mongoDB Drawbacks
if person is None:
print "Joe isnt here!"
else:
print person['age']
# bulk inserts
persons = [{ 'name' : 'Joe' }, {'name' : 'Sue'}]
peopleList.insert(persons)
# queries with multiple results
for person in peopleList.find():
print person['name']
GIGASPACES XAP
# count:
nDrinkingAge = peopleList.find({'age' : {'$ge' : 21}}).count()
# indexing
from pymongo import ASCENDING, DESCENDING
peopleList.create_index([('age', DESCENDING), ('name', ASCENDING)])
Application Frameworks
Java
C++
.Net
Groovy
Mule
Spring
JEE
Jetty
Object ID
A successful insertion into the database results in a valid
Object ID. This is the unique identifier in the database for a
given document. When querying the database, a return value
will include this attribute:
{
"name" : "Tom",
"age" : 42,
"_id" : ObjectId('999999')
}
RDBMS
mongoDB
Memcache DB
www.dzone.com
Google
Applications
Datastore
Java (JDO, JPA)
API 1
Other language
Datastore
Python
Bigtable
Master Server
(Logical table management, load balancing, garbage collection)
Tablet
Server 0
http://www.gigaspaces.com/wiki/display/XAP71/Programmer%27s+Guide
Tablet
Server 1
Tablet
Server n
FS 0
FS 1
FS 2
FS n
Hot
Tip
Datastore Programming
The programming model is based on inheritance of basic
entities, db.Model and db.Expando. Persistent data is
mapped onto an entity specialization of either of these classes.
The API provides persistence and querying instance methods
for every entity managed by the Datastore.
Programming Example
The Datastore API is simpler than other NoSQL APIs and is
highly optimized to work in the App Engine environment. In
this example we insert data into the data store, then run a query:
class Person(db.Model):
name = db.StringProperty(required=True)
age = db.IntegerProperty(require=True)
person = Person(name = 'Tom', age = 42)
person.put()
Your
Applications
www.dzone.com
Datastore Drawbacks
Vendor lock-in - persistence and queries are tightly
coupled with the Datastore and the Datastore API is far
from being an industry standard
Availability - Datastore has been known to fail and the
EULA doesnt allow more than 4-nines SLAs
Quotas - Datastore utilization costs per data access and
for processor time
Query limits - Result sets are limited to return a maximum
of 1,000 entities, forcing queries be needlessly complex
RECOMMENDED BOOK
MongoDB, a cross-platform NoSQL database, is the fastestgrowing new database in the world. MongoDB provides a
rich document orientated structure with dynamic queries that
youll recognize from RDMBS offerings such as MySQL. In other
words, this is a book about a NoSQL database that does not
require the SQL crowd to re-learn how the database world
works!
ref ca
RATION
Upcoming Refcardz
By Daniel Rubio
ge. Colla
Chan
dz. com
HTML
LUD E:
Basics
ref car
L vs XHT technologies
Automated growthHTM
& scalable
to isolat
space
n
e Work
riptio
itory
a Privat
Desc
ge
These companies
have
webmana
applications
are in long deployed
trol repos
to
n-con
lop softw
ing and making them
Deve
a versio
that adapt
and scale
bases,
rn
les toto large user
ize merg
Patte
it all fi
minim
le
space
Comm
ine to
tos multip
cloud
computing.
e Work knowledgeable in amany
mainl aspects related
Privat
that utilize
lop on
Deve code lines
a system
sitory
of work
Vis it
Valid
ML
Apache Ant
Hadoop
Spring Security
Subversion
Elem
al Elem ents
Large scale growth scenarios involvingents
specialized
and mor equipment
e... away by
(e.g. load balancers and clusters) are all but abstracted
Structur
rdz !
e.com
INTEG
Cloud#64Computing
HTM
L BAS
Core
HTML
By An
dy Ha
rris
Cloud Computing
Vis it
rd z!
Re fca
Aldon
active
Repo
are within
d units
This Refcard
will introduce
to you to cloud
softw
riente computing, with an
loping
ine
task-o it
e
Mainl
es by
emphasis onDeve
these
so
youComm
can better understand
ines providers,
softwar
chang
codel
e code
ding
Task Level
sourc es as aplatform
what it is a cloudnize
computing
can offer your
trol
ut web
line Policy
of buil
NT
Orga
Code
e witho
it chang
cess
ion con
e name
sourc
T CO
and subm
applications.
it
the pro jects vers
are from
with uniqu
ABOU
softw
(CI) is
um
the build
evel Comm
build
a pro
minim
Label
Task-L
ies to
gration
ed to
activit
blem
the bare
ion
ate all
cies to
t
ous Inte
committ
USAGE SCENARIOS
to a pro
Autom configurat
nden
ymen
Build
depe
al
deplo
t
Continu ry change
manu
Label
d tool
solution fective
nmen
a
the same
stalle
,
)
Build
eve
t, use target enviro
(i.e.
, inef
ated
ce pre-in
with
ymen
Redu
problem
Autom
terns
ns (i.e.
ory.
d deploEAR) in each
Pay only
consume
ticular
tagge
via pat
or
cieswhat you
-patter
s that
reposit
t
nden
For each (e.g. WAR
es
lained ) and anti
the par solution duce
al Depeapplication deployment
ge
librari
x
t
exp
Web
until
a
few
years
agonmen
was similar
t enviro
packa
Minim
are
be
nden
text
to fi
to pro
all targe
rity
all depe
tterns
can
used
CI can ticular con
le that
alizeplans with
tend
y Integ
to
most phone services:
late fialloted resources,
Centr
Binar
ts with an
Anti-pa
they
es, but
etimes
temp
nt
nmen
on
ng
end,
in a par hes som
cess.
geme
practic
t enviro
e a single
incurred
cost
whether
such
resources
were
consumed
or
pro
enti
the
based
thenot.
Mana
targe
in
Creat
cy
nt
es to
rties are
rily bad
nden
implem
approac ed with the cial, but,
chang
prope
Depe
into differe
itting
er
necessa pared to
efi
te builds
e comm
late Verifi
associat to be ben
befor
etc.
are not
Cloud
computing asRun
itsremo
known etoday
has changed this.
Temp
n com
Build
ually,
They
Privat
lts whe
y, contin
appear effects.
rm a
nt team
dicall
The various
resourcesPerfo
consumed
by webperio
applications
(e.g.
opme
ed resu
d Builds
sitory
Build
gration
r to devel
Repo
Stage
adverse unintend
ration on a per-unit
bandwidth,
memory, CPU)
areInteg
tallied
basis
CI serve
e
ous Inte
from
e Build
rm an
tinu
ack
ard
produc
Privat
Con
feedb computing platforms.
Refc
on
(starting
from zero) by Perfo
all majorated
cloud
tern.
occur
term
based
autom
e, this
as
as they
the pat
builds
Build
gration
Send
of the
soon
cycl
such
ration
ion with
ors as
Integ
entat
ous Inte tional use and test concepts
tinu
docum
ven
oper
Con
build include
the con s to the
rate devel
to
Gene
While
of CI
efer
notion
the
s on
expand
S
INUOU
Mo re
Re fca
Ge t
tion:
tegra ternvasll
us Ind Anti-PPaat
Du
ul M.
nuorn
By
an
ti
s
n
o
C
Patte
w ww.dzone.com
rdz .co
E:
INC LUD gration
NTS
ous Inte Change
CO NTE
Continu at Every
ns
About
Software i-patter
Build
and Ant
Patterns Control
ment
Version
e...
Manage s and mor
Build
Practice
d
Buil
CONTENTS INCLUDE:
Cost
by...
youTechnologies
Data
t toTier
Comply.
brough
Platform Management and more...
borate.
Ge t Mo
re
#84
#82
BUY NOW
books.dzone.com/books/mongodb
Publications
Developing with Google App Engine
DZone Refcard #43: Scalability and High Availability
DZone Refcard #38: SOA Patterns
The Tesla Testament: A Thriller
DZone, Inc.
140 Preston Executive Dr.
Suite 100
Cary, NC 27513
ISBN-13: 978-1-934238-75-2
ISBN-10: 1-934238-75-9
50795
888.678.0399
919.678.0300
Refcardz Feedback Welcome
refcardz@dzone.com
Sponsorship Opportunities
sales@dzone.com
$7.95
Hot
Tip
STAYING CURRENT
9 781934 238752
Copyright 2010 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical,
photocopying, or otherwise, without prior written permission of the publisher.
Version 1.0