Perchè potresti aver bisogno di un database NoSQL anche se non sei Google o Facebook

  • 2,284 views
Uploaded on

La presentazione di Luca Garulli …

La presentazione di Luca Garulli
in occasione del Codemotion, Roma 5 marzo 2011 http://www.codemotion.it

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,284
On Slideshare
0
From Embeds
0
Number of Embeds
4

Actions

Shares
Downloads
0
Comments
0
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Perchè potresti avere bisogno di un database NoSQL anche se non sei Google o Facebook Luca Garulli
  • 2. The graph db for the Enterprise & Web www.orientechnologies.com
  • 3. Why do I could need something different than a Relational DBMS ? www.orientechnologies.com
  • 4. (1) RDBMSs have more than 30 years Information Technology is not properly the same of '70 ... www.orientechnologies.com
  • 5. (2) In the Web age applications could have Thousands or Millions of users Are you ready for this? www.orientechnologies.com
  • 6. (3) Time-to-Market measured not anymore in years/man but days/weeks for a demo and months for the final www.orientechnologies.com
  • 7. (4) Applications are more “ social” with much more relationships - tabular data and + interconnected Graphs www.orientechnologies.com
  • 8. (5) Who believe yet to the bullshit that performance problems can be resolved just by scaling with the hardware? www.orientechnologies.com
  • 9. (6) We use new stuff everyday HTTP , REST , Javascript & JSON How can I use them in better way without conversions & mapping? www.orientechnologies.com
  • 10. (7) Modern applications are mostly I/O Bound not CPU bound. Often the DB Is the bottleneck of all www.orientechnologies.com
  • 11. www.orientechnologies.com NoSQL = “Not Only SQL” = make the best choice for your use case
  • 12. Can I trust new DBMSs? www.orientechnologies.com
  • 13. www.orientechnologies.com
  • 14. www.orientechnologies.com Non exhaustive list of NoSQL products: AllegroGraph, Amazon SimpleDB, Amazon Dynamo, Dynomite, BerkleyDB, Google BigTable, Cassandra, CouchDB, DB4O, Hbase, Hipertable, Hive, Jackrabbit, InfiniteGraph, InfoGrid, Memcached, MemcacheDB, Mnesia, M/DB/DT.M, MongoDB, Neo4J, OrientDB , Pig, Project Voldemort, RavenDB, Redis, Riak, Scalaris, Sesame, Sones, Terrastore, Tokyo Cabinet/Tyrant, Yahoo! Pnuts/Sherpa
  • 15. www.orientechnologies.com The “NoSQL container” groups so very-very-very different products, no standard, difficult to choice, difficult to learn them
  • 16. www.orientechnologies.com Can I have a Fast, scalable, flexible storage with transactions , SQL and security easy to use and maintain?
  • 17. www.orientechnologies.com The fastest NoSQL document - graph dbms
  • 18. +12 years of research www.orientechnologies.com
  • 19. +1,5 year of design and development www.orientechnologies.com
  • 20. = best features of newest NoSQL solutions + best features of Relational DBMS + new ideas and concepts www.orientechnologies.com
  • 21. Ø config download, unzip, run! cut & paste the db www.orientechnologies.com
  • 22. No dependencies with 3 rd parties software no conflicts with other software About 1 Mb of run-time libraries www.orientechnologies.com
  • 23. Java ® runs everywhere is available JRE1.5+ robust engine www.orientechnologies.com
  • 24. 150,000 records per second www.orientechnologies.com
  • 25. Schema- less schema is not mandatory, relaxed model , collect heterogeneous documents all together www.orientechnologies.com
  • 26. Schema- full schema with constraints on fields and validation rules Customer.age > 17 Customer.address not null Customer.surname is mandatory Customer.email matches 'b[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}b' www.orientechnologies.com
  • 27. Schema- mixed schema with mandatory and optional fields + constraints the best of schema-less and schema-full modes www.orientechnologies.com
  • 28. ACID Transactions db.begin(); try{ // your code ... db.commit(); } catch( Exception e ) { db.rollback(); } www.orientechnologies.com
  • 29. Complex types native support for collections : ['cool','fast'] maps (key/value): { 'age', 33 } and embedded documents no more additional tables to handle them www.orientechnologies.com
  • 30. Relationships are direct links no Relational JOINS to connect multiple tables Load trees and graphs in few ms ! www.orientechnologies.com
  • 31. Example of a Graph www.orientechnologies.com
  • 32. SQL select * from employee where name like '%Jay%' and status=0 www.orientechnologies.com
  • 33. www.orientechnologies.com A NoSQL product that supports SQL ? Naa... is it a joke?
  • 34. www.orientechnologies.com For the most of the queries everyday a programmer needs SQL is simpler, more readable and compact then Scripting (Map/Reduce)
  • 35. www.orientechnologies.com SELECT SUM(price) as prices, SUM(cost) as costs, prices-costs, margin/price FROM Balance VS function (key, values) { var price = 0.0, cost = 0.0, margin = 0.0, marginPercent = 0.0; for (var i = 0; i < values.length; i++) { price += values[i].price; cost += values[i].cost; } margin = price - cost; marginPercent = margin / price; return { price: price, cost: cost, margin: margin, marginPercent: marginPercent }; }
  • 36. For Relational skilled Developers (everyone of us?) using OrientDB is easy www.orientechnologies.com
  • 37. Asynchronous Query invoke callback when a record matches the condition doesn't collect the result set perfect for immediate results useful to compute aggregates www.orientechnologies.com
  • 38. Language bindings Java as native JRuby , Scala and Javascript ready C , C++ , Ruby , Node.js in progress www.orientechnologies.com
  • 39. Your language is not supported (yet)? Write an adapter using the C, Java or HTTP binding www.orientechnologies.com
  • 40. HTTP RESTful firewall friendly use it from the web browser use it from the ESB (SOA) www.orientechnologies.com
  • 41. Native JSON { '@rid' = '26:10', '@class' = 'Developer', 'name' : 'Luca', 'surname' : 'Garulli', 'company' : '19:76' } www.orientechnologies.com
  • 42. Import/Export uses JSON format online operations (don't stop the database) www.orientechnologies.com
  • 43. MVRB+Tr e e index the best of B+Tree and RB-Tree fast on browsing, low insertion cost It's a new algorithm (soon public) www.orientechnologies.com
  • 44. www.orientechnologies.com OO Inheritance Definition of Classes of documents Classes can extend others classes Queries are polymorphics Contact name : string surname : string Customer orders : List<Order> Provider products : List<Product>
  • 45. Hooks similar to triggers catch events against records , database and transactions implement custom cascade deletion algorithm enforce constraints www.orientechnologies.com
  • 46. Fetch plans Choose what to fetch on query and document loading Documents not fetched will be lazy-loaded on request Invoice 3:100 | | customer +---------> Customer | 5:233 | city country +---------> City ---------> Country | 11:2 12:3 | orders +--------->* [ OrderItem OrderItem OrderItem ] [ 8:12 8:19 8:23 ] www.orientechnologies.com
  • 47. Security users and roles , encrypted passwords fine grain privileges www.orientechnologies.com
  • 48. 4 storage modes embedded client/server distributed in-memory www.orientechnologies.com
  • 49. Embedded mode really fast runs in the same JVM of the application, less resources, no tcp/ip used www.orientechnologies.com
  • 50. Client/server mode client and server are separated JVMs thousands of clients concurrently remote tcp/ip binary transport www.orientechnologies.com
  • 51. Distributed mode distribute database clusters on multiple servers (in alpha status) www.orientechnologies.com
  • 52. In-memory mode Database lives only in memory No disk is used Destroyed at shutdown www.orientechnologies.com
  • 53. www.orientechnologies.com Java API Document Database Graph Database Object Database
  • 54. Document Database the base of all DB implementations documents have dynamic structure something like a smart Map<String,Object> or a record with dynamic fields www.orientechnologies.com
  • 55. Demo! www.orientechnologies.com
  • 56. SQL Query List<ODocument> result = db.query( new OSQLSynchQuery( &quot;select * from person where city.name = 'Rome'&quot; ) ); for( ODocument d : result ) { System.out.println( &quot;Person: &quot; + d.field( &quot;name&quot; ) + d.field( &quot;surname&quot; ) ); } www.orientechnologies.com
  • 57. Native Query List<ODocument> result = new ONativeSynchQuery<ODocument, OQueryContextNativeSchema<ODocument>>( db, &quot;Profile&quot;, new OQueryContextNativeSchema<ODocument>()) { @Override public boolean filter(OQueryContextNativeSchema<ODocument> iRecord) { return iRecord.field(&quot;city&quot;).field(&quot;name&quot;).eq(&quot;Rome&quot;).and().field(&quot;name&quot;).like(&quot;G%&quot;).go(); }; }.setLimit(20).execute(); www.orientechnologies.com
  • 58. Update a document List<ODocument> result = db.query( new OSQLSynchQuery( &quot;select * from person where city.name = 'Rome'&quot;)); for( ODocument d : result ) { d.field( &quot;local&quot;, true ); d.save(); } // IT'S THE SAME OF: db.command( new OSQLCommand( &quot;update person set local = true where city.name = 'Rome'&quot;)) .execute(); Copyright © 2010 Luca Garulli - www.orientechnologies.com
  • 59. Delete a document List<ODocument> result = db.query( new OSQLSynchQuery( &quot;select * from person where city.name = 'Rome'&quot; ) ); for( ODocument d : result ) { d.delete(); // IT'S THE SAME OF: int deleted = db.command( new OSQLCommand( &quot;delete person where city.name = 'Rome'&quot;)).execute(); Copyright © 2010 Luca Garulli - www.orientechnologies.com
  • 60. from/to JSON // EXPORT JSON System.out.println( document.toJSON() ); // IMPORT JSON document.fromJSON( “{ '@class' = 'Developer', 'name' : 'Luca', 'surname' : 'Garulli' }” ); document.save(); www.orientechnologies.com
  • 61. Use hooks (triggers) public class HookTest extends ORecordHookAbstract { public saveProfile(){ ODatabaseObjectTx database = new ODatabaseObjectTx(&quot;remote:localhost/demo&quot;); database.open(&quot;writer&quot;, &quot;writer&quot;); database.registerHook(this); ... } @Override public void onRecordAfterCreate(ORecord<?> iRecord){ System.out.println(&quot;Record created successfully&quot;); } } www.orientechnologies.com
  • 62. Object Database wrapper on top of Document Database binds POJO from/to the database no OR-Mapping complexity no enhancement, no Java Proxies www.orientechnologies.com
  • 63. POJO mapping Uses the reflection to bind POJO fields at start-up caches reflection meta-data 1-to-1 binding configurable options by @annotations www.orientechnologies.com
  • 64. Demo! www.orientechnologies.com
  • 65. Polymorphics SQL Query List<Person> result = database.query( new OSQLSynchQuery(&quot;select from person where city.name = 'Rome'&quot;)); for( Person p : result ) { if( p instanceof Customer ) System.out.println(&quot;Customer: &quot; + p.getName() + “ “ + p.getSurname() ); } www.orientechnologies.com Queries are polymorphics and subclasses of Person can be part of result set
  • 66. Graph Database wrapper on top of Document Database Few simple concepts: Vertex , Edge , Property and Index www.orientechnologies.com
  • 67. TinkerPop Blueprints http://tinkerpop.com Standard de-facto to interact with GraphDBs implements transactional and indexable property graph model with bidirectional edges www.orientechnologies.com
  • 68. TinkerPop Blueprints Available implementations: OrientDB Neo4J, Sail (RDF storage) Under development: InfiniteGraph, DEX, Redis www.orientechnologies.com
  • 69. GraphDB & Blueprints API OrientGraph graph = new OrientGraph(&quot;local:/tmp/db/graph”); Vertex actor = graph.addVertex(null); actor.setProperty(&quot;name&quot;, &quot;Leonardo&quot;); actor.setProperty(&quot;surname&quot;, &quot;Di Caprio&quot;); Vertex movie = graph.addVertex(null); movie.setProperty(&quot;name&quot;, &quot;Inception&quot;); Edge edge = graph.addEdge(null, actor, movie, &quot;StarredIn&quot;); graph.shutdown(); www.orientechnologies.com
  • 70. TinkerPop scripting language easy to learn and understand Used for operations against graphs www.orientechnologies.com
  • 71. www.orientechnologies.com Graph example graph-example-1.xml
  • 72. Load graph Run the console, open the database and load a graph in xml format marko:~/software/gremlin$ ./gremlin.sh ,,,/ (o o) -----oOOo-(_)-oOOo----- gremlin> $_g := orientdb:open('/tmp/graph/test') ==>orientgraph[/tmp/graph/test] gremlin> g:load('data/graph-example-1.xml') ==>true gremlin> $_g ==>orientgraph[/tmp/graph/test] www.orientechnologies.com
  • 73. Search Displays outgoing edges of vertices with name equals to 'marko', then the name of inbound vertices gremlin> g:key-v('name','marko')/outE ==>e[6:0][5:2-knows->5:1] ==>e[6:1][5:2-knows->5:4] ==>e[6:4][5:2-created->5:0] gremlin> g:key-v('name','marko')/outE/inV/@name ==>vadas ==>josh ==>lop gremlin> g:close() ==>true www.orientechnologies.com
  • 74. API resume object, key/value and graph elements all work on top of Document you can always access to the underlying document changes to the document are reflected to the object, key/value and graph elements and viceversa www.orientechnologies.com
  • 75. Enhanced SQL SQL is not enough for collections, maps, trees and graphs need to enhance SQL syntax Easy syntax derived from JDO/JPA standards www.orientechnologies.com
  • 76. SQL & relationships select from Account where address .city.country.name = 'Italy' select from Account where addresses contains ( city.country.name = 'Italy') www.orientechnologies.com
  • 77. SQL & trees/graphs select from Profile where friends traverse(0,7) ( sex = 'female' ) (Soon new specific operators for trees and graphs) www.orientechnologies.com
  • 78. SQL & strings select from Profile where name .toUpperCase() = 'LUCA' select from City where country.name .substring(1,3).toUpperCase() = 'TAL' select from Agenda where phones contains ( number .indexOf( '+39' ) > -1 ) select from Agenda where email matches 'bA-Z0-9._%+-?+@A-Z0-9.-?+.A-Z?{2,4}b' www.orientechnologies.com
  • 79. SQL & conversions select from Shapes where area .toFloat() > 3.14 select from Agenda where birthDate .toDateTime() > '1976-10-26 07:00:00' select from Workflow where completed .toBoolean() = true www.orientechnologies.com
  • 80. SQL & schema-less select from Profile where any() like '%Jay%' select from Stock where all() is not null www.orientechnologies.com
  • 81. SQL & collections select from Tree where children contains ( married = true ) select from Tree where children containsAll ( married = true ) select from User where roles containsKey 'shutdown' select from Profile where tags in 'cool' select from Graph where edges .size() > 0 www.orientechnologies.com
  • 82. SQL & documents select from Vehicle where @class = 'Car' select from Friend where @version > 100 select from File where @size > 1000000 www.orientechnologies.com
  • 83. High-Availability Cluster of distributed server nodes Synchronous, Asynchronous and Read-Only Replication Load-balancing between client ↔ servers and Servers ↔ Servers www.orientechnologies.com
  • 84. Demo again! OrientDB Studio www.orientechnologies.com
  • 85. Always Free Open Source Apache 2 license free for any purposes, even commercials www.orientechnologies.com
  • 86. Prof €$$ ional $ € rvic €$ by a network of companies through Orient Technologies support, training, consulting, mentoring www.orientechnologies.com
  • 87. www.orientechnologies.com OrientDB for Java developers 8 hours OrientDB Master Development 14 hours OrientDB for SOA 6 hours OrientDB and the power of graphs 6 hours OrientDB for DBA 6 hours OrientPlanet for Web Developers 6 hours
  • 88. Certification Program to be part of the network do courses share revenues for support work as consultant www.orientechnologies.com Contact commercial @orientechnologies.com
  • 89. NuvolaBase.com (beta) www.orientechnologies.com The first Graph Database on the Cloud always available few seconds to setup it use it from app & mobile
  • 90. NuvolaBase.com (beta) www.orientechnologies.com By Alfonso Focareta twitter.com/afocareta & Dino Ciuffetti twitter.com/tuxweb
  • 91. NuvolaBase.com (beta) www.orientechnologies.com Only 350 FREE accounts available for the Get your account for FREE inserting “ CM2011 ” as promotional code! “ CM2011”
  • 92. Luca Garulli Author of OrientDB and Roma <Meta> Framework Open Source projects, Member of JSR#12 (jdo 1.0) and JSR#243 (jdo 2.0) CTO at Asset Data and Orient Technologies Technical Manager at Romulus consortium www.orientechnologies.com www.twitter.com/ lgarulli @Rome, Italy