CQL: SQL In Cassandra

20,970 views
20,430 views

Published on

CQL presentation from Cassandra NYC, December 6, 2011

Published in: Technology
1 Comment
11 Likes
Statistics
Notes
No Downloads
Views
Total views
20,970
On SlideShare
0
From Embeds
0
Number of Embeds
1,907
Actions
Shares
0
Downloads
234
Comments
1
Likes
11
Embeds 0
No embeds

No notes for slide

CQL: SQL In Cassandra

  1. 1. CQL: SQL for Cassandra Cassandra NYC December 6, 2011 Eric Evans eric@acunu.com @jericevans, @acunu
  2. 2. ● Overview, history, motivation● Performance characteristics● Coming soon (?)● Drivers status
  3. 3. What?● Cassandra Query Language ● aka CQL ● aka /ˈsēkwəl/● Exactly like SQL (except where its not)● Introduced in Cassandra 0.8.0● Ready for production use
  4. 4. SQL? Almost.–- Inserts or updatesINSERT INTO Standard1 (KEY, col0, col1)VALUES (key, value0, value1) vs.–- Inserts or updatesUPDATE Standard1SET col0=value0, col1=value1 WHERE KEY=key
  5. 5. SQL? Almost.–- Get columns for a rowSELECT col0,col1 FROM Standard1 WHERE KEY=key–- Range of columns for a rowSELECT col0..colN FROM Standard1 WHERE KEY=key–- First 10 results from a range of columnsSELECT FIRST 10 col0..colN FROM Standard1 WHERE KEY=key–- Invert the sorting of resultsSELECT REVERSED col0..colN FROM Standard1 WHERE KEY=key
  6. 6. Why?
  7. 7. Interface Instability
  8. 8. (Un)ease of useColumn col = new Column(ByteBuffer.wrap(“name”.getBytes()));col.setValue(ByteBuffer.wrap(“value”.getBytes()));col.setTimestamp(System.currentTimeMillis());ColumnOrSuperColumn cosc = new ColumnOrSuperColumn();cosc.setColumn(col);Mutation mutation = new Mutation();Mutation.setColumnOrSuperColumn(cosc);List mutations = new ArrayList<Mutation>();mutations.add(mutation);Map mutations_map = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();Map cf_map = new HashMap<String, List<Mutation>>();cf_map.set(“Standard1”, mutations);mutations.put(ByteBuffer.wrap(“key”.getBytes()), cf_map)
  9. 9. CQLINSERT INTO Standard1 (KEY, col0) VALUES (key, value0)
  10. 10. Why? How about...● Better stability guarantees● Easier to use (you already know it)● Better code readability / maintainability
  11. 11. Why? How about...● Better stability guarantees● Easier to use (you already know it)● Better code readability / maintainability● Irritates the NoSQL purists
  12. 12. Why? How about...● Better stability guarantees● Easier to use (you already know it)● Better code readability / maintainability● Irritates the NoSQL purists● (Still )irritates the SQL purists
  13. 13. Performance
  14. 14. Thrift RPCColumn col = new Column(ByteBuffer.wrap(“name”.getBytes()));col.setValue(ByteBuffer.wrap(“value”.getBytes()));col.setTimestamp(System.currentTimeMillis());ColumnOrSuperColumn cosc = new ColumnOrSuperColumn();cosc.setColumn(col);Mutation mutation = new Mutation();Mutation.setColumnOrSuperColumn(cosc);List mutations = new ArrayList<Mutation>();mutations.add(mutation);Map mutations_map = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();Map cf_map = new HashMap<String, List<Mutation>>();cf_map.set(“Standard1”, mutations);mutations.put(ByteBuffer.wrap(“key”.getBytes()), cf_map)
  15. 15. Your query, its a graph
  16. 16. CQLINSERT INTO Standard1 (KEY, col0) VALUES (key, value0)
  17. 17. Hotspot Quoted string literalsUPDATE table SET name = value WHERE KEY = somekey
  18. 18. Hotspot Quoted string literalsUPDATE table SET name = value WHERE KEY = somekey
  19. 19. Hotspot Quoted string literalsUPDATE table SET name = value WHERE KEY = somekey● Anything that appears between quotes● Inlined Java constructs a StringBuilder to store the contents (slow not fast)● Incurred multiple times per statement
  20. 20. Hotspot MarshallingUPDATE table SET clear = abffaadd10 WHERE KEY = acfe12ff
  21. 21. Hotspot MarshallingUPDATE table SET clear = abffaadd10 WHERE KEY = acfe12ff ascii blob
  22. 22. Hotspot MarshallingUPDATE table SET clear = abffaadd10 WHERE KEY = acfe12ff ascii blob● Terms are marshalled to bytes by type● String.getBytes is slow (AsciiType)● Hex conversion is fast faster (BytesType)● Incurred multiple times per statement
  23. 23. Hotspot Copying / Conversionexecute_cql_query( ByteBuffer query, enum compression)● Query is binary to support compression (is it worth it?)● And dont forget the String → ByteBuffer conversion on the client-side● Incurred only once per statement!
  24. 24. Achtung! (These tests werent perfect)● Uneeded String → ByteBuffer → String● No query compression implemented● Co-located client and server
  25. 25. Insert 20M rows, 5 columns Avg rate Avg latency RPC 20,953/s 1.6ms CQL 19,176/s (-8%) 1.7ms (+9%)
  26. 26. Insert 10M rows, 5 cols (indexed) Avg rate Avg latency RPC 9,850/s 5.3ms CQL 9,290/s (-6%) 5.5ms (+4%)
  27. 27. Counts, 10M rows, 5 cols Avg rate Avg latency RPC 18,052/s 1.7ms CQL 17,635/s (-2%) 1.7ms
  28. 28. Reading 20M rows, 5 cols Avg rate Avg latency RPC 22.726/s 2.0ms CQL 20,272/s (-11%) 2.3ms (+10%)
  29. 29. In SummaryDont step over dollars to pick up pennies!
  30. 30. Coming Soon(ish)
  31. 31. Roadmap● Prepared statements (CASSANDRA-2475)● Compound columns (CASSANDRA-2474)● Custom transport / protocol (CASSANDRA-2478)● Performance testing (CASSANDRA-2268)● Schema introspection (CASSANDRA-2477)● Multiget support (CASSANDRA-3069)
  32. 32. Drivers
  33. 33. Drivers● Hosted on Apache Extras (Google Code)● Tagged cassandra and cql● Licensed using Apache License 2.0● Conforming to a standard for database connectivity (if applicable)● Coming soon, automated testing and acceptance criteria
  34. 34. DriversDriver Platform Statuscassandra-jdbc Java Goodcassandra-dbapi2 Python Goodcassandra-ruby Ruby Newcassandra-pdo PHP Newcassandra-node Node.js Goodhttp://code.google.com/a/apache-extras.org/hosting/search?q=label%3aCassandra
  35. 35. The End

×