So I was deciding if switch from views to N1QL for a game I am developing and so I decided to run some simple benchmark.
Turn out even for a simple select returning all docs of one type there is a 30x difference in performance.
I have setup a test scenario with 200K docs. I then fire 100 concurrent queries and these are the results:
The view returns the data in 300ms average.
N1QL return the data in min 9 seconds max 72 seconds and then even run out of ram.
Running 1000 concurrent.
The view returns in 300ms-3seconds.
N1QL return the data in min 15 seconds max 90 seconds and then some queries run even out of ram.
What’s funny is that when I try to make 1000 concurrent queries with just 5 docs, with n1ql it takes from 4 to 10 seconds on the first run and 500ms to 5 seconds on subsequent runs, with views 400ms to 3 seconds from the first run.
I am using Couchbase 4.5.1 on a mac running inside vmware so it’s quite starved both for cpu and ram but the same apply for views so I shouldn’t be biased.
Here is the plan for the query, did I mistake something:
explain select val from Fitness where type=‘fitsession’
[
{
“plan”: {
“#operator”: “Sequence”,
“~children”: [
{
“#operator”: “IndexScan”,
“index”: “valindex”,
“index_id”: “d587c7d7513389c3”,
“keyspace”: “Fitness”,
“namespace”: “default”,
“spans”: [
{
“Range”: {
“High”: [
“"fitsession"”
],
“Inclusion”: 3,
“Low”: [
“"fitsession"”
]
}
}
],
“using”: “gsi”
},
{
“#operator”: “Fetch”,
“keyspace”: “Fitness”,
“namespace”: “default”
},
{
“#operator”: “Parallel”,
“~child”: {
“#operator”: “Sequence”,
“~children”: [
{
“#operator”: “Filter”,
“condition”: “((Fitness
.type
) = "fitsession")”
},
{
“#operator”: “InitialProject”,
“result_terms”: [
{
“expr”: “(Fitness
.val
)”
}
]
},
{
“#operator”: “FinalProject”
}
]
}
}
]
},
“text”: “select val from Fitness where type=‘fitsession’”
}
]