Skip to content

Instantly share code, notes, and snippets.

@pahud
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pahud/63c148bd033c857e8bfb to your computer and use it in GitHub Desktop.
Save pahud/63c148bd033c857e8bfb to your computer and use it in GitHub Desktop.
Datastore JSON API non_transactional commit test
連續寫入30次,運行在google compute engine上,每次寫入時間大約0.3秒。
$ for i in `seq 30`; do curl -sH "Content-Type: application/json" -H "Authorization: Bearer xxxxxxxx" https://www.googleapis.com/datastore/v1beta2/datasets/project-id/commit -d @addbody -o /dev/null -w "total:%{time_total}\n"; done
total:0.364
total:0.353
total:0.362
total:0.352
total:0.354
total:0.357
total:0.357
total:0.358
total:0.369
total:0.359
total:0.357
total:0.352
total:0.354
total:0.358
total:0.349
total:0.360
total:0.383
total:0.362
total:0.375
total:0.350
total:0.399
total:0.352
total:0.448
total:0.363
total:0.360
total:0.352
total:0.361
total:0.344
total:0.349
total:0.353
content of @addbody
{
"mode": "NON_TRANSACTIONAL",
"mutation": {
"insertAutoId": [
{
"key": {
"path": [
{
"kind": "STAFF"
}
]
},
"properties": {
"name": {
"stringValue": "Emilie"
}
}
}
]
}
}
runQuery大約0.2~0.3秒
$ for i in `seq 30`; do curl -sH "Content-Type: application/json" -H "Authorization: Bearer xxxxx" https://www.googleapis.com/datastore/v1beta2/datasets/project-id/runQuery -d @queryBody -o /dev/null -w "total:%{time_total}\n"; done
total:0.287
total:0.276
total:0.268
total:0.291
total:0.285
total:0.272
total:0.291
total:0.276
total:0.282
total:0.328
total:0.275
total:0.280
total:0.281
total:0.270
total:0.270
total:0.276
total:0.281
total:0.343
total:0.274
total:0.313
total:0.278
total:0.282
total:0.275
total:0.285
total:0.284
total:0.358
total:0.275
total:0.283
total:0.287
total:0.273
content of @queryBody
{
"query": {
"kinds": [
{
"name": "STAFF"
}
],
"filter": {
"propertyFilter": {
"value": {
"stringValue": "Emilie"
},
"property": {
"name": "name"
},
"operator": "equal"
}
},
"limit": 1
}
}
結論:
1)對create/insert來說速度不快,但query速度挺不錯,如果像Datastore號稱幾百萬幾千萬筆裡面查出100筆,跟幾千筆裡面查出100筆的速度是一樣的話,這0.2~0.3的查詢速度的確很不錯。
2)create/insert可能要做一些operations aggregation的封裝,節省每次commit的時間成本。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment