Advantages of using cql over thrift

懵懂的女人 提交于 2019-11-27 00:47:22

问题


Are there any distinct advantages for using cql over thrift or is it simply a case of developers being too used to SQL? I'm wanting to switch from thrift querying to cql, the only problem is I'm not sure about the downsides of doing so. What are they?


回答1:


Querying
In CQL you can query cassandra and get data in a couple of lines (using JDBC driver):

String query = "SELECT * FROM message;";
PreparedStatement statement = con.prepareStatement(query);

While in thrift based API's it's a bit more complicated (example with Astyanax):

OperationResult<ColumnList<String>> result = 
     keyspace.prepareQuery(mail/*specify columnfamily structure*/)
             .getKey("lyuben@1363115059").execute();
ColumnList<String> columns = result.getResult();

Performance
Based on the benchmarks carried out by Acunu, Thrift (RPC) is slightly ahead of CQL when it comes to query performance, but you need to be in a situation where high throughput is key for this performance advantage to have a significant benefit.


Some excellent articles to lookup are:

  • A thrift to CQL3 upgrade guide.
  • CQL vs RPC - Acunu benchmarks
  • CQL3 for cassandra experts

EDIT

The above benchmarks are outdated, the paul provided newer benchmarks on prepared statements.




回答2:


Lyuben's answer is a good one, but I believe he may be misinformed on a few points. First, you should be aware that the Thrift API is not going to be getting new features; it's there for backwards compatibility, and not recommended for new projects. There are already some features that can not be used through the Thrift interface.

Another factor is that the quoted benchmarks from Acunu are misleading; they don't measure the performance of CQL with prepared statements. See, for example, the graphs at https://issues.apache.org/jira/browse/CASSANDRA-3634 (probably the same data set on which the Acunu post is based, since Eric Evans wrote both). There have also been some improvements to CQL parsing and execution speed in the last year. It is not likely that you will observe any real speed difference between CQL 3 and Thrift.

Finally, I don't think I even agree that Thrift is more flexible. The CQL 3 datamodel allows using the same data structures that Thrift does for nearly all usages that are not antipatterns; it just allows you to think about the model in a more organized way. For example, Lyuben mentioned rows with differing numbers of columns. A CQL 3 table may still utilize that capability: there is a difference between "storage engine rows" (which is Cassandra's low level storage, and what Thrift uses directly) and "CQL rows" (what you see through the Thrift interface). CQL just does the extra work necessary to visualize wide storage engine rows as structured tables.

It's a little difficult to explain in a quick SO answer, but see this post for a somewhat gentle explanation.



来源:https://stackoverflow.com/questions/15701263/advantages-of-using-cql-over-thrift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!