这个简单的问题......
是的;http://host/database/docid
比这更快;
http://host/database/_design/category/_view/specific/?key=docid
我希望索引视图会更快,但我不能确定,详细的答案会很好。
答案 0 :(得分:4)
不考虑技术细节,让我们试着描述整个过程:
对于网址:
http://host/database/docid
O(logn)
操作现在查看:
http://host/database/_design/category/_view/specific/?key=docid
include_docs=true
查询参数,这将花费您额外的I / O操作如您所见,请求视图比通过文档ID请求更复杂。
以下是使用{id}的wrk虚拟基准:
Running 1m test @ http://host/database/docid
8 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 48.35ms 7.14ms 102.98ms 83.13%
Req/Sec 250.38 24.81 323.00 74.06%
Latency Distribution
50% 45.99ms
75% 50.98ms
90% 57.95ms
99% 74.01ms
119880 requests in 1.00m, 103.71MB read
Requests/sec: 1997.91
Transfer/sec: 1.73MB
并使用视图:
Running 1m test @ http://host/database/_design/category/_view/specific/?key=docid
8 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 61.06ms 13.68ms 178.97ms 79.74%
Req/Sec 200.38 28.80 263.00 71.60%
Latency Distribution
50% 57.05ms
75% 66.98ms
90% 77.01ms
99% 112.99ms
96071 requests in 1.00m, 28.69MB read
Requests/sec: 1601.06
Transfer/sec: 489.55KB
并使用include_docs=true
查看:
Running 1m test @ http://host/database/_design/category/_view/specific/?key=docid&include_docs=true
8 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 82.95ms 13.26ms 200.98ms 77.46%
Req/Sec 145.91 15.11 192.00 73.28%
Latency Distribution
50% 80.77ms
75% 88.97ms
90% 98.97ms
99% 124.98ms
69988 requests in 1.00m, 69.89MB read
Requests/sec: 1166.27
Transfer/sec: 1.16MB
但是,视图不是用于通过id获取文档。它们是数据库的二级索引,允许以更多不同的方式定位数据。它们支持减少操作,分组,这对统计数据非常有用。