[英]How can I do an atomic operation to a document field in ArangoDB?
I would like to know which is best way to do this with ArangoDB, I started using transactions, or updating it records using revision check, but it's not very good with many concurrent updates. 我想知道哪种最好的方式是使用ArangoDB做到这一点,我开始使用事务,或者使用修订检查来更新记录,但是对于许多并发更新来说,效果不是很好。
With the new release 2.1 I see that that I can register functions in the server to execute every X amount of time, as I'm keeping raw data for a long period of time, I can count it async using one server task but It gives more latency to the counter. 在新版本2.1中,我看到我可以在服务器中注册函数以每X的时间执行一次,因为我要长时间保留原始数据,因此我可以使用一个服务器任务将其异步计数,但是它可以计数器的等待时间更长。
Is there any other way to do it? 还有其他方法吗?
Thanks, 谢谢,
Diego Guraieb 迭戈·格莱布
At the moment there would be at least three ways to increase a counter: 目前,至少有三种方法可以增加计数器:
Alternative 1 will require at least 2 HTTP calls (fetch + update), and you will need error handling for the case of a concurrent update. 备选方案1将至少需要2个HTTP调用(提取+更新),并且对于并发更新,您将需要错误处理。 So it's not very useful.
所以它不是很有用。
Alternative 2 will be the easiest-to-use from the client perspective I think. 从客户的角度来看,备选方案2将是最容易使用的。 It allows exposing the "increase counter" operation via the REST API, and the fetch-and-update can be implemented in an atomic transaction.
它允许通过REST API公开“增加计数器”操作,并且获取和更新可以在原子事务中实现。
Alternative 3 will work, too, if you can afford your counters to be slightly outdated. 如果您可以负担得起一些过时的计数器,则备选方案3也将起作用。 When implemented, it should be implemented incrementally, eg by keeping a total for the counter and adding only the new values on each update task execution.
在实施时,应以增量方式实施,例如,通过保留计数器的总数并在每次更新任务执行时仅添加新值。 Otherwise your "counter operations" collection will grow infinitely and updates will become slower and slower.
否则,您的“计数器操作”集合将无限增长,并且更新速度将越来越慢。 Alternative #3 also has the advantage that you can keep a (small) log of recent operations, eg for auditing.
备选方案3的优势还在于,您可以保留(少量)近期操作的日志,例如用于审核。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.