dpd3447 2017-04-20 09:16
浏览 50
已采纳

GAE / Go:数据存储迭代器太慢

Iteration to datastore query result in GAE/Go is very slow.

q := datastore.NewQuery("MyStruct")
gaeLog.Infof(ctx, "run")                                                 // (1)
it := client.Run(ctx, q)
list := make([]MyStruct, 0, 10000)
gaeLog.Infof(ctx, "start mapping")                                       // (2)
for {
    var m MyStruct
    _, err := it.Next(&m)
    if err == iterator.Done {
        break
    }
    if err != nil {
        gaeLog.Errorf(ctx, "datastore read error : %s ", err.Error())
        <some error handling>
        break
    }
    list = append(list , m)
}
gaeLog.Infof(ctx, "end mapping. count : %d", len(list))                  // (3)

The result is below.

18:02:11.283 run                             // (1)
18:02:11.291 start mapping                   // (2)
18:02:15.741 end mapping. count : 2400       // (3)

It takes about 4.5 seconds between (2) and (3), just only 2400 record. It is very slow.

How can I improve performance?

[Update]

I added the query in above code q := datastore.NewQuery("MyStruct"). I tried to retrieve all the entities in the kind MyStruct. This kind has 2400 entities.

  • 写回答

1条回答 默认 最新

  • dongman5539 2017-04-21 05:01
    关注

    I was using cloud.google.com/go/datastore and found it is slow. I migrated to use google.golang.org/appengine/datastore.

    The result is as follows, less than 1 second.

    13:57:46.216 run
    13:57:46.367 start mapping
    13:57:47.063 end mapping. count : 2400
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试