减少数据存储区写操作

时间:2012-04-02 21:14:59

标签: google-app-engine google-cloud-datastore web-crawler

我正在Google App Engine上构建网络抓取工具。要将已爬网的信息存储在Data Store中,我使用JDO使用以下字段。守则如下:

public class LinkInfo
{
   @PrimaryKey
   @Persistent private String id;

   @Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
   @Persistent private int linkNo;

   @Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
   @Persistent private String link;

   @Persistent private int version;

   @Persistent private String fetchDate;

   @Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
   @Persistent private long fetchTime;

   @Persistent private String nextFetch;

   @Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
   @Persistent private String pageCreationDate;

   @Persistent private int retries;

   @Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
   @Persistent private int retryInterval;

   @Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
   @Persistent private int outLinks;

   @Persistent private float score;

   @Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
   @Persistent private String abstractContent;

   @Persistent private String contentType;

   @Persistent private String parent;

   @Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
   @Persistent private String title;

       ...

在16个字段中,我做了8个未索引的索引,因为我不需要对它们进行过滤或排序。即使是现在,我也超过了数据存储区写操作限制。

通过“数据存储区写操作”减少的任何建议?

2 个答案:

答案 0 :(得分:6)

来自Google App Engine:

对于每个新的实体投放:

  

" 2每个索引属性值写入+ 2次写入,每个复合索引值写入1次写入。"

因此,对于每个实体,您将拥有2 + 2 * 8 +(无论您拥有多少个自定义索引)。

每个实体至少18个。

减少写入次数的最佳方法是减少索引属性的数量。

答案 1 :(得分:1)

你可以做很多事情来减少写入...假设你没有经常更新数据。它的内容是您可以通过缓存进行优化。根据你的例子,这是一个非常直接的表,没有连接,所以如果你只是在那里存储数据,你可以做的不多。保存数据时,每个条目是否看到多个写入?

我唯一要建议的是完全放弃JDO,只需通过本机API写入数据存储区,以便在JDO采取多个操作来持久保存对象时真正优化写入,但实际上,它不应该比你自己做的要糟糕得多。

相关问题