我的帖子非常相似:App引擎批量加载器下载警告"__key__没有降序索引,执行串行下载"
我基本上想要做同样的事情.
基本上,我使用以下内容来下载我的一种类型的所有实例:
appcfg.py download_data --config_file=bulkloader.yaml --kind=ModelName --filename=ModelName.csv --application=MyAppid --url=http://MyAppid.appspot.com/remote_api
Run Code Online (Sandbox Code Playgroud)
如果类型的实例多于批量大小,那么我会收到此警告:
No descending index on __key__, performing serial download
Run Code Online (Sandbox Code Playgroud)
这导致我只下载大约6500个实体需要471.4秒(根据bulkloader工具完成后).这真的很慢,因为我还有其他4种甚至更大(大约15,000个实体)!
另外根据我的Mac的活动监视器,我只以大约24Kb /秒的速度下载,如bulkloader输出中的带宽所示:
[INFO ] Logging to bulkloader-log-20110514.011333
[INFO ] Throttling transfers:
[INFO ] Bandwidth: 250000 bytes/second
[INFO ] HTTP connections: 8/second
[INFO ] Entities inserted/fetched/modified: 20/second
[INFO ] Batch Size: 10
Run Code Online (Sandbox Code Playgroud)
1)如何摆脱这个警告"__key__没有下降索引,执行串行下载"以获得并行下载速度?
我认为我的问题的答案是添加降序索引.就像是:
<datastore-index kind="Game" ancestor="false" source="manual">
<property name="id" direction="desc"/>
</datastore-index>
Run Code Online (Sandbox Code Playgroud)
我尝试将其添加到datastore-indexes.xml文件中.
它已成功部署,但我查看了Google上管理门户网站上的数据存储区索引,但我没有看到它正在服务或正在构建.无论如何,为了它,我重申下面的命令,它仍然很慢......
我也尝试将相同的xml,但使用source ="auto",添加到datastore-indexes-auto.xml文件.但是,当我尝试部署我的eclipse抱怨时出现以下错误:
java.io.IOException: Error posting to URL: https://appengine.google.com/api/datastore/index/add?app_id=<My_APP_ID>&version=1&
400 …Run Code Online (Sandbox Code Playgroud) 我对Objectify很新,我有一个快速的问题,要求做最好的方法:
假设我有一个允许人们发送和接收消息的应用程序(为简单起见,请考虑发送电子邮件).当我的应用加载时,我不想从每个发送消息给给定用户的联系人加载每条消息.那将是一种浪费.相反,我想加载用户有消息的所有联系人(读取或未读取),以便我可以在我的应用程序上显示联系人列表,当用户点击给定联系人时我想加载所有来自该联系人的消息显示给用户.
如果不加载帐户的所有消息,我找不到一个好方法.我在多对一关系中阅读了Objectify wiki,我仍然想不出一个不是非常低效的好方法.客观化网站推荐的方式似乎是,我必须为给定用户加载所有消息,然后解析它们以寻找唯一的联系人.
我正在尝试使用尽可能少的App Engine读取和写入,并尽可能地尝试使用Smalls而不是Reads(运行我的应用程序的总体成本是我的一个大问题,而我正在制作这个) .
在Objectify,我该怎么做?
我有以下的嗜好.
GrandParent - >父母 - >孩子
父母和孩子使用@Parent Ref<GrandParent>并@Parent Ref<Parent>创建父母关系.
我试图用一个很好的方法来进行级联删除GrandParent.
我当然可以加载所有孩子,从他们生成密钥并按键删除.这看起来非常低效.是否存在我可以通过父查询并将查询结果转换为键列表而无需进行完整提取的内容?
欢迎任何想法或第三方图书馆.
如何从中删除python属性lxml.objectify.ObjectifiedElement?
例:
In [1]: from lxml import etree, objectify
In [2]: foo = objectify.Element("foo")
In [3]: foo.bar = "hi"
In [4]: foo.baz = 1
In [5]: foo.fritz = None
In [6]: print etree.tostring(foo, pretty_print=True)
<foo xmlns:py="http://codespeak.net/lxml/objectify/pytype" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" py:pytype="TREE">
<bar py:pytype="str">hi</bar>
<baz py:pytype="int">1</baz>
<fritz xsi:nil="true"/>
</foo>
Run Code Online (Sandbox Code Playgroud)
我反而喜欢输出看起来像:
<foo>
<bar>hi</bar>
<baz>1</baz>
<fritz/>
</foo>
Run Code Online (Sandbox Code Playgroud) 我在Objectify中使用appengine来访问我的数据源.我使用Spring作为业务层.为了玩数据,我使用了objectify-appengine-spring工厂.
我想使用基于注释的本地事务.你知道我可以直接插入一个Spring bean的现有实现吗?
我真的想避免使用线程本地实现我自己的事务提供程序的痛苦.
google-app-engine spring transactions objectify google-cloud-datastore
我有一个实体,一个字段包含一个列表,以Refs到其他实体(总是4).我正在尝试获取一些实体,并将它们分配给jsp进行显示.我希望加载字段中的所有Refs,并在jsp中访问它们.
这是我的基本结构:
@Entity
public class Question {
@Id Long id;
@Index String question;
@Load List<Ref<Answer>> answers = new ArrayList<Ref<Answer>>();
}
Run Code Online (Sandbox Code Playgroud)
当我提取这样的问题时,显然jsp中存在错误.有道理,因为答案字段不是答案列表,而是refs:
ObjectifyService.register(Question.class);
ObjectifyService.register(Answer.class);
List<Question> questions = ofy().load().type(Question.class).limit(50).list();
req.setAttribute("questions", questions);
try {
getServletContext().getRequestDispatcher("/admin/view-questions.jsp").forward(req, resp);
} catch (ServletException e) {
System.out.println (e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
那么如何在jsp中访问答案呢?是手动循环问题并为答案字段执行get()的唯一方法吗?
我正在使用GeoModel开发一个应用程序.我需要根据给定的纬度和经度在特定半径内执行搜索.我可以使用Objectify在数据存储区中生成GeoCells,但无法在特定半径内返回结果.
我在下面分享我的代码.
实体类
@Entity
public class NewsFeed implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Index
private Long feedID;
@Index
private String topic;
@Index
private String title;
private String description;
@Index
private Date createDate;
private String imageOrVideo;
private String imageUrl;
private String blobKey;
@Latitude
private Double latitude;
@Longitude
private Double longitude;
@Geocells
private List<String> cells;
// getter and setters ...
}
Run Code Online (Sandbox Code Playgroud)
来自此源的自定义GeocellQueryEngine类
public class ObjectifyGeocellQueryEngine implements GeocellQueryEngine {
private String geocellsProperty;
private Objectify ofy; …Run Code Online (Sandbox Code Playgroud) 您有两个相关的实体:客户和汽车.每个客户可以拥有多辆汽车
这是实体的摘要视图:
public class Customer
{
//Inner classes for partial loads
public static class NoCars{}
@Id protected String id;
private String fullName;
@Load(unless=NoCars.class) private List<Ref<Car>> cars;
}
public class Car
{
@Id private Long id;
private String makeAndModel;
private String plateNumber;
}
Run Code Online (Sandbox Code Playgroud)
这是一种从数据存储区和他拥有的所有汽车中检索客户的方法:
public Customer getCustomer(@Named("id") String customerId)
{
Customer customer = ofy().load().type(Customer.class).id(customerId).now();
if (customer==null)
throw new NotFoundException("customer not found");
else
return customer;
}
Run Code Online (Sandbox Code Playgroud)
endpoints.sh无法实现这一点,因为不支持List <Ref<Car>>返回类型Customer中包含的类型,但我发现这个有趣的解决方法:
我创建了CustomerPOJO类
public class CustomerPOJO …Run Code Online (Sandbox Code Playgroud) 为什么我想要异步加载Objectify实体?异步加载实际上意味着什么?
根据Objectify关于加载的文档,以下加载实体的方式是异步的:
// Simple key fetch, always asynchronous
Result<Thing> th = ofy().load().key(thingKey);
Run Code Online (Sandbox Code Playgroud)
如果我想要一个加载同步执行,那么我应该这样做:
Thing th = ofy().load().key(thingKey).now(); // added .now()
Run Code Online (Sandbox Code Playgroud)
对我而言,异步意味着该操作将在稍后的某个未指定时间发生.对于保存,异步是有意义的,因为数据存储区操作可能需要一些时间来完成而不会阻塞应用程序代码.
但是加载时,异步意味着负载会在另一个时间发生吗?如何在Java中实现这一点?我认为Result<Thing> th当代码行Result<Thing> th = ofy().load().key(thingKey);完成执行时必须更新变量.
作为一个新手,我花了很长时间才弄清楚这一点(例如参见Objectify错误"你不能在JUnit中为一个带有@Id的对象创建一个键").
所以我有几个问题:
1]为什么我想要异步加载Objectify实体?
2]异步加载实际意味着什么?
3] now()加载和now()保存之间的概念联系是什么?
同步负载(源)
Thing th = ofy().load().key(thingKey).now();
Run Code Online (Sandbox Code Playgroud)
同步保存(源)
ofy().save().entity(thing1).now();
Run Code Online (Sandbox Code Playgroud)
4]为什么不同步保存和加载的默认行为?
我注意到我的app在app引擎上运行的周期性但持续的延迟峰值.起初我认为网络可能很慢,但应用统计数据证实并非如此.
我已经能够使用较旧和较新版本的SDK重现延迟峰值,目前我正在使用以下内容:
所以在应用程序上的使用率非常低,在过去的30天里我通常低于0.04秒的请求:
大多数操作的延迟都不到一秒钟,但是令人震惊的请求数量要长10到30倍.
所以我认为它必须只是网络延迟,但每个缓慢操作的appstat都反驳了这一点.数据存储和网络始终非常可靠.这是一个超过30秒的缓慢请求的解剖:
从高层次来说,我的代码非常无趣:它是一个简单的api,可以进行一些网络调用,并从云数据存储中保存/读取数据.整个源代码可以在github上找到.该应用程序在单个自动扩展应用程序引擎实例上运行并且已预热.
很奇怪,即使是快速操作,在CPU上花费了大量的时间,即使代码只是创建了一些对象,它们仍然存在并返回JSON.我想知道CPU是否被另一个应用程序挂在我的应用程序引擎实例上,这可能会导致性能周期性降低.
我的appengine.xml配置如下所示:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>sauce-sync</application>
<version>1</version>
<threadsafe>true</threadsafe>
<automatic-scaling>
<!-- always keep an instance up in order to keep startup time low-->
<min-idle-instances>1</min-idle-instances>
</automatic-scaling>
</appengine-web-app>
Run Code Online (Sandbox Code Playgroud)
我的web.xml看起来像这样:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>com.sauce.sync.SauceSyncEndpoint</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
<!--reaper-->
<servlet>
<servlet-name>reapercron</servlet-name>
<servlet-class>com.sauce.sync.reaper.ReaperCronServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>reapercron</servlet-name>
<url-pattern>/reapercron</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>reaper</servlet-name>
<servlet-class>com.sauce.sync.reaper.ReaperServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>reaper</servlet-name>
<url-pattern>/reaper</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<filter>
<filter-name>ObjectifyFilter</filter-name> …Run Code Online (Sandbox Code Playgroud) objectify ×10
java ×6
bulkloader ×1
elementtree ×1
endpoints ×1
formatting ×1
geospatial ×1
json ×1
lxml ×1
python ×1
spring ×1
transactions ×1