定期删除objectify中的条目 [英] periodically delete entries in objectify
问题描述
我正在使用带有Objectify的Google App Engine,并希望每5分钟删除数据库中的一些条目。什么是最好的方法来完成这个?我应该使用Google App Engine的ThreadManager还是cron作业?还是有其他方法?
I'm using Google App Engine with Objectify and would like to delete some entries in the db every 5 minutes. What would be the best way to accomplish this? Should I use Google App Engine's ThreadManager or a cron job? Or is there another way?
推荐答案
Cron 听起来像这样符合要求,但我担心需要删除的实体的规模。 (根据评论,每五分钟可达几十万)。删除很多实体需要相当长的时间,最有可能超过五分钟的时间,甚至可能超过前端cron处理程序的10分钟截止日期。
Cron sounds like fitting the requirement here, but I'm worried about the scale of entities that need to be deleted. (Up to a few hundred thousands every five minutes according to the comments). Deleting that many entities takes a considerable amount of time, most likely more than the five minutes period, and might even be more than the 10 minutes deadline for front-end cron handlers.
一种可能的解决方案是从后端实例中删除,因为后端可以运行没有任何截止日期。 Crons可以用来启动一个进程,查询要删除的实体,使用纯键查询获取它们的键,然后删除多个 background threads 。
One possible solution is to do the deletion from the backend instance, since backends could run without any deadline. Crons could be used to kick up a process that queries for to-be-deleted entities, fetch their keys using key-only query, and then delete the entities in multiple background threads.
由于进程可以无限期运行,报告删除完成,您可以立即查询并删除下一组实体。您可以在后端使用全局内存锁定,以确保后续cron请求不会启动单独的进程,但如果它检测到进程已运行,则会静默退出。所以这里cron只用作删除过程的保持活动信号。
Since the process could run indefinitely, after the threads report that the deletion finishes, you could immediately query again and delete the next set of entities. You could use a global in-memory lock in the backend to ensure subsequent cron requests are not kicking up a separate process, but silently exit if it detects that the process already runs. So here the cron is used only as a keep-alive signal for the deletion process.
注意,请注意,经常查询和删除实体在数据存储操作成本方面,规模可能非常昂贵。
As a side note, please note that querying and deleting entities this frequently and at this scale might be prohibitively expensive in terms of datastore operation cost.
这篇关于定期删除objectify中的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!