Advantages of using cql over thrift

爱⌒轻易说出口 提交于 2019-11-28 05:04:54
Lyuben Todorov

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:

EDIT

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

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.

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