为什么计算GAE数据存储区中X实体的时间会随着实体总数的增加而增加?

时间:2015-12-16 10:22:23

标签: java google-app-engine google-cloud-datastore objectify

我运行了一些测试来计算Google App Engine数据存储区中X类实体的数量,计数限制为5000.令我惊讶的是,此操作所花费的时间会增加数据存储区中实体X的实体总数增加。

如果计数操作只是在实体的键上行走索引,那么时间不应该是恒定的(只要总计数> 5000),而不管数据存储区中类型X的实体总数是多少?

[ NB:这不是关于是使用分片计数器还是使用数据存储统计信息,而是关于我的测试结果是否违反直觉。]

更新1:devserver上进行测试。

以下是一些数据:

Time to create & save 100000 entities: 35.92 s
Using Objectify:
Individual times of 10 runs: 14795, 9521, 9300, 9117, 9848, 9391, 8378, 8525, 8593, 8706
Average time to count 5000 entities over 10 runs: 9.617 seconds
--------------------------------------------------------------------------------
Using Datastore:
Individual times of 10 runs: 8984, 8827, 9062, 9160, 8768, 8737, 8488, 8523, 8828, 8956
Average time to count 5000 entities over 10 runs: 8.833 seconds
--------------------------------------------------------------------------------

Time to create & save 50000 entities: 20.03 s
Using Objectify:
Individual times of 10 runs: 5877, 4736, 4162, 4252, 4126, 4203, 4153, 4168, 4051, 4110
Average time to count 5000 entities over 10 runs: 4.384 seconds
--------------------------------------------------------------------------------
Using Datastore:
Dec 16, 2015 10:00:36 AM in.co.amebatechnologies.empireapp.test.DatastoreTests tearDown
INFO: Closing this session
Individual times of 10 runs: 4409, 4380, 4577, 4414, 4121, 4050, 4076, 4050, 4089, 4148
Average time to count 5000 entities over 10 runs: 4.231 seconds
--------------------------------------------------------------------------------

Time to create & save 10000 entities: 8.989 s
Using Objectify:
Individual times of 10 runs: 1893, 802, 713, 678, 679, 657, 648, 654, 659, 654
Average time to count 5000 entities over 10 runs: 0.804 seconds
--------------------------------------------------------------------------------
Using Datastore:
Individual times of 10 runs: 923, 789, 871, 680, 677, 694, 680, 682, 728, 682
Average time to count 5000 entities over 10 runs: 0.741 seconds
--------------------------------------------------------------------------------

使用:

  • GAE SDK 1.9.30
  • Objectify 5.1.7

直接计算数据存储区中实体的代码(即不使用Objectify):

DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
com.google.appengine.api.datastore.Query qry = new com.google.appengine.api.datastore.Query();
qry.setKeysOnly();
PreparedQuery prepQry = ds.prepare(qry);
FetchOptions fetchOpts = FetchOptions.Builder.withOffset(0).limit(5000).chunkSize(1000);
// Time this operation only:
prepQry.countEntities(fetchOpts);

0 个答案:

没有答案