Google App Engine(Java) - JDO PersistenceManager makePersistentAll Slowing Down

时间:2013-03-07 03:52:36

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

我有一个迷你CRM应用程序。我正在尝试添加允许批量用户导入的功能。上传处理程序从CSV文件中读取数据,然后调用我的CustomerService类将Customer对象存储在数据存储区中:

public int createCustomers(final List<Customer> customers) {
    List<List<Customer>> buckets = bucketList(customers);
    int bucketCount = 0;
    PersistenceManager persistenceManager = PMF.get().getPersistenceManager();
    for(List<Customer> bucket: buckets) {
        Collection<Customer> makePersistentAll = persistenceManager.makePersistentAll(bucket);
    }           
    return customers.size();        
}

bucketList方法只是将大型列表分解为较小的列表。我这样做是为了调整应用程序并查看makePersistentAll调用是否有最佳大小。我目前将其设置为1000,并使用包含100,000条记录的CSV文件进行测试。随着更多记录的增加,应用程序似乎变得越来越慢,特别是在60K记录标记附近。我已经尝试将Customer中的所有字段设置为无索引,但这似乎没有任何明显的区别:

@PersistenceCapable
public class Customer implements Serializable {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;

@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
@Persistent
private String accountNumber;
@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
@Persistent
private String email;
@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
@Persistent
private String firstName;
@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
@Persistent
private String lastName;
    ...

我已经在开发(本地)以及生产App Engine中对此进行了测试,但无济于事。我认为这是一个常见的用例,将大量数据导入系统并将其快速保存到数据存储区。我已经尝试了很多方法来实现这个目的: - 使用AsyncDatastoreService - 逐个保存客户对象(makePersistent) - 使用Customer中的Key对象作为主键 - 使用accountNumber字符串作为主键

但似乎没有什么区别。

1 个答案:

答案 0 :(得分:1)

建议您查看http://www.datanucleus.org/products/accessplatform_3_2/jdo/performance_tuning.html特别是关于大量对象的“持久性过程”。您可以减少被泵入"makePersistentAll()"的对象数量,这样您就可以进行多次调用。显然,GAE /数据存储可能有些奇怪,可能导致这个