Reputation: 4329
Simple question this one...
Is this;
http://host/database/docid
Faster than this;
http://host/database/_design/category/_view/specific/?key=docid
I expect that an indexed view would be faster, but I can't be sure, and a detailed answer would be nice.
Upvotes: 0
Views: 186
Reputation: 4679
Without diving into technical details, let's try to describe the whole process:
For URL:
http://host/database/docid
O(logn)
operationNow for the view:
http://host/database/_design/category/_view/specific/?key=docid
include_docs=true
query parameter and that's will cost you additional I/O operationAs you see, requesting views is a bit more complex than requesting by document id.
Here is dummy benchmark using wrk by doc id:
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
and using view:
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
and view with 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
However, views aren't for getting documents by their id. They are secondary indexes for your database and allows to locate the data in more different ways. They supports reduce operation, grouping, which is extremely useful for statistics.
Upvotes: 4