MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / BenchmarkReadOps_Changes

Function BenchmarkReadOps_Changes

rest/api_benchmark_test.go:188–260  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

186}
187
188func BenchmarkReadOps_Changes(b *testing.B) {
189
190 base.DisableTestLogging(b)
191
192 rt := NewRestTesterDefaultCollection(b, nil) // use non default in CBG-2618
193 defer rt.Close()
194 defer PurgeDoc(rt, "doc1k")
195
196 // Create user
197 username := "user1"
198 rt.SendAdminRequest("PUT", "/{{.db}}/_user/"+username, fmt.Sprintf(`{"name":"%s", "password":"letmein", "admin_channels":["channel_1"]}`, username))
199
200 doc1k_putDoc := fmt.Sprintf(doc_1k_format, "")
201
202 // Create branched doc
203 response := rt.SendAdminRequest("PUT", "/{{.keyspace}}/doc1k", doc1k_putDoc)
204 if response.Code != 201 {
205 log.Printf("Unexpected create response: %d %s", response.Code, response.Body.Bytes())
206 }
207
208 var body db.Body
209 require.NoError(b, base.JSONUnmarshal(response.Body.Bytes(), &body))
210 revid := body["rev"].(string)
211 _, rev1_digest := db.ParseRevID(rt.Context(), revid)
212 response = rt.SendAdminRequest("PUT", fmt.Sprintf("/{{.keyspace}}/doc1k?rev=%s", revid), doc1k_putDoc)
213 if response.Code != 201 {
214 log.Printf("Unexpected add rev response: %d %s", response.Code, response.Body.Bytes())
215 }
216
217 doc1k_rev2_meta := fmt.Sprintf(`"_revisions":{"start":2, "ids":["two", "%s"]},`, rev1_digest)
218 doc1k_rev2 := fmt.Sprintf(doc_1k_format, doc1k_rev2_meta)
219 response = rt.SendAdminRequest("PUT", "/{{.keyspace}}/doc1k?new_edits=false", doc1k_rev2)
220 if response.Code != 201 {
221 log.Printf("Unexpected add conflicting rev response: %d %s", response.Code, response.Body.Bytes())
222 }
223
224 // Changes benchmarks use since=1 to exclude the user doc from the response
225 changesBenchmarks := []struct {
226 name string
227 URI string
228 asUser string
229 }{
230 {"Admin_Simple", "/{{.keyspace}}/_changes?since=1", ""},
231 {"Admin_Longpoll", "/{{.keyspace}}/_changes?since=1&feed=longpoll", ""},
232 {"Admin_StyleAllDocs", "/{{.keyspace}}/_changes?since=1&style=all_docs", ""},
233 {"Admin_StyleAllDocsChannelFilter", "/{{.keyspace}}/_changes?since=1&style=all_docs&filter=sync_gateway/bychannel&channels=channel_1", ""},
234 {"Admin_IncludeDocs", "/{{.keyspace}}/_changes?since=1&include_docs=true", ""},
235 {"User_Simple", "/{{.keyspace}}/_changes?since=1", username},
236 {"User_Longpoll", "/{{.keyspace}}/_changes?since=1&feed=longpoll", username},
237 {"User_StyleAllDocs", "/{{.keyspace}}/_changes?since=1&style=all_docs", username},
238 {"User_StyleAllDocsChannelFilter", "/{{.keyspace}}/_changes?since=1&style=all_docs&filter=sync_gateway/bychannel&channels=channel_1", username},
239 {"User_IncludeDocs", "/{{.keyspace}}/_changes?since=1&include_docs=true", username},
240 }
241
242 for _, bm := range changesBenchmarks {
243 b.Run(bm.name, func(b *testing.B) {
244 var changesResponse *TestResponse
245 for i := 0; i < b.N; i++ {

Callers

nothing calls this directly

Calls 10

DisableTestLoggingFunction · 0.92
JSONUnmarshalFunction · 0.92
ParseRevIDFunction · 0.92
PurgeDocFunction · 0.85
SendAdminRequestMethod · 0.80
SendUserRequestMethod · 0.80
CloseMethod · 0.65
ContextMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected